Surface rotation in 3d

2 views (last 30 days)
rem9818
rem9818 on 1 Aug 2019
Edited: rem9818 on 2 Aug 2019
Hello,
I have a problem to rotate a surface in 3D. I would like to rotate an ellipsoid (S) in the three directions but it doesn't work.
When I run the code below just the third rotation is taken into account.
Thank you for your help!
rotate(S, [1 0 0], 180*roll(i)/pi, center);
rotate(S, [0 1 0], 180*pitch(i)/pi, center);
rotate(S, [0 0 1], 180*yaw(i)/pi, center);
  4 Comments
darova
darova on 2 Aug 2019
Can you please show?
rem9818
rem9818 on 2 Aug 2019
Edited: rem9818 on 2 Aug 2019
I managed to display the new surfaces but their positions changed
for i=1:101
[x, y, z] = ellipsoid(X(i),Y(i),Z(i),b,a,a);
S = surf(x,y,z);
S.FaceColor = 'white';
S.EdgeColor = 'white';
title('Position and orientation of fibers in the water channel')
xlabel('X')
ylabel('Y')
zlabel('Z')
center = [X(i) Y(i) Z(i)];
rotm = eul2rotm([roll(i) pitch(i) yaw(i)],'XYZ');
%rotate(S, [1 1 1], 180*roll(i)/pi, center);
%rotate(S, [0 1 0], 180*pitch(i)/pi, center);
%rotate(S, [0 0 1], 180*yaw(i)/pi, center);
Matrix_X = S.XData;
Matrix_Y = S.YData;
Matrix_Z = S.ZData;
Vec_X = Matrix_X(:);
Vec_Y = Matrix_Y(:);
Vec_Z = Matrix_Z(:);
V = [Vec_X Vec_Y Vec_Z];
s = size(V);
for j=1:s(1)
NewV = rotm*V';
end
NewM_X = vec2mat(NewV(1,:),21);
NewM_Y = vec2mat(NewV(2,:),21);
NewM_Z = vec2mat(NewV(3,:),21);
S2 = surf(NewM_X,NewM_Y,NewM_Z, 'EdgeColor', 'r');
hold on
set(gca,'color','k')
axis equal
end

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!