MATLAB: How to plot an Ellipse

ellipsegraphmathematicsplot

I want to plot an Ellipse. I have the verticles for the major axis: d1(0,0.8736) d2(85.8024,1.2157) (The coordinates are taken from another part of code so the ellipse must be on the first quadrant of the x-y axis) I also want to be able to change the eccentricity of the ellipse.

Best Answer

Let (x1,y1) and (x2,y2) be the coordinates of the two vertices of the ellipse's major axis, and let e be its eccentricity.
a = 1/2*sqrt((x2-x1)^2+(y2-y1)^2);
b = a*sqrt(1-e^2);
t = linspace(0,2*pi);
X = a*cos(t);
Y = b*sin(t);
w = atan2(y2-y1,x2-x1);
x = (x1+x2)/2 + X*cos(w) - Y*sin(w);
y = (y1+y2)/2 + X*sin(w) + Y*cos(w);
plot(x,y,'y-')
axis equal
Related Question