Line intersection

After point containment, the line intersection the is the next logical intersection test to implement. Knowing if a line intersects one of the basic 2D primitives is very useful, and in most cases rather straightforward to implement.

Getting ready

We are going to implement functions to test if a line is intersecting any of the basic 2D primitives. To keep the naming of these functions a little more convenient, we are going to use the #define macro to create aliases for each function.

How to do it…

Follow these steps to test if a line intersects any of the two-dimensional primitives we have defined so far:

  1. Declare the line test functions in Geometry2D.h:
    bool LineCircle(const Line2D& line, const Circle& circle); bool LineRectangle(const ...

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.