Re Ellipse Distance Intersection by TaylorRandle


									                                    Re: Ellipse Distance / Intersection

Re: Ellipse Distance / Intersection


      • From: Duncan Muirhead <dmuir@xxxxxxxxx>
      • Date: Mon, 29 Oct 2007 18:42:57 +0000

On Sat, 27 Oct 2007 09:13:12 −0500, Stephan Rose wrote:

       Hi all,

       I'm working on some software where I need to do distance / intersection
       checks between object outlines. These outlines are composed of line
       segments and curve segments. The curve segments are basically just
       partial ellipses, so no bezier curves or anything like that.

       Line vs Line checks are simple enough but when it comes to checking
       anything against the ellipses is where I've been running into some

       I do currently have a working implementation that does give reasonably
       good results and does appear to be watertight. However, it relies very
       heavily on iteration, especially when checking an ellipse against another
       ellipse where I end up with nested iterations to solve it.

       My math background though is somewhat rusty. I spent most my years in
       high school doing a lot of math, but it's been a few years since then and
       has all rusted in place a bit as I usually don't get much of a chance to
       apply any of it until now. =)

       So what I would like to ask is, can anyone give me some suggestions as to
       some ways I could use to more elegantly solve these problems?

       Essentially, the cases are as follows:

       Distance between point and ellipse

       Distance/Intersection between line segment and ellipse

       Distance/Intersection between ellipse and ellipse

       Any help and information would be highly appreciated,


Re: Ellipse Distance / Intersection                                                1
                                       Re: Ellipse Distance / Intersection

Distance from an ellipse to a point:
This sort of thing is done in geodesy.
Some notation: (sorry if I'm labouring the obvious)
Assume the coordinates have been chosen so that the ellipse
is (x/a)^2 + (y/b)^2 = 1, where a > b.
The geodetic latitude of a point on an ellipse is the angle between the
normal at the point and the x axis. It's often denoted phi, and we have
x= nu*cos(phi), y=(1−e2)*nu*sin(phi)
b^2 = a^2*(1−e2) defines the eccentricity squared e2 of the ellipse
nu(phi) = a/sqrt( 1−e2*sin(phi)^2)

We get a coordinate system by letting a points coordinates be
phi, h. Here phi is the foot of the normal to the ellipse on which
the point lies and h the "height above the ellipse" ie the distance
along the normal from the ellipse to the point.]
x = (nu+h)*cos(phi)
y = ((1−e2)*nu + h)*sin(phi).
The usual approach to solving finding phi, h given x,y is
to rearrange the x,y equations to get phi − atan2( y+e2*nu, x) = 0
and then solve this via newton raphson starting at
phi = atan2( y, (1−e2)*x)
Given phi we can recover h as hypot( x, y+e2*nu)−nu

One way to test whether a line segment/ellipse and an ellipse
intersect would be to apply a shear to transform the second ellipse
into a circle, and then test whether the sheared line segment (which
is still a line segment) or sheared ellipse (an ellipse) intersects
the circle (ie in the latter case whether the centre of the circle is at
most the circle radius from the ellipse)

If an infinite line does not intersect an ellipse, then the line
joining the closest points must be normal to the line and the ellipse.
Knowing the normal to the line, we know the geodetic
latitude of the point on the ellipse to be either atan2(beta, alpha)
(where the line is alpha*x+beta*y+gamma=0) or the negative of this, so
we can compute the points on the ellipse at these latitudes and
see which is closer to the line.

I think the ellipse/ellipse distance can be solved this way, though
here I'm writing off the top of my head.
If we choose coordinates so that one ellipse is standard, then the
other will be translated (by (c,d) say) and rotated (by a say).
In terms of this second ellipse's local geodetic latitude p we will
have the point
(x) = (c) + R(a)*(nu(p)*cos(p))
(y) (d) ((1−e2)*nu(p)*sin(p))
on the ellipse and the normal to the ellipse has azimuth p+a

Re: Ellipse Distance / Intersection                                          2
                                  Re: Ellipse Distance / Intersection
(Here R(a) is the rotation matrix).
Again, for two non−intersecting ellipses the line between the closest
points must be normal to both.
If the azimuth of this line is phi, we have from the first ellipse
that the line goes through
(nu*cos(phi), (1−e2)*nu*sin(phi)) and has azimuth phi, and from the
second ellipse that
(X) = (c) + R(a)*(nu(p)*cos(p))
(Y) (d) ((1−e2)*nu(p)*sin(p))
where p = −(phi+a)
is on the line too, so we get at equation
(X−nu(phi)*cos(phi))*sin(phi) − (Y−(1−e2)*nu(phi)sin(phi))*cos(phi) = 0
to solve for phi, say via newton raphson.
I guess a reasonable starting phi would the the azimuth of the centre
of the second centre from the first, ie atan2(d,c).
As I said, I don't know if this would work...


Re: Ellipse Distance / Intersection                                       3

To top