Ellipse / vector intersection

Started by
2 comments, last by d00fus 16 years, 2 months ago
Quick question: If I've got an ellipse - centred on the origin - and a vector of any length coming from the centre, how can I find the point on the perimeter of the ellipse at which the two will intersect? Thanks. :)
Advertisement
Transform the ellipse to a unit circle. Then apply the same transformation to the vector. Find the intersection of the vector with the unit circle. Then transform this intersection point back.

If your ellipse is axis-aligned, the transformations are simple - just scaling by the ellipse extents (or 1/extents).
Equating the two equations (one for each spatial component) describing the ellipse with the corresponding equation for each spatial component of the equation describing your line will yield two equations in two unknowns which when solved will give you the point of intersection.
For example you can parametrize your ellipse as:

x(t) = x0 + a * cos(t)
y(t) = y0 + b * sin(t)

where x0 and y0 are the coordinates of the center of the ellipse, in your case both zero; and a and b are the two ellipse "radi"; and t is the parameter you wish to find.
Your line can be parametrized as:

x(k) = x0 + k * cos(h)
y(k) = y0 + k * sin(h)

where h is the angle the line makes with the positive x-axis, and k is your unknown parameter.

In your case the equations will thus be:

a * cos(t) = k * cos(h)
b * sin(t) = k * sin(h)

from the first equation we get:

k = a * cos(t) / cos(h)

inserting this in the second equation yields:

b * sin(t) = a * cos(t) * sin(h) / cos(h) =>
tan(t) = (a / b) * tan(h) =>
t = atan[(a/b) * tan(h)]

a, b and h are known and thus you have t. Inserting this in the above equations for the ellipse yields the x and y coordinates of the intersection point.

Hopefully I didn't make any mistakes there [smile]
Best regards, Omid
Just to add yet another approach:

The Cartesian equation for an ellipse is:

x2/a2 + y2/b2 = 1

where a is the x extent and b the y extent of the ellipse. Solving simultaneously with the equation for the line l = td (where d is the direction vector [x,y]) gives:

t = sqrt(a2b2/(b2x2 + a2y2))

Only the positive root is needed in your case.

This topic is closed to new replies.

Advertisement