0

I'm trying to plot the vertices of an ellipse of the form:

$Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0$.

Here's my attempt:

A = -0.009462052409440;
B = 0.132811666715687;
C = -0.991096125887092;
D = 1.450474988439371;
E = -10.108254824293347;
F = -55.282226665842030;

% semi-major axis a = -sqrt(2(AE^2 + CD^2 - BDE + (B^2 - 4AC)F)((A+C) + sqrt((A-C)^2 + B^2)))/(B^2-4A*C); % semi-major

% semi-minor axis b = -sqrt(2(AE^2 + CD^2 - BDE + (B^2 - 4AC)F)((A+C) - sqrt((A-C)^2 + B^2)))/(B^2-4A*C); % semi-minor

% centre of ellipse xx = (2CD -BE)/(B^2-4AC); yy = (2AE - BD)/(B^2-4AC);

% the angle from the positive horizontal axis to the ellipse's major axis if B ~= 0 theta = atan(1/B*(C-A-sqrt((A-C)^2 + B^2))); elseif A < C theta = 0; else theta = pi/2; end

% plot ellipse fimplicit(@(x,y) Ax.^2 +Bx.y + Cy.^2 + Dx + Ey + F,'--') xlim([68,86]) ylim([-1,1])

% plot centre point hold on plot(xx,yy,'rx')

% plot vertices plot(xx + acos(theta),yy + asin(theta),'rx') plot(xx + acos(-theta),yy + asin(-theta),'rx') plot(xx + bcos(theta+pi/2),yy + bsin(theta+pi/2),'rx') plot(xx + bcos(theta-pi/2),yy + bsin(theta-pi/2),'rx')

Result:

enter image description here

Clearly something is not quite right, but I can't seem to figure it out.

The formulae for axes and angle are taken from here: https://en.wikipedia.org/wiki/Ellipse#General_ellipse

The ellipse needs to remain in its original form, so no transformations or rotations in the final result please.

1 Answers1

1

Everything is correct, I've just checked your formulas with GeoGebra. Your plot looks wrong because $x$ and $y$ axes don't have the same scale: to obtain a correct visualisation you need an aspect ratio $x:y=1$.

enter image description here

Intelligenti pauca
  • 50,470
  • 4
  • 42
  • 77