Mathematica Asked by user153012 on June 16, 2021
Five points are required to define a unique ellipse. An ellipse has five degrees of freedom: the $x$ and $y$ coordinates of each focus, and the sum of the distance from each focus to a point on the ellipse, or alternatively, the $x$ and $y$ coordinates of the center, the length of each radius, and the rotation of the axes about the center.
I need a function, that fits an ellipse, for given five $(x,y)$ pairs. Is there a function in Mathematica to do that? If it’s possible I need a plot with the ellipse and the given points, and also the equation of the fitted ellipse.
I need an other function, that could check that if a point is on an ellipse. For example on an ellipse, that we just fitted with the previous function.
The following is based on the fact that the determinant of a matrix is equal to zero when two rows are the same. Thus, if you plug any of the points in, you get a true statement.
SeedRandom[3];
pts = RandomReal[{-1, 1}, {5, 2}];
row[{x_, y_}] := {1, x, y, x*y, x^2, y^2};
eq = Det[Prepend[row /@ pts, row[{x, y}]]] == 0
(* Out:
0.0426805-0.0293168x-0.155097x^2-0.019868y-0.087933x*y-0.061593y^2 == 0
*)
ContourPlot[Evaluate[eq], {x, -1, 1}, {y, -1, 1},
Epilog -> Point[pts]]
Correct answer by Mark McClure on June 16, 2021
The general equation of an ellipse (here) is given by:
ellipse[x_, y_] = a x^2 + b x y + c y^2 + d x + e y + f == 0;
solving using 5 points results in:
SeedRandom[3];
pts = RandomReal[{-1, 1}, {5, 2}];
sol = Solve[ellipse @@@ pts];
ellipse[x, y] /. sol[[1]] // Simplify
(*a (-0.275185 + 1. x^2 + x (0.189022 + 0.566953 y) + 0.1281 y +
0.397124 y^2) == 0*)
all $a$ values result in the same equation except when $a=0$.
Answered by Basheer Algohi on June 16, 2021
Through 5 points we can pass a conic, an ellipse, hyperbola etc. After Algohi's solution coefficients are obtained we can determine choice of conic by sign of the second evaluated invariant $ (b^2 - 4 a c) $ along with standard calculated expression for values of rotation/translation of central conic.A sign change test for a test point chosen inside or outside can be done,it should vanish on the arc.
Answered by Narasimham on June 16, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP