MATLAB: Rotating a line given the angle and a vector

rotation of vector

I have 2 points (x1, y1) and (x2, y2). I want to rotate it clockwise by 123 deg and find the co-ordinate (x2', y2') after rotation. Can anyone help?

Best Answer

p1 = rand(2,1) ;
p2 = rand(2,1) ;
%%rotation matrix
th = 123*pi/180 ;
R = [cos(th) -sin(th) ;sin(th) cos(th)] ;
%%rotate points
pr2 = R*p2 ;
figure
hold on
plot([p1(1) p2(1)],[p1(2) p2(2)] ,'r') ;
plot([p1(1) pr2(1)],[p1(2) pr2(2)] ,'b') ;