Find points on an ellipse in the xy-plane given the quadratic equation using symbolic variables.

9 views (last 30 days)
Hi,
I'm am trying to find points on an ellipse given a certain quadratic equation e.g. -0.0204*x^2 -0.0084*x*y + 0.5750*x - 0.0076*y^2 + 0.3871*y - 6.4044 = 0 . Here, x and y are symbolic the symbolic variables (syms x y).
This equation is generated using another script and is the projection of a rotated 3D-ellipsoid on the xy-plane. I need to find these points automatically, because I have to repeat this process countless times. My current code is shown below and I am using R2010a.
Thanks in advance!
% Rotation matrix
W = angle2dcm(123*pi/180, 234*pi/180, 23*pi/180);
% Center point ellipse
x0 = 10; y0=20; z0=20;
% Minor axis ellipse
a = 10; b = 5; c = 2;
% Diagonal matrix
D = [1/a^2 0 0; 0 1/b^2 0; 0 0 1/c^2];
% New rotated diagonal matrix
D2 = W*D*transpose(W);
x = sym('x'); y = sym('y');
Q = [x; y; 0];
U = [0; 0; 1];
C = [x0; y0; z0];
a2 = transpose(U)*D2*U;
a1 = (transpose(U)*D2*(Q-C)) + transpose(Q-C)*D2*U;
a0 = transpose(Q-C)*D2*(Q-C) - 1;
variableName = a1^2 - 4*a0*a2;

Accepted Answer

Roger Stafford
Roger Stafford on 19 Jul 2014
Diederik, it is not clear what you mean by "find points on an ellipse", since there are infinitely many such points. Presumably you mean find many closely-spaced points so that the ellipse can be plotted.
Also since you "have to repeat this process countless times" it would probably be unwise to do so using symbolic methods which are comparatively slow, so I have given here a numerical method of using a set of coefficients A, B, C, D, E, and F in the quadratic equation
A*x^2 + B*x*y + C*y^2 + D*x + E*y + F = 0
to generate the plot of the corresponding ellipse.
Here is the code, assuming that A, B, C, D, E, and F have been defined:
e = 4*A*C-B^2; if e<=0, error('This conic is not an ellipse.'), end
x0 = (B*E-2*C*D)/e; y0 = (B*D-2*A*E)/e; % Ellipse center
F0 = -2*(A*x0^2+B*x0*y0+C*y0^2+D*x0+E*y0+F);
g = sqrt((A-C)^2+B^2); a = F0/(A+C+g); b = F0/(A+C-g);
if (a<=0)|(b<=0), error('This is a degenerate ellipse.'), end
a = sqrt(a); b = sqrt(b); % Major & minor axes
t = 1/2*atan2(B,A-C); ct = cos(t); st = sin(t); % Rotation angle
p = linspace(0,2*pi,500); cp = cos(p); sp = sin(p); % Variable parameter
x = x0+a*ct*cp-b*st*sp; y = y0+a*st*cp+b*ct*sp; % Generate points on ellipse
plot(x,y,'y.'), axis equal % Plot them
You can use the following as a measure of the maximum amount of deviation from the perfect ellipse due to round-off error.
max(abs(A*x.^2+B*x.*y+C*y.^2+D*x+E*y+F))
  3 Comments
Prabin
Prabin on 14 Mar 2015
Edited: James Tursa on 16 Jul 2018
Hi Roger,
Thank you for your answer. I was also trying to do the same thing and the way you described above works perfectly works for me too but i was confused with some of the calculation that you have perform to find major and minor axis.Do you have any reference that will help me to understand how you have derived the equation using the coefficients. Thanking you in advance
Regards, Prabin
supernoob
supernoob on 16 Jul 2018
Edited: supernoob on 16 Jul 2018
Hi Roger, thanks so much for this response. Could you please point me to the place where you are finding these equations? I am looking at http://mathworld.wolfram.com/Ellipse.html and I can't, for example, figure out why you define F0 and a and b as such. Thanks in advance!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!