rotate the coordinates plotted with plot3 without changing the axes

조회 수: 22 (최근 30일)
Alberto Acri
Alberto Acri 2022년 12월 20일
댓글: Alberto Acri 2022년 12월 20일
Hi. I need to rotate the plotted curves (3D figure on the left) by 180° as shown in the figure on the right. Is there any efficient method?
Attached is the code.

채택된 답변

Karim
Karim 2022년 12월 20일
Hi, in the code below I added some comments to demonstrate how you can rotate the curve.
imageArray = imread("fig_A.png");
binaryImage = imageArray;
binaryImage = ~binaryImage;
M1 = function_verification_code(binaryImage);
z = 100;
figure
current_z = z * ones(size(M1, 1), 1);
plot3(M1(:, 2), M1(:, 1), current_z, 'b.')
grid on
xlabel('X');ylabel('Y');zlabel('Z');
view([15 50 30])
title("Original Curve - Figure A")
% adjust the x and x vectors before we apply the rotation
M_rot = M1(:,[2 1]);
% find the mean of the curve in the x-y axis, we will use this point as rotation center
P0 = mean(M_rot,1);
% shift grid to the center for the rotation
M_rot = M_rot - repmat(P0,size(M1, 1),1);
% set up the rotation matrix about the z-axis
Rot = @(x) [cosd(x) -sind(x); sind(x) cosd(x)];
% rotate the shifted grid with 180 degrees
M_rot = (Rot(180) * M_rot')';
% shift the curve back to its own centroid
M_rot = M_rot + repmat(P0,size(M1, 1),1);
figure
current_z = z * ones(size(M_rot, 1), 1);
plot3(M_rot(:,1), M_rot(:,2), current_z, 'b.')
grid on
xlabel('X');ylabel('Y');zlabel('Z');
view([15 50 30])
title("Rotated Curve - Figure A")
  댓글 수: 3
Star Strider
Star Strider 2022년 12월 20일
The rotate function can rotate multiple plots at once, and keep their relative positions unchanged. They can slso be rotated individually.
t = linspace(0, 1, 500);
r = 1;
x = r*cos(2*pi*t) + [0; 0; 0];
y = r*sin(2*pi*t) + [0; 0; 0];
z = ones(size(t)) + [0; 1; 2];
figure
hold on
for k = 1:size(x,1)
hp3(k) = plot3(x(k,:), y(k,:), z(k,:)); % Three Separate 3D Plots
end
hold off
grid on
axis('equal')
view(60,30)
xlabel('X')
ylabel('Y')
zlabel('Z')
title('Original')
figure
hold on
for k = 1:size(x,1)
hp3(k) = plot3(x(k,:), y(k,:), z(k,:)); % Three Separate 3D Plots
end
hold off
grid on
axis('equal')
view(60,30)
xlabel('X')
ylabel('Y')
zlabel('Z')
rotate(hp3, [1 2 0], 45) % Call 'rotate'
title('Rotated Original')
Make appropriate changes to work with your data.
Thanking @Karim again for solving the .mat file load problem using the online Run feature, so not posting this as a separate Answer.
.
Alberto Acri
Alberto Acri 2022년 12월 20일
I thank you both.
I modified that line as:
P0 = [A/2, B/2]; % where A and B are the size of the image on x and on y.
I will also keep an eye on your solution @Star Strider in case I need it in the future.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by