From b2879b7333856b3e1823fb5e2c8318b3e8cc0110 Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Mon, 20 Mar 2006 14:42:49 +0000 Subject: [PATCH] IntersectionSegmentPlane and Intersection_Segment_Box functions Added --- vcg/space/intersection3.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/vcg/space/intersection3.h b/vcg/space/intersection3.h index 48055b18..431c892a 100644 --- a/vcg/space/intersection3.h +++ b/vcg/space/intersection3.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.21 2006/01/20 16:35:51 pietroni +added Intersection_Segment_Box function + Revision 1.20 2005/10/03 16:07:50 ponchio Changed order of functions intersection_line_box and intersectuion_ray_box @@ -156,6 +159,17 @@ namespace vcg { po = li.Origin() + li.Direction()*r; return true; } + + /// 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; + } /// intersection between segment and plane template @@ -461,7 +475,7 @@ bool Intersection_Ray_Box( const Box3 & box, const Ray3 & r, Point3 & c return(Intersection_Line_Box(box,l,coord)); } -// segment-box +// segment-box return fist intersection found from p0 to p1 template bool Intersection_Segment_Box( const Box3 & box, const Segment3 & s, Point3 & coord ) { @@ -484,6 +498,23 @@ bool Intersection_Segment_Box( const Box3 & box, const Segment3 & s, Point } } +// segment-box intersection , return number of intersections and intersection points +template +int Intersection_Segment_Box( const Box3 & box, const Segment3 & s, Point3 & coord0, Point3 & coord1 ) +{ + int num=0; + Segment3 test= s + if (Intersection_Segment_Box(box,test,coord0 )) + { + num++; + Point3 swap=test.P0(); + test.P0()=test.P1(); + test.P1()=swap; + if (Intersection_Segment_Box(box,test,coord1 )) + num++; + } + return num; +} template bool Intersection (const Plane3 & plane0, const Plane3 & plane1,