Skip to main content
GameDev.net gamedev.net
🔒 Locked

Point distance from ellipse outline

Started by CloudNine Aug 24, 2006 at 11:50 AM 3 replies 4.1k views
Original Post
CloudNine
CloudNine
Hi, This is in a similar vein to my previous thread, involving GDI+ and ellipses (here). In short, I'd like to know a general formula for a 2 dimensional point's (shortest) distance from a ellipse's outline at any angle (if I've got the x,y, width and height of the ellipse). Thanks in advance, CloudNine
Zakwayda
Zakwayda
Quote:
Original post by CloudNine
Hi,

This is in a similar vein to my previous thread, involving GDI+ and ellipses (here). In short, I'd like to know a general formula for a 2 dimensional point's (shortest) distance from a ellipse's outline at any angle (if I've got the x,y, width and height of the ellipse).
The first step is to transform the point into the local space of the ellipse. This reduces the problem to that of finding the distance between a point and an axis-aligned ellipse centered at the origin.

The problem can be solved by finding the points on the ellipse for which the normal at that point is parallel to the vector from the point to the query point. The closest of these can then be used to compute the distance.

This reduces to solving a quartic equation. For details, see this paper. You can find example source code at the same site (geometrictools.com).

[Edit: Beaten. ]
CloudNine
CloudNine
Thanks for the linky - it's helpful! I'd just like to clarify some of the terms used in the example code - such as "extent". Would the extent of my ellipse be "width/2" and "height/2" in my case? It's definitely a harder task than I thought though.
Wasting Time
Wasting Time
Quote:
Original post by CloudNine
Would the extent of my ellipse be "width/2" and "height/2" in my case?


Yes. An input to the distance function is an Ellipse2 object. Look at the comments in the header file Wm3Ellipse2.h (on the Mathematics page of that web site).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.