90° clockwise rotation of 2D coordinates
Show older comments
Hi. I cannot understand why the 90° clockwise rotation of the attached 2D coordinates (matrix.txt) is not done.
I have tried two different ways but I do not get the desired result.
1st way (using "rot90"):
matrix = importdata('matrix.txt');
Rmatrix = rot90(matrix,3); % I have to rotate 3 times 90° counterclockwise
figure
plot(Rmatrix(1,:), Rmatrix(2,:), 'k.')
axis equal
xlim([0 512]);
ylim([0 512]);
2nd way (using rotation matrix, more convenient):
matrix = importdata('matrix.txt');
theta = 90;
R = [cos(theta) -sin(theta); sin(theta) cos(theta)];
Rmatrix = R*matrix';
figure
plot(Rmatrix(1,:), Rmatrix(2,:), 'k.')
axis equal
xlim([0 512]);
ylim([0 512]);
2 Comments
As @Voss mentioned, rot90 rotates the array of data. Look how this 4x3 matrix turns into a 3x4 matrix and the top row moves to the first column and it gets fliped as if you moved your monitor 90deg counter clockwise.
x = randi(9,4,3)
rot90(x)
What is the problem with your second method using the rotation matrix?
Accepted Answer
More Answers (1)
matrix = importdata('matrix.txt');
p=polyshape(matrix(:,1), matrix(:,2),'Simplify',1);
[cx,cy]=centroid(p);
prot=rotate(p,90*3,[cx,cy]);
plot([p,prot]); axis equal
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


