I'm having trouble with unaligned collision avoidance for what I think is a rare case. I have set two objects to move towards each other but with a slight offset, so one of the objects is moving slightly upwards, and one of the objects is moving slightly downwards.

In my unaligned collision avoidance steering algorithm I'm finding the points on the object's forward line and the other object's forward line where these two lines are the closest. If these closest points are within a collision avoidance distance, and if the distance between them is smaller than the two radii of the two object's bounding spheres, then the objects should steer away in the appropriate direction.

The problem is that for my case, the closest points on the lines are calculated to be really far away from the actual collision point. This is because the two forward lines for each object are moving away from each other as the objects pass. The problem is that because of this, no steering takes place, and the two objects partially collide.

Screenshot of object forward lines.

Does anyone have any suggestions as to how I can correctly calculate the point of collision? Perhaps by somehow taking into account the size of the two objects?

  • \$\begingroup\$ Note that in the screenshot, the green, red and blue lines are just the axes of the 3D world. \$\endgroup\$ Mar 16, 2011 at 21:53

4 Answers 4


This is by far the best ball to ball collision detection article I have come across.

Pool Hall Lessons: Fast, Accurate Collision Detection Between Circles or Spheres

  • \$\begingroup\$ I know how to do a sphere-sphere collision test. My problem is trying to find the position where this collision will happen in the future. Thanks. \$\endgroup\$ Mar 17, 2011 at 20:43
  • \$\begingroup\$ @James that article will solve your problems. Look at page 2 and you can use an arbitrarily high number for the "velocity" on one of your spheres to determine the collision point "in the future". \$\endgroup\$
    – Tetrad
    Mar 17, 2011 at 20:58
  • \$\begingroup\$ Ok - sorry for not checking it out, it does look pretty good! I'll have to get back to you once I've read it. Thanks :) \$\endgroup\$ Mar 17, 2011 at 22:03
  • 1
    \$\begingroup\$ Could I just clarify that on page 2 under the section "Bank Shot: Collision between two moving circles", it means that you should use the difference between the two circle's velocity in the algorithm instead of the first circle's velocity? (The second circle's velocity is not used in the stationary version of the algorithm.) This bit wasn't so clear to me. Thanks. \$\endgroup\$ Mar 20, 2011 at 16:18

You don't want to find the closest point.

You want to find the point on the lines where the distance is equal to the combined radii of both spheres.

  • \$\begingroup\$ Ah... ok! Do you know how I can figure this out mathematically..? \$\endgroup\$ Mar 17, 2011 at 8:41

If I'm understanding your question correctly you can simply just use a Sphere vs Sphere intersection test, like AttackingHobo has suggested.

The math to do such a test is as follows (correct me if I'm wrong, it's been awhile). Also, this is considering that your spheres have a center and a radius variable each.

The formula for checking goes something like this:

distanceOfSpheres <= sumOfRadii^2

You have a sphere vs sphere intersection. This is pretty simple, let's see what it looks like in code!

bool sphereIntersectTest(BoundingSphere* s1, BoundingSphere* s2)
   Vector3 distance;

   // Get the distance between each sphere, center is a Vector3 type
   distance = (s1->center - s2-> center);

   // Determine the sum of both radii
   float radii = (s1->radius + s2->radius);

   // Determine if we have an intersection
   if (distance.length <= (radii * radii))
      return true;
      return false;

Again, I think that this is the correct answer you may be looking for. If anyone knows that this is wrong please correct me, since it has been a while since I've done this math.

  • \$\begingroup\$ I know how to do a sphere-sphere collision test. My problem is trying to find the position where this collision will happen in the future. Thanks. \$\endgroup\$ Mar 17, 2011 at 20:42

Ok, hopefully this makes sense... Get the vectors of the balls and calculate their collision point, call this p1. Find the angle between the 2 vectors, call this a1. At a1/2 draw a line, this will be in the exact middle in degrees between the two vectors. You need the location on this line where sin(a1/2) = (radius1 + radius2)/2. If this picture is visualized in my head right, this is where the collision occurs. Sorry if this is wrong... its late.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .