rotate the coordinates plotted with plot3 without changing the axes

10 views (last 30 days)
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.

Accepted Answer

Karim
Karim on 20 Dec 2022
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 Comments
Alberto Acri
Alberto Acri on 20 Dec 2022
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.

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by