How can i rotate an ellipse?

74 visualizaciones (últimos 30 días)
anderson95
anderson95 el 27 de Mayo de 2017
Respondida: MathReallyWorks el 27 de Mayo de 2017
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]);

Respuesta aceptada

MathReallyWorks
MathReallyWorks el 27 de Mayo de 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.

Más respuestas (1)

KSSV
KSSV el 27 de Mayo de 2017

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by