Equation ellipse with foci at origin

조회 수: 10 (최근 30일)
Martin
Martin 2022년 2월 26일
편집: Torsten 2022년 2월 26일
Hello,
Here is the task that I have to finish:
In polar coordinates (r,t), the equation of an ellipse with one of its foci at the origin is: r(t) = a (1 − e^2) (1 − e · cos(t)) 2 where a is the size of the semi-major axis (along the x-axis) and e is the eccentricity. Write a Matlab script to plot ellipses using this formula, ensuring that the curves are smooth by selecting an appropriate number of points in the angular (t) coordinate. Use the command ’axis equal’ to set the proper axis ratio to see the ellipses.
This is my Matlab script to plot ellipses:
function r=ellipse(a,e)
numPoints=500;
t = linspace(0, 2 * pi, numPoints);
r=a.*(1-e.^2)./(1-e.*cos(t));
x=r.*cos(t);
y=r.*sin(t);
axis equal
plot(x,y);
end
My question is, how do I make it so one of it's foci is at the origin?
Thanks in advance,
Martin

채택된 답변

Torsten
Torsten 2022년 2월 26일
편집: Torsten 2022년 2월 26일
You already did it because ellipses that are given by r=a.*(1-e.^2)./(1-e.*cos(t)) automatically have one focus at the origin (as you've written yourself).
numPoints = 500;
a = 3; % length of semi-major axis
b = 2; % length of semi-minor axis
e = sqrt(1-b^2/a^2); %excentricity
phi = pi/4; % angle of the center of the ellipse from the origin
theta = linspace(0,2*pi,numPoints);
r=a.*(1-e.^2)./(1-e.*cos(theta-phi));
x=r.*cos(theta);
y=r.*sin(theta);
axis equal
plot(x,y)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by