MATLAB Answers

How can i rotate an ellipse?

250 views (last 30 days)
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]);

  0 Comments

Sign in to comment.

Accepted Answer

MathReallyWorks
MathReallyWorks on 27 May 2017
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.

  0 Comments

Sign in to comment.

Sign in to answer this question.