Linetest Plane
A Line segment represented by end points A and B can be parametrically expressed as follows:
S(t) = A + t(B-A) where
We can check if a line segment intersects a Plane by substituting the parametric equation of the Line into the Plane equation. If any point along the line at time t exists that satisfies the Plane equation, the Line segment and Plane intersect:
Getting ready
We are going to implement a function to test if a Line segment and a Plane intersect. This function will return a Boolean result.
How to do it…
Follow these steps to implement line testing against a plane:
- Declare the
Linetest
function inGeometry3D.h
:bool Linetest(const Plane& plane, const Line& line);
- Implement the
Linetest
function inGeometry3D.cpp
:bool Linetest(const Plane& plane, const Line& line) { vec3 ab = line.end - line.start; float nA = Dot(plane.normal, line.start); float nAB = Dot(plane.normal, ab); // If the line and plane are parallel, nAB will be 0 //...