# Ray Object Intersections

## Introduction

The general idea behind ray-object intersections is to put the mathematical equation for the ray into the equation for the object and determine if there is a real solution. If there is a real solution then there is an intersection (hit) and we must return the closest point of intersection and the normal (N) at the intersection point. For a shadow ray we must return whether any ray-object intersection is closer than the ray-light intersection. For a ray tested against a boundary volume, we just return a simple hit or no hit. For texture mapping we need the intersection point relative to some reference frame for the surface.

```
We define a ray as:
R0 = [x0, y0, z0] 	- origin of ray
Rd = [xd, yd, zd]	- direction of ray
then define a set of points on the ray:
R(t) = R0 + Rd * t	with t > 0.0
```

If Rd is normalized, then t equals the distance of the ray from origin in World Coordinates, else it is just a multiple of Rd, so we want to normalize Rd. Note that many of the intersection computations require the solution of the quadratic equation. Here is a more precise way to solve the quadratic equation.

Ray - Sphere Intersections

Ray-Plane Intersection

Ray-Polygon Intersection

Ray - Box Intersection