Ray-Sphere Intersection - From Math to Code

08-10-2020 - 6 minutes, 20 seconds - Computer Graphics

In this article I derive a ray-sphere intersection algorithm from it's math. While certain knowledge in mathematics and programming will be assumed, I am trying to show all the steps of the process.

Ray-sphere intersection is used to determine wether and where a ray hits a sphere. This is useful in selecting 3D objects with the cursor (well, spheres in this case), calculating bullet hits in games, etc., but you knew that. Why else would you look up such a specific topic?

So let's start with what we have: a sphere (your object, a hitbox, ...) and a ray (a bullet, your cursor, ...). What we we'd like to know is, if they intersect and what the intersection point(s) are, if any.

Continue Reading...