From cbbb1cd0ff60a7b9e563a99e5a5e69fb48577073 Mon Sep 17 00:00:00 2001 From: ganovelli Date: Mon, 26 Apr 2004 12:34:50 +0000 Subject: [PATCH] plane line plane segment triangle triangle added --- vcg/space/intersection3.h | 77 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/vcg/space/intersection3.h b/vcg/space/intersection3.h index 5c8fa7e6..127b48ca 100644 --- a/vcg/space/intersection3.h +++ b/vcg/space/intersection3.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.1 2004/04/21 14:22:27 cignoni +Initial Commit + ****************************************************************************/ @@ -33,10 +36,24 @@ $Log: not supported by cvs2svn $ #define __VCGLIB_INTERSECTION_3 #include +#include +#include +#include +#include +#include +#include + + + +/** \addtogroup space */ +/*@{*/ +/** + Function computing the intersection between couple of geometric primitives in + 3 dimension + */ namespace vcg { -// sphere line - +/// interseciton between sphere and line template inline bool Intersection( const Sphere3 & sp, const Line3 & li, Point3 & p0,Point3 & p1 ){ @@ -65,6 +82,62 @@ inline bool Intersection( const Sphere3 & sp, const Line3 & li, Point3 return true; } +/// intersection between line and plane +template +inline bool Intersection( const Plane3 & pl, const Line3 & li, Point3 & po){ + const T epsilon = T(1e-8); + + T k = pl.n * li.dire; // Compute 'k' factor + if( (k > -epsilon) && (k < epsilon)) + return false; + T r = (pl.d - pl.n*li.orig)/k; // Compute ray distance + po = li.orig + li.dire*r; + return true; + } + +/// intersection between segment and plane +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()); + if( (k > -epsilon) && (k < epsilon)) + return false; + T r = (pl.d - pl.n*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 two triangles +template +inline bool Intersection( Triangle3 t0,Triangle3 t1){ + return NoDivTriTriIsect(t0.P0(0),t0.P0(1),t0.P0(2), + t1.P0(0),t1.P0(1),t1.P0(2)); + } +template +inline bool Intersection( Point3 V0,Point3 V1,Point3 V2, + Point3 U0,Point3 U1,Point3 U2){ + return NoDivTriTriIsect(V0,V1,V2,U0,U1,U2); + } + +template +inline bool Intersection( Point3 V0,Point3 V1,Point3 V2, + Point3 U0,Point3 U1,Point3 U2,int *coplanar, + Point3 &isectpt1,Point3 &isectpt2){ + + return tri_tri_intersect_with_isectline(V0,V1,V2,U0,U1,U2, + coplanar,isectpt1,isectpt2); + } +template +inline bool Intersection( Triangle3 t0,Triangle3 t1,bool &coplanar, + Segment3 & sg){ + Point3 ip0,ip1; + return tri_tri_intersect_with_isectline(t0.P0(0),t0.P0(1),t0.P0(2), + t1.P0(0),t1.P0(1),t1.P0(2), + coplanar,sg.P0(),sg.P1() + ); + } } // end namespace #endif \ No newline at end of file