distance from given point to given ellipse

后端 未结 7 1943
抹茶落季
抹茶落季 2021-02-05 08:07

I have an ellipse, defined by Center Point, radiusX and radiusY, and I have a Point. I want to find the point on the ellipse that is closest to the given point. In the illustrat

7条回答
  •  盖世英雄少女心
    2021-02-05 08:28

    Consider a bounding circle around the given point (c, d), which passes through the nearest point on the ellipse. From the diagram it is clear that the closest point is such that a line drawn from it to the given point must be perpendicular to the shared tangent of the ellipse and circle. Any other points would be outside the circle and so must be further away from the given point.

    enter image description here

    So the point you are looking for is not the intersection between the line and the ellipse, but the point (x, y) in the diagram.

    Gradient of tangent:

    enter image description here

    Gradient of line:

    enter image description here

    Condition for perpedicular lines - product of gradients = -1:

    enter image description here

    enter image description here

    enter image description here

    When rearranged and substituted into the equation of your ellipse...

    enter image description here

    ...this will give two nasty quartic (4th-degree polynomial) equations in terms of either x or y. AFAIK there are no general analytical (exact algebraic) methods to solve them. You could try an iterative method - look up the Newton-Raphson iterative root-finding algorithm.

    Take a look at this very good paper on the subject: http://www.spaceroots.org/documents/distance/distance-to-ellipse.pdf

    Sorry for the incomplete answer - I totally blame the laws of mathematics and nature...

    EDIT: oops, i seem to have a and b the wrong way round in the diagram xD

提交回复
热议问题