// line (or segment) in 3D vs plane bool vsLine3D(const Line3D& line, const Plane3D& plane, Point3D *rpoint = NULL, bool check = true) { // check if line is parallel with plane if ( abs( line.vector * plane.normal() ) < epsilon ) return false; Point3D p = line.point, q = line.point + line.vector; float normalLen = plane.normal().length(); // get dist (and side) from plane for each point float distP = plane.Evaluate( p ) / normalLen; float distQ = plane.Evaluate( q ) / normalLen; // find t float t; if ( ( distP < 0.f && distQ < 0.f ) || ( distP > 0.f && distQ > 0.f ) ) { if ( check ) return false; t = abs( distP ) < abs( distQ ) ? -abs( distP / ( distP - distQ ) ) : abs( ( distP + distQ ) / ( distP - distQ ) ); } else { t = abs( distP ) / ( abs( distP ) + abs( distQ ) ); } if ( rpoint ) *rpoint = p + t * line.vector; return true; }
// Compute angle between two geometric entities (in radians; use acos) float AngleBetween(const Line3D& line, const Plane3D& plane) { Vector3D u = line.vector ^ plane.normal(); Vector3D v = plane.normal() ^ u; float angle = acos( v * line.vector ); return ( ( angle < 0.f ) ? ( angle + 2.f * M_PI ) : angle ); }
// Determine if two geometric entities are perpendicular. bool Perpendicular(const Plane3D& plane1, const Plane3D& plane2) { return ( plane1.normal() * plane2.normal() <= epsilon ); }
// Determine if two geometric entities are perpendicular. bool Perpendicular(const Line3D& line, const Plane3D& plane) { return ( abs( line.vector * plane.normal() - line.vector.length() * plane.normal().length() ) <= epsilon ); }
// Determine if two geometric entities are parallel. bool Parallel(const Plane3D& plane1, const Plane3D& plane2) { return ( abs( plane1.normal() * plane2.normal() - plane1.normal().length() * plane2.normal().length() ) <= epsilon ); }
// Determine if two geometric entities are parallel. bool Parallel(const Line3D& line, const Plane3D& plane) { return ( abs( line.vector * plane.normal() ) <= epsilon ); }
// Compute angle between two geometric entities (in radians; use acos) float AngleBetween(const Plane3D& plane1, const Plane3D& plane2) { return acos( ( plane1.normal() * plane2.normal() ) / ( plane1.normal().length() * plane2.normal().length() ) ); }
// Return the distance from a point to a plane. float Distance(const Point3D& point, const Plane3D& plane) { return abs( plane.Evaluate( point ) / plane.normal().length() ); }