So arbitrary ellipses seem to have two more degrees of freedom than circles, because in addition to a circle's radius and center there is the angle of rotation as well as the scaling of the ratio of the major axis to the minor axis (which circles do not have). So, I would have to check but I believe it is 5 distinct points that are needed to uniquely define an ellipse passing through those points, possibly subject to some restrictions on the points, such as no point is in the convex hull of any other 3. Anyway, let's say that in general you need a certain number of points to define a unique ellipse (probably 4 or 5 points) passing through them. Let's say we have more than that number of points. If we are dealing in IEEE floating point, say 64-bit, subject to round-off error in the mantissa, what is a robust way to determine whether the points MAY lie on a common ellipse, provided that round-off error in the points' manitissas can explain any discrepancy? Ideally I'd like to avoid extended precision arithmetic to get the answer, but if that is required, so be it, as long as its use and added running time can be minimized.
-
What specifically do you mean by "up to roundoff error" here? – tmyklebu Aug 03 '15 at 19:03
-
@tmyklebu I mean, ff we assume that each floating point number was the result of some basic calculation that involved simple round-off error (rounding the last digit of precision either up or down), then can this limited precision uncertainty in each number explain how all the 2-d floating points could possibly lie on a common ellipse? Or would we need more error in one or more floating points to explain how all 2-d points could be on an ellipse? – user2566092 Aug 03 '15 at 19:48
-
@tmyklebu It's basically a question of whether a collection of arbitrary real number pairs, each number within a certain range (as specified by floating point finite precision), could possibly all lie on a common ellipse. – user2566092 Aug 03 '15 at 19:52
-
That isn't too helpful. What's the connection between the real numbers and the floating-point numbers? Given a real number and a floating-point number, how do I tell if the real number "is" the floating-point number "up to roundoff error"? – tmyklebu Aug 03 '15 at 20:15
-
@tmyklebu Assuming standard round-off in floating point calculations/representations, and that the errors haven't accumulated, it's simple. Take the mantissa of a floating point number. Then the "true" real valued number that it represents, when expressed in floating point, could be anything from -0.5 to +0.5 added to the least signifcant bit in the mantissa. We can imagine having a true real valued number in between those extremes. So then the question is, assuming the true real valued numbers are in those ranges, could the points possibly all be on an ellipse? – user2566092 Aug 03 '15 at 21:33
-
So you're comfortable assuming each real gets rounded to the nearest floating-point number. That means you want to know whether there exists an ellipse that passes through a handful of rectangles. I don't know an easy way to do this, especially without involving extra precision. – tmyklebu Aug 04 '15 at 03:54
-
@user2566092: The way you phrase the question, it sounds as though you already know how to do this for circles (e.g., given four points rather than six). Is that the case? If so, do you have a link? – Mark Dickinson Aug 04 '15 at 11:03
-
And yes, [five points determine a conic](https://en.wikipedia.org/wiki/Five_points_determine_a_conic), though that conic may or may not be an ellipse. – Mark Dickinson Aug 04 '15 at 11:04
-
@user2566092 added answer please have a look at the linked Q/A's too. Have you some sample data to test on? what language you want to use? how many dimensions (2D,3D,n-D) ? how many points you have (min,max,average)? – Spektre Aug 05 '15 at 08:06
-
1"up to roundoff errors" for the result may be really hard to achieve, because the results of intermediate calculations will likely accumulate more error than that would allow. did you intend that? – Silly Freak Aug 05 '15 at 18:49
-
@SillyFreak Yes, exactly, that's what worries me. Ideally I'd like to treat the points as correct up to round-off in the least significant bit, because they come from e.g. measurements, but it seems like to answer my question I'm going to have to at least probably use extended precision. – user2566092 Aug 06 '15 at 16:41
-
@tmyklebu Yes, determining whether there is an ellipse that passes through the rectangle for each point (rectangles defined by round-off) is the proper pure geometric statement of my proposed problem. – user2566092 Aug 06 '15 at 16:43
-
@MarkDickinson Jonathan Shewchuck has what he calls "robust predicates" that can determine whether a 4th point is inside or outside or potentially on the circle defined by the other 3 points. I know it uses extended precision that can go on to very high precision before making the determination. However, one key difference is that Shewchuck assumes the given points are "correct," and only uses robust predicates to make the inside/outside call on the alleged "correct" points. I'd like to answer the question taking into account uncertainty (round-off error) in the given floating point numbers. – user2566092 Aug 06 '15 at 16:53
-
@user2566092: That's rather a huge key difference, though: in Shewchuk's situation he's simply computing some carefully-chosen values with as much extended precision as necessary to avoid loss of precision. In your situation, you're asking for something much more sophisticated. Just characterising all circles that pass through a *single* point "up to roundoff error" is going to be pretty messy. – Mark Dickinson Aug 06 '15 at 17:45
-
@user2566092: You may get better answers on math.stackexchange.com, especially if you phrase the question in terms of whether there's an ellipse passing through 6 or more given small rectangles (which is pretty much what this question amounts to). – Mark Dickinson Aug 06 '15 at 17:47
2 Answers
I would fit the best ellipse you can to your point set and then compute the error of points positions to it.
Finding/fitting ellipse:
If you have many points dispersed along whole circumference
compute middle point point
C
(middle of bounding box) and find closestB
and most farA
points to it.C
- is the centerCA
is major axisCB
is semi major axis
if you have just few points or not covering whole circumference
ellipse equation with use of basis vectors
a,b
:x(t)=x0+ax*cos(t)+bx*sin(t); y(t)=y0+ay*cos(t)+by*sin(t);
a=(ax,ay)
is major axis vectorb=(bx,by)
is semi major axis vector(x0,y0)
is center pointt=<0,2.0*PI>
is the angular parameter(x(t),y(t))
is point on circumference
We know that
a,b
are perpendicular to each other so in 2D:bx= ay*|b|/|a|; by=-ax*|b|/|a|;
in that case we need at least 5 points. In case of 3D we need 6 points or somehow exploit cross product. Anyway this system of equations would most probably lead to transcendental equations so I would not even try to solve this algebraically but instead use approximation search see:
so just nest for approximation for
x0,y0,ax,ay,|b|/|a|
and computebx,by
then compute cumulative errore=(sum of distances of points to ellipse)
and that is it.
Computing the distance of point and ellipse can be tricky
I would construct homogenous transform matrix representing ellipse coordinate system:
a
will be the x axisb
will be the y axis(x0,y0)
will be the originthen if you need to compute smallest distance between point
(xi,yi)
and ellipse transform(xi,yi)
to ellipse coordinate system (multiply by inverse matrix) and let call the result(Xi,Yi)
This can be done also by dot products instead of inverse matrix ...Then compute its mean angle on circle
t=atan2(Yi*|a|/|b|,Xi)=M
then compute point on that angle in real ellipse
x(t),y(t)
and the distance is thend=|(xi-x(t),yi-y(t))|
Now the error evaluation of yours
after approximation search found best fitted ellipse compute min distance of each point to it and remember/compute min,max,average
distances. From that you now can estimate the error properties you need for example if (max<=round_error) ...
[Notes]
- 5 or 6 nested approximation loops can take a lot of time
O(log^6(n))
so try to set the solution bounds as close as you can. Do not use too many recursion layers. - Also you can combine both approaches first find A,B,C from many points and then use that as start solution and use approx search near that initial solution
- In 2D you can also construct
(ax,ay),(bx,by)
from|a|,|b|,angle
-
Thanks for the thorough answer. Like I said for the other answer, I fear that the computations you suggest will introduce new round-off errors (at least, if done without extended precision) and so it may be possible that SOME ellipse (maybe not expressible with standard floating point precision) CAN fit the points, assuming the points have round-off error in the least significant precision bit, and yet I'm not sure if these outlined methods can always detect that. – user2566092 Aug 06 '15 at 15:28
This is a nontrivial task, and numerous methods have been studied in the past. The topic is called "ellipse fitting" or "robust ellipse fitting". In the second case, you expect that a proportion of the points are not aligned on the ellipse (they are called outliers) and you don't want them to influence the fitting.
For a first approach, I would recommend you the RANSAC method:
choose five points at random; this is indeed what you need to define an ellipse
form a 6x6 matrix by plugging the coordinates of the five given points plus an unknown point, with rows (x², xy, y²,x, y, 1)
Developing the determinant of this matrix (6 cofactors), you will find the implicit equation of the ellipse,
a x² + b xy + c y² + d x + e y + f = 0.
- Then a goodness-of-fit is given by the sum (or maximum) of distances of the remaining points to the ellipse.
The Euclidean distance to an ellipse is an uneasy problem as it involves a quartic equation. A reasonable approximation is obtained by plugging the point coordinates in the LHS of the implicit equation and dividing the absolute value by the norm of the gradient.
Repeat the process with several point sets and keep the smallest global residue, this is your robust fit.
You can now look at individual residues.
-
Thanks, I'll look into this but I fear that the computations you suggest will introduce new round-off errors (at least, if done without extended precision) and so it may be possible that SOME ellipse (maybe not expressible with standard floating point precision) CAN fit the points, assuming the points have round-off error in the least significant precision bit, and yet I'm not sure if these outlined methods can always detect that. – user2566092 Aug 06 '15 at 15:26
-
@user2566092: I doubt that you can do without somehow evaluating the equation of the ellipse or equivalent computation that will be subjected to roundoff errors. Could you solve the same problem for a straight line ? – Aug 06 '15 at 15:41
-
I see your point, I think extended precision is probably going to be required here, and so then it's just a question of how much (which will depend on what kind of calculations are being done) – user2566092 Aug 06 '15 at 15:51