% plotRotatedShape.m
% Draws a random figure and does it again after rotating it
% J.M.Soler. Sep.2012

% Find n random points in the unit square, centered in the origin
clear all
n = 5;
r = rand(2,n)-0.5;

% Sort points according to angle
%phi = atan2( r(2,:), r(1,:) );
%[~,iphi] = sort(phi);
%r = r(:,iphi);

% Make last point equal to first one
r(:,n+1) = r(:,1);

% Rotate the points
angle = pi/4;         % 45 degrees
rrot = rotMat(angle)*r;

% Translate the points one unit along the x axis
rrot(1,:) = rrot(1,:)+1;

% Plot the original and rotated shapes
plot(r(1,:),r(2,:), rrot(1,:),rrot(2,:), [0,1],[0,0],'+','LineWidth',1.5)
axis equal
axis([-0.8,1.8,-0.8,0.8])
title(['A random shape before and after rotation by ', ...
       num2str(angle*180/pi),' degrees'])
set(gca,'FontSize',15)
