Point containment

So far in this chapter, we have implemented the basic primitives for 2D shapes. Now we are going to implement the most basic primitive test for 2D shapes; point containment. It's often useful to know if a point is inside a shape or not.

Getting ready

We are going to implement a method to check if a point is on a line, as well as methods to check if a point is within a circle, rectangle, and oriented rectangle. These are the most basic 2D intersection tests we can perform.

How to do it…

Follow these steps to test if a point is contained within any of the two-dimensional primitives we have created so far:

  1. Declare the containment functions in Geometry2D.h:
    bool PointOnLine(const Point2D& point, const Line2D& line); bool PointInCircle(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.