Plotting the Vertices of a Rotated Ellipse with Non-Origin Centre (MATLAB)

304 Views Asked by At

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*(A*E^2 + C*D^2 - B*D*E + (B^2 - 4*A*C)*F)*((A+C) + sqrt((A-C)^2 + B^2)))/(B^2-4*A*C); % semi-major

% semi-minor axis
b = -sqrt(2*(A*E^2 + C*D^2 - B*D*E + (B^2 - 4*A*C)*F)*((A+C) - sqrt((A-C)^2 + B^2)))/(B^2-4*A*C); % semi-minor

% centre of ellipse
xx = (2*C*D -B*E)/(B^2-4*A*C); 
yy = (2*A*E - B*D)/(B^2-4*A*C);

% 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) A*x.^2 +B*x.*y + C*y.^2 + D*x + E*y + F,'--')
xlim([68,86])
ylim([-1,1])

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


% plot vertices
plot(xx + a*cos(theta),yy + a*sin(theta),'rx')
plot(xx + a*cos(-theta),yy + a*sin(-theta),'rx')
plot(xx + b*cos(theta+pi/2),yy + b*sin(theta+pi/2),'rx')
plot(xx + b*cos(theta-pi/2),yy + b*sin(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

There are 1 best solutions below

5
On BEST ANSWER

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