   Calculating Sphere Collision
  Need some help -- my math is not terribly good, nor is my knowledge of collisions (might have missed that week in school all those years ago...)Given two spheres, perhaps with the following structure:struct Sphere{   float m_radius;   float3 m_velocity; /* Properties are X, Y, and Z, all floats */   float3 m_position;};Now, say 1 'hour' just passed (low resolution simulation). I have two spheres, Sphere sA and Sphere sB. How can I determine if they collided/intersected during that time, and if they did, where the initial point of collision was (though I know that it's possible to have 2, in which case I'll just average the two), and if possible how long after the beginning of the 'tick' the collision occured?Thanks for the help!   
  Usually when I do collision I check each iteration through a loop, but it sounds like you want to detect collisions that could occur be between iterations.There might be a more efficient way, but it sounds like you should just do a line search between t = 0 and t = 1 hour. Just look for the point in which distance minus r1 plus r2 equals 0. If the result goes negative you have gone too far. If the result starts increasing they will never collide without new forces acting on them.P.S. You will probably never get exactly zero, so pick a value for your precision which is good enough (abs(result)<10^-10 for example).   ;  sphere centre motion equationspa(t) = ca + va * tpb(t) = cb + vb * ttwo sphere touches when their distance squared between their centre is equal to their radius squared(pa - pb)^2 = (ra + rb)^2replace pa and pb by sphere motions((ca - cb) + (va - vb))^2 = (ra + rb)^2expand first bit[(va - vb)^2] * t^2 + [2 * (ca - cb) . (ca - cb)] * t + (ca - cb)^2 = (ra + rb)^2reorder[(va - vb)^2] * t^2 + [2 * (ca - cb) . (ca - cb)] * t + (ca - cb)^2 - (ra + rb)^2 = 0quadratic equation in the form a * t^2 + b^t + c = 0 wherea = (va - vb) . (va - vb)b = (va - vb) . (ca - cb) * 2c = (ca - cb) . (ca - cb) - (ra + rb)^2if a = 0, it means the spheres are moving at the same velocity, and you should check the spheres for intersections (check if distance between centre is less than combined radius).else, solve quadratic equationsd = b*b - 4 * a * cif(d < 0.0f) no collisions  (the spheres paths do not collide).two solutions to equationst0 = (-b - sqrt(d)) / (2 * a)t1 = (-b + sqrt(d)) / (2 * a)These values represent the two times where spheres A and B are just touching.call these times t_enter and t_exit.t_enter = min(t0, t1);t_exit = max(t0, t1);if t_exit < 0.0f, the spheres missed the collision (it happens back in time).if t_enter < 0.0f, the spheres are already intersecting at the start of the frame.if t_enter >= 0.0f, this is the time where the spheres first touch.if t_enter > 1 hour (in your example), the spheres will touch outside the time interval.[Edited by - oliii on May 15, 2010 1:20:25 PM]