bool Plane::intersectLine(const Line3& line, Vector3* result) const { const Vector3 direction = line.delta(); float denominator = normal().dot( direction ); if ( denominator == 0 ) { // line is coplanar, return origin if ( distanceToPoint( line.start() ) == 0 ) { if (result) { result->copy( line.start() ); } return true; } // Unsure if this is the correct method to handle this case. return false; } float t = - ( line.start().dot( normal() ) + constant() ) / denominator; if( (t < 0 || t > 1) ) { return false; } if (result) result->copy( direction ).multiplyScalar( t ).add( line.start() ); return true; }
bool Plane::isIntersectionLine( const Line3& line ) const { // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it. float startSign = distanceToPoint( line.start() ); float endSign = distanceToPoint( line.end() ); return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 ); }