diff --git a/vcg/space/intersection3.h b/vcg/space/intersection3.h index 127b48ca..3d28a375 100644 --- a/vcg/space/intersection3.h +++ b/vcg/space/intersection3.h @@ -24,6 +24,11 @@ History $Log: not supported by cvs2svn $ +Revision 1.2 2004/04/26 12:34:50 ganovelli +plane line +plane segment +triangle triangle added + Revision 1.1 2004/04/21 14:22:27 cignoni Initial Commit @@ -99,16 +104,40 @@ inline bool Intersection( const Plane3 & pl, const Line3 & li, Point3 & template inline bool Intersection( const Plane3 & pl, const Segment3 & sg, Point3 & po){ const T epsilon = T(1e-8); - T k = pl.d - pl.n * (sg.P1()-sg.P0()); + + T k = pl.Direction() * (sg.P1()-sg.P0()); if( (k > -epsilon) && (k < epsilon)) return false; - T r = (pl.d - pl.n*sg.P0())/k; // Compute ray distance + T r = (pl.Offset() - pl.Direction()*sg.P0())/k; // Compute ray distance if( (r<0) || (r > 1.0)) return false; po = sg.P0()*(1-r)+sg.P1() * r; return true; } +/// intersection between plane and triangle +// not optimal: uses plane-segment intersection (and the fact the two or none edges can be intersected) +template +inline bool Intersection( const Plane3 & pl, const TRIANGLE & tr, Segment3 & sg){ + if(Intersection(pl,Segment3(tr.P(0),tr.P(1)),sg.P0())){ + if(Intersection(pl,Segment3(tr.P(0),tr.P(2)),sg.P1())) + return true; + else + { + Intersection(pl,Segment3(tr.P(1),tr.P(2)),sg.P1()); + return true; + } + }else + { + if(Intersection(pl,Segment3(tr.P(1),tr.P(2)),sg.P0())) + { + Intersection(pl,Segment3(tr.P(0),tr.P(2)),sg.P1()); + return true; + } + } + return false; + } + /// intersection between two triangles template inline bool Intersection( Triangle3 t0,Triangle3 t1){ @@ -139,5 +168,7 @@ inline bool Intersection( Triangle3 t0,Triangle3 t1,bool &coplanar, ); } + + } // end namespace #endif \ No newline at end of file