MATLAB: Rotating a line using rotation matrix

MATLABmatrix manipulationmatrix multiplicationrotationrotation matrix

I have this function thats supposed to rotate a 2×2 matrix (arm) by theta.
I think i have to multiply the arm matrix by a rotation matrix to be given the new arm but i can't figure out how to do it. I keep getting error messages saying that arm and the rotation matrix is of different sizes.

Best Answer

L = rand(2,2) ; % line
% Rotation matrix
R = @(theta) [cos(theta) -sin(theta) ; sin(theta) cos(theta)] ;
% Get mean
m = mean(L) ;
L1 = m+(L-m)*R(pi/2) ; % rotate line by 45 degrees
plot(L(:,1),L(:,2),'r',L1(:,1),L1(:,2),'b')
Related Question