I want to improve a collision system.
Right now I detect if 2 irregular objects collide if their bounding rectangles collide.
I want to obtain the for recta
Supposing: the ellipse is centred at the origin and with the semi-major axis (of length a) oriented along the x axis, and with a semi-minor axis of length b; E2 is the eccentricity squared, ie (aa-bb)/(a*a); the circle is centred at X,Y and of radius r.
The easy cases are: the circle centre is inside the ellipse (ie hypot(X/a, Y/b) <= 1) so there is an intersection; the circle centre is outside a circle centred at 0 of radius a+r (ie hypot(X,Y) > a+r) so there isn't an intersection.
One approach for the other cases is to compute the geodetic coordinates (latitude, height) of the circle centre. The circle intersects the ellipse if and only if the height is less than the radius.
The geodetic latitude of a point on an ellipse is the angle the normal to the ellipse at the point makes with the x axis, and the height of a point outside the ellipse is the distance of the point from the point on the ellipse closest to it. Note the geodetic latitude is not same as the polar angle from the ellipse centre to the point unless the ellipse is in fact circular.
In formulae the conversion from geodetic coordinates lat,ht to cartesian coordinates X,Y is X = (nu+ht)*cos(lat), Y = (nu * (1-E2) + ht)*sin(lat) where nu = a/sqrt( 1 - E2*sin(lat)sin(lat)). The point on the ellipse closest to X,Y is the point with the same latitude, but zero height, ie x = nucos(lat), y = nu * (1-E2) * sin(lat). Note that nu is a function of latitude.
Unfortunately the process of finding lat,ht from X,Y is an iterative one. One approach is to first find the latitude, and then the height.
A little algebra shows that the latitude satisfies lat = atan2( Y+ E2*nusin(lat), X) which can be used to compute successive approximations to the latitude, starting at lat = atan2( Y, X(1.0-E2)), or (more efficiently) can be solved using newton's method.
The larger E2 is, ie the flatter the ellipse is, the more iterations will be required. For example if the ellipse is nearly circular (say E2<0.1) then five iterations will get x,y below to within a*1e-12, but if the ellipse is very flat, e.g. E2=0.999 you'll need around 300 iterations to get the same accuracy!
Finally, given the latitude, the height can be computed by computing (x,y): x = nucos(lat), y = nu(1-E2)*sin(lat) and then h is the distance from x,y to the circle centre, h = hypot( X-x, Y-y)