Point in triangle
We already have a definition for Triangle
in Geometry3D.h
, we implemented this primitive in Chapter 7, 3D Primitive Shapes . The first operation we want to perform on a triangle is testing for point containment. The containment test works by moving the triangle into the point's local space, then constructing a pyramid out of the triangle and the point. If the pyramid is flat, the point is inside the triangle. If it's not, the point is outside.
Getting ready
We are about to implement a function that will test if a point falls inside of a triangle. This function will return a simple boolean
result.
How to do it…
Follow these steps to implement a point in triangle test:
- Declare the
PointInTriangle
function inGeometry3D.h
:bool PointInTriangle(const Point& p, const Triangle& t);
- Implement the
PointInTriangle
function inGeometry3D.cpp
:bool PointInTriangleNormals(const Point& p, const Triangle& t) {
- Create a temporary triangle with the size of our...