Point and ray

A ray is the same as a directed line. Unlike a line segment, which has a start and an end point, a ray has only a start point and a direction. The ray extends infinitely in this one direction. Because of the ray's similarity to a line, operations on a ray are similar to those on a line.

Because a ray's direction is a normal vector, we can use the dot product to check its direction against other known vectors. For example, to test whether a point is on a ray, we need to get a normalized vector from the origin of the ray to the test point. We can then use the dot product to see if this new normal vector is the same as the normal of the ray. If two vectors point in the same direction, the result of the dot product will be 1:

Getting ready ...

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.