MATLAB: How can i rotate an ellipse

ellipserotate

Im wondering how i can rotate an ellipse to a bearing/azimuth of 30deg about the xcenter and ycenter. Below is an example of how i have plotted the ellipse.
Thanks
xCenter = 50;
yCenter = 50;
xRad = 25;
yRad = 100;
theta = 0 : 0.01 : 2*pi;
x = xRad * cos(theta) + xCenter;
y = yRad * sin(theta) + yCenter;
plot(x, y, 'r');
axis([-50 150 -100 200]);

Best Answer

Hello,
Use this:
clc;
xc=50; %xCenter
yc=50; %yCenter
a=25; %xRad
b=100; %yRad
m = 1000;
x = zeros(m,1);
y = zeros(m,1);
theta = linspace(0,2*pi,m);
for k = 1:m
x(k) = a * cos(theta(k));
y(k) = b * sin(theta(k));
end
alpha = input('Enter the rotation angle');
R = [cos(alpha) -sin(alpha); ...
sin(alpha) cos(alpha)];
rCoords = R*[x' ; y'];
xr = rCoords(1,:)';
yr = rCoords(2,:)';
plot(x+xc,y+yc,'r');
grid on;
hold on;
axis equal;
plot(xr+xc,yr+yc,'b');
Red ellipse is the original one and Blue is the rotated one.