How can i rotate an ellipse?

69 次查看(过去 30 天)
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]);

采纳的回答

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

更多回答(1 个)

KSSV
KSSV 2017-5-27

类别

Help CenterFile Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by