At 7/18/09 03:31 PM, Paranoia wrote:
A geometrical method is probably the best - approximate your objects as ellipses or whatever and work out some mathematical method of determining whether or not there's an intersection (no idea whatsoever how you'd do this - there's probably some geometry whiz who can help you out).
This is for a circle, I'm not sure about ellipses. I'm not sure if this method would be wise because of the obvious inaccuracy of testing a bounding sphere, but nonetheless...
Lets take the centre of our circle to be (0,0) for ease. Your line looks to be finite so we'll take the 2 end points, if not you want 2 points one each side of the circle. Let these end points be (x1, y1) and (x2, y2). If you're familiar with the quadratic formula you would be familiar with the concept of the discriminant. For a circle this is in the form of:
r^2 * d^2 - D^2
where r is the radius of the circle
d is the distance between the end points
D is x1 * y2 - x2 * y1
So to put that into code, something like:
var r:uint = 25;
var p1:Point = new Point(-50, -171.5250437021);
var p2:Point = new Point(50, 50);
var xd:Number = p2.x - p1.x;
var yd:Number = p2.y - p1.y;
var d:Number = xd*xd + yd*yd;
var D:Number = p1.x * p2.y - p2.x * p1.y;
trace(r * r * d - D * D);
The output with these numbers should be approx 0. This means that it is more or less a tangent to our circle. If you draw the circle and line you should notice this. If the discriminant is > 0 then there is an intersection. If the discriminant is < 0 there is no intersection. If it is 0 then it is a tangent.
Anyway, this is all pointless as I'm gonna guess that circles aren't accurate enough for you :P