Equation ellipse with foci at origin

11 views (last 30 days)
Martin
Martin on 26 Feb 2022
Edited: Torsten on 26 Feb 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

Accepted Answer

Torsten
Torsten on 26 Feb 2022
Edited: Torsten on 26 Feb 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)

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!