diff --git a/vcg/space/intersection3.h b/vcg/space/intersection3.h index 2af6e5db..06758428 100644 --- a/vcg/space/intersection3.h +++ b/vcg/space/intersection3.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.28 2007/02/21 02:40:52 m_di_benedetto +Added const qualifier to bbox parameter in Intersection_Triangle_Box(). + Revision 1.27 2006/10/25 16:04:32 pietroni added intersection control between bounding boxes for intersection between segment and triangle function @@ -214,7 +217,7 @@ namespace vcg { /// 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, + inline bool IntersectionPlaneTriangle( const Plane3 & pl, const TRIANGLETYPE & tr, Segment3 & sg){ typedef typename TRIANGLETYPE::ScalarType T; @@ -603,6 +606,45 @@ bool Intersection_Plane_Box(const vcg::Plane3 &pl, return false; } +///if exists return the center and ardius of circle +///that is the intersectionk between the sphere and +//the plane +template +bool Intersection_Plane_Sphere(const vcg::Plane3 &pl, + const vcg::Sphere3 &sphere, + vcg::Point3 ¢er, + vcg::Point3 &radius) +{ + ///set the origin on the center of the sphere + vcg::Plane3 pl1; + vcg::Point3 p_plane=pl.Direction()*pl.Offset(); + vcg::Point3 p_plane=p_plane-sphere.Center(); + + ///set again the plane + pl1.Set(p_plane,pl.Direction()); + + ///test d must be positive + d=pl1.Offset(); + vcg::Point3 n=pl1.Direction(); + ///invert d if is <0 + if (d<0) + { + n=-n; + d=-d; + } + ///no intersection occour + if (d>r) + return false; + else + { + ///calculate center and translate in back + center=n*d; + center+=sphere.Center(); + radius=math::Sqrt((r*r)-(d*d)); + } +} + + template bool Intersection_Triangle_Box(const vcg::Box3 &bbox, const vcg::Point3 &p0,