Rotation of an xy coordinate system

81 views (last 30 days)
xRah
xRah on 30 Oct 2020
Commented: xRah on 30 Oct 2020
Hi fellow MatLabbers, this is my first post. I hope I hang around here and ask questions and hopefully answer some at some point.
So... My first post question is:
I have a triangle with vectors (1,0) (2,4) and (-2,2) and I am supposed to rotate it by 2pi/3 in respect to the ORIGIN. Then I need to calculate the new coordinates after the rotation. Then I need to plot both the original and rotated triangle. This is what I have so far:
-----------
clear all
x = [1 2 -2 1];
y = [0 4 2 0];
theta = (2*pi)/3;
v=[x;y];
R = [cos(theta) sin(theta); -sin(theta) cos(theta)];
so = R*v;
x_rotated = so(1,:);
y_rotated = so(2,:);
% make a plot
plot(x, y, 'k-', x_rotated, y_rotated);
axis equal
x_rotated
x_rotated = 1×4
-0.5000 2.4641 2.7321 -0.5000
y_rotated
y_rotated = 1×4
-0.8660 -3.7321 0.7321 -0.8660
-----------
I am not entirely sure if my result is correct because I assume since it needs to rotate in respect to the origin, the first vector should? stay the same.

Accepted Answer

Matt J
Matt J on 30 Oct 2020
Looks fine to me. When you rotate about the origin, the only point that stays fixed is the origin.
  3 Comments
Matt J
Matt J on 30 Oct 2020
The origin is the point x,y=(0,0). None of your vertices are located there.
xRah
xRah on 30 Oct 2020
Thanks for your input. I will accept your reply as answer soon if nobody objects :) I appreciate your help.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!