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:
Declare the line test functions in
Geometry2D.h
:bool LineCircle(const Line2D& line, const Circle& circle); bool LineRectangle(const Line2D& l, const Rectangle2D& r); bool LineOrientedRectangle(const Line2D& line, const OrientedRectangle& rectangle);
Using the
#define
directive, add aliases for all these functions toGeometry2D.h
. These defines do not...