diff --git a/vcg/space/intersection3.h b/vcg/space/intersection3.h index c4ba754c..00eaff77 100644 --- a/vcg/space/intersection3.h +++ b/vcg/space/intersection3.h @@ -349,13 +349,12 @@ namespace vcg { /// intersection between segment and plane template - inline bool IntersectionSegmentPlane( const Plane3 & pl, const Segment3 & s, Point3 & po){ - vcg::Line3 l; - l.Set(s.P0(),s.P1()-s.P0()); - l.Normalize(); - if (IntersectionLinePlane(pl,l,po)) - return((po-s.P0()).Norm()<=(s.P0()-s.P1()).Norm()); - return false; + inline bool IntersectionSegmentPlane( const Plane3 & pl, const Segment3 & s, Point3 & p0){ + T p1_proj = s.P1()*pl.Direction()-pl.Offset(); + T p0_proj = s.P0()*pl.Direction()-pl.Offset(); + if ( (p1_proj>0)-(p0_proj<0)) return false; + p0 = s.P0() + (s.P1()-s.P0()) * fabs(p0_proj/(p1_proj-p0_proj)); + return true; } /// intersection between segment and plane @@ -867,7 +866,7 @@ public: return (bret); } }; - + /*@}*/