src/Geometry/clipConvexFacetedVolumeByPlanes3d.cc
//------------------------------------------------------------------------------
// Intersect a line-segment with a plane.
//------------------------------------------------------------------------------
Intersect a line-segment with a plane.
Intersect a line - segment with a plane .
Dim<3>::Vector
segmentPlaneIntersection(const Dim<3>::Vector& a,       
                         const Dim<3>::Vector& b,       
                         const Dim<3>::Vector& p,       
                         const Dim<3>::Vector& phat) {  
  const auto ab = b - a;
  const auto abhat = ab.unitVector();
  CHECK2(std::abs(abhat.dot(phat)) > 0.0, (abhat.dot(phat)) << " " << a << " " << b << " " << abhat << " " << phat);
  const double s = std::max(0.0, std::min(ab.magnitude(), (p - a).dot(phat)/(abhat.dot(phat))));
  CHECK2(s >= 0.0 and s <= ab.magnitude(), s << " " << ab.magnitude());
  const auto result = a + s*abhat;
  CHECK2(fuzzyEqual((result - p).dot(phat), 0.0, 1.0e-10),
         a << " " << b << " " << s << " " << result << " " << (result - p).dot(phat));
  return result;
}
Dim < 3 > :: Vector segmentPlaneIntersection ( const Dim < 3 > :: Vector & a , const Dim < 3 > :: Vector & b , const Dim < 3 > :: Vector & p , const Dim < 3 > :: Vector & phat ) { const auto ab = b - a ; const auto abhat = ab . unitVector ( ) ; CHECK2 ( std :: abs ( abhat . dot ( phat ) ) > 0.0 , ( abhat . dot ( phat ) ) << " " << a << " " << b << " " << abhat << " " << phat ) ; const double s = std :: max ( 0.0 , std :: min ( ab . magnitude ( ) , ( p - a ) . dot ( phat ) / ( abhat . dot ( phat ) ) ) ) ; CHECK2 ( s >= 0.0 and s <= ab . magnitude ( ) , s << " " << ab . magnitude ( ) ) ; const auto result = a + s * abhat ; CHECK2 ( fuzzyEqual ( ( result - p ) . dot ( phat ) , 0.0 , 1.0e-10 ) , a << " " << b << " " << s << " " << result << " " << ( result - p ) . dot ( phat ) ) ; return result ; }
Intersect a line-segment with a plane.
Intersect a line - segment with a plane .
// line-segment begin // line-segment end // point in plane // plane unit normal