Equation ellipse with foci at origin

10 vues (au cours des 30 derniers jours)
Martin
Martin le 26 Fév 2022
Modifié(e) : Torsten le 26 Fév 2022
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

Réponse acceptée

Torsten
Torsten le 26 Fév 2022
Modifié(e) : Torsten le 26 Fév 2022
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)

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by