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 ...
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.