Sphere-to-sphere

To check if two spheres overlap, we check if the distance between them is less than the sum of their radii. We can avoid an expensive square root operation by checking the square distance between the spheres against the squared sum of their radii:

Sphere-to-sphere

Getting ready

Checking if two 3D spheres intersect is very similar to checking if two 2D circles intersect. We are going to implement a new function to check if two spheres intersect. This is the simplest 3D intersection function we are going to write.

How to do it…

Follow the given steps to implement sphere-to-sphere intersection testing:

  1. Declare the SphereSphere function in Geometry3D.h

Get Game Physics Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.