How can i rotate an ellipse?

조회 수: 74 (최근 30일)
anderson95
anderson95 2017년 5월 27일
답변: MathReallyWorks 2017년 5월 27일
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