Point and sphere

Given a point and a sphere there are two operations we want to perform. First, we want to check whether a test point is inside the sphere or not. Alternately, we may want to get the closest point to the test point along the surface of the sphere:

Point and sphere

Getting ready

To test whether a point is within a sphere we have to compare the distance from the center of the sphere and the test point to the radius of the sphere. If the distance is less than the radius, the sphere contains the point. We can get the point on the surface of the sphere closest to a test point by obtaining a vector that points from the center of the sphere to the test point. ...

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.