Triangle to plane
There are two scenarios in which a triangle and plane intersect:
- Not every point of the triangle is on the same side of the plane
- Every point of the triangle is on the plane
Getting ready
We are going to implement the TrianglePlane
function to test for intersection between a triangle and a plane. This function will use our existing PlaneEquation
function to classify which side of the plane the triangle is on.
How to do it…
Follow these steps to test if a triangle and a plane intersect:
- Declare the new
TrianglePlane
function inGeometry3D.h
:bool TrianglePlane(const Triangle& t, const Plane& p);
- Declare a convenience macro in
Geometry3D.h
:#define PlaneTriangle(p, t) \ TrianglePlane(t, p)
- Implement the
TrianglePlane
function inGeometry3D.cpp
:bool TrianglePlane(const Triangle& t, const Plane& p) {
- Check which side of the plane every point of the triangle is on:
float side1 = PlaneEquation(t.a, p); float side2 = PlaneEquation(t.b, p); float side3...