% function square_transform(len,angle_rad) % % Square transform - rotation. % % Input: % 1. len - the side of the square; % 2. angle_rad - the angle in radians, by which the square % should be rotated. % a=-len/2; % the corner of the square - bottom-left b=-len/2; x(1)=a; x(2)=x(1)+len; x(3)=x(2); x(4)=x(1); x(5)=x(1); %-------------------- y(1)=b; y(2)=y(1); y(3)=y(2)+len; y(4)=y(3); y(5)=y(1); v0=[x;y]; % v(1,i) - row 1, column i. Transform_M=[ [cos(angle_rad) sin(angle_rad)]; [-sin(angle_rad) cos(angle_rad)]]; % do not forget (-) minus sign. v=Transform_M*v0; for i=1:4 % line([x(i) x(i+1)],[y(i) y(i+1)]); line([v(1,i) v(1,i+1)] , [v(2,i),v(2,i+1)]); % text(x(i),y(i),num2str(i)); end % i %