Calculate the distance between a fixed point and an ellipse

31 Views Asked by At

I have happened upon a process to find how close a point (p) is to the edge of an ellipse, within a few percentile points of accuracy. It works as follows:

  1. Offset the ellipse so that its center is at the origin of the cartesian plane.
  2. Rotate the cartesian plane such that the max and min radii of the ellipse alligns with the axis of the cartesian plane.
  3. Determine in which axis the ellipse has the smaler radii and scale the ellipse radius and point coodinate in this axis such that the ellipse forms a circle.
  4. Calculate the gradient between the center of this circle and the scaled point.
  5. Scale this gradient by the inverse of the scale used in step 3.
  6. Repeat step 5.
  7. Scale the point coodinate in the axis used in step 3 by the inverse of the scale used in step 3.
  8. Assume a line with this gradient intersects the scaled point p from step 7, find where this line would then intersect the circle.
  9. Use this x value in your ellipse formula to the y at that coordinate.
  10. Determine the distance between p and (x, y).

Using an ellipse with an eccentricity of 10 yields results within 5% of the correct answer. With an ellipse with an eccentricity of 2 is within an accuracy of 1%.

Determining the distance between a point and an ellipse the proper way, with absolute accuracy, is long, tedious and computationally expensive. When asking how to determine this in the past, as well as in my google searches, all the results said the same answer. The closest point between an ellipse and a fixed point will occur when a line from the point to the ellipse is perpendicular to the tangent of the ellipse at that location. Get the derivatives, make them equal, etc.

Somehow this process yields results that are consistently close to the true result. I am not a mathematician, but perhaps somebody can expand upon this process to refine its accuracy further without requiring processing the math the traditional way.