Line segment

A line is the shortest straight path that goes through two points. A line extends infinitely in both directions. Like its 2D counterpart, the 3D line we are going to implement will actually be a Line Segment. We define this line segment using a Start point and an End point:

Line segment

Getting ready

We are going to define a Line structure that holds start and end points. This structure represents a line segment. We will also implement two helper functions, Length and LengthSq. These functions will help us find the length and squared length of the line segment.

How to do it…

Follow these steps to implement a 3D line segment:

  1. Add the declaration of

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.