views:

240

answers:

2

I'm using a Segment to Segment closest approach method which will output the closest distance between two segments of length. Each segment corresponds to a sphere object's origin and destination. The speed is simply from one point, to the other.

Closest Approach can succeed even when there won't be a real collision. So, I'm currently using a 10-step method and calculating the distance between 2 spheres as they move along the two segments. So, basically the length of each segment is the object's traverse in the physics step, and the radius is the objects radius. By stepping, I can tell where they collide, and if they collide (Sort of; for the MOST part.)..

I get the feeling that there could be something better. While I sort of believe that the first closest approach call is required, I think that the method immediately following it is a TAD weak. Can anyone help me out? I can illustrate this if needed.

Thanks alot! alt text

+2  A: 

Closest approach can be done without simulating time if the position function is invertible and explicit.

  1. Pick a path and object.
  2. Find the point on the path where the two paths are closest. If time has bounds (e.g. paths are line segments), ignore the bounds in this step.
  3. Find the time at which the object is at the point from the previous step.
  4. If time has bounds, limit the picked time by the bounds.
  5. Calculate the position of the other object at the time from the previous step.
  6. Check if the objects overlap.

This won't work for all paths (e.g. some cubic), but should work for linear paths.

outis
In the case where two objects are moving in two segments which form a sort of 'V' shape, with them originating at the top of the V, their actual collision point wouldn't be the closest approach, it would actually be before it due to their radiuses.
Kyle
So, due to that, I merely use the CA as a Boolean check to do the sub stepping.
Kyle
@Kyle: for line segments rather than lines, you can find the closest point on one of them to the other.
outis
+2  A: 

(I don't know how to post graphics; bear with me.)

All right, we have two spheres with radii r1 and r2, starting at locations X1 and X2, moving with velocities V1 and V2 (X's and V's are vectors).

The velocity of sphere 1 as seen from sphere 2 is

V = V1-V2

and its direction is

v = V/|V|

The distance sphere 1 must travel (in the frame of sphere 2) to closest approach is

s = Xv

And if X is the initial separation, then the distance of closest approach is

h = |X - Xv|

This is where graphics would help. If h > r1+r2, there will be no collision. Suppose h < r1+r2. At the time of collision, the two sphere centers and the point of closest approach will form a right triangle. The distance from Sphere 1's center to the point of closest approach is

u = sqrt((r1 + r2)^2 - h^2)

So the distance sphere 1 has traveled is

s - u

Now just see if sphere 1 travels that far in the given interval. If so, then you know exactly when and where the spheres were (you must shift back from sphere 2's frame, but that's pretty easy). If not, there's no collision.

Beta
Thanks, Beta! I guess I'm not sure what the X represents in Xv, and what operation you're doing. So, I guess I'm stuck on that particular part.
Kyle
Sorry, X is the initial separation of the spheres (X2 - X1), v is a unit vector in the direction of V, and when I write two vectors together like Xv, I mean the dot product.
Beta