MATLAB: Rotation of an xy coordinate system

2dMATLABmatricesplotrotatetriangle

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.

Best Answer

Looks fine to me. When you rotate about the origin, the only point that stays fixed is the origin.