% ICE10 - Rotation matrices.


% Do a 2D rotation of a parabola.

theta = 55; theta = theta*pi/180; % rotation relative to x-axis

x = -1:.1:1;
y = x.^2;

subplot(1,2,1); xLim = 2; yLim = 2;
% plot axes (Matlab should do this, but I don't know how ...
plot([-xLim xLim],[0 0],'k'); hold on; plot([0 0],[-yLim yLim],'k')
plot(x,y,'k','linewidth',2); hold off; axis square

R = [cos(theta) sin(theta); -sin(theta) cos(theta)];
newCoords = R*[x;y];

subplot(1,2,2);
% plot axes (Matlab should do this, but I don't know how ...
plot([-xLim xLim],[0 0],'k'); hold on; plot([0 0],[-yLim yLim],'k')
plot(newCoords(1,:),newCoords(2,:),'k','linewidth',2); hold off; axis square
set(gcf,'Color',[1 1 1])


% Do a 2D rotation of an ellipse.

theta = 152; theta = theta*pi/180; % rotation relative to x-axis

a = 1; b = 2; % major and minor axes of ellipse
x = -1:.01:1; 
y1 = sqrt((1-a*x.^2)/b);  y2 = -sqrt((1-a*x.^2)/b);

subplot(1,2,1); xLim = 2; yLim = 2;
% plot axes (Matlab should do this, but I don't know how ...
plot([-xLim xLim],[0 0],'k'); hold on; plot([0 0],[-yLim yLim],'k')
plot(x,y1,'k.','linewidth',2); plot(x,y2,'k.','linewidth',2); 
hold off; axis square

R = [cos(theta) sin(theta); -sin(theta) cos(theta)];
newCoords = R*[x,x;y1,y2];

subplot(1,2,2);
% plot axes (Matlab should do this, but I don't know how ...
plot([-xLim xLim],[0 0],'k'); hold on; plot([0 0],[-yLim yLim],'k')
plot(newCoords(1,:),newCoords(2,:),'k.','linewidth',2); hold off; axis square
set(gcf,'Color',[1 1 1])
