From 31512102edf34b7eba08fbf60e9cbeb9ecac9c94 Mon Sep 17 00:00:00 2001 From: nicopietroni Date: Fri, 20 Jan 2006 16:35:51 +0000 Subject: [PATCH] added Intersection_Segment_Box function --- vcg/space/intersection3.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/vcg/space/intersection3.h b/vcg/space/intersection3.h index 2ec7fd3d..48055b18 100644 --- a/vcg/space/intersection3.h +++ b/vcg/space/intersection3.h @@ -24,6 +24,10 @@ History $Log: not supported by cvs2svn $ +Revision 1.20 2005/10/03 16:07:50 ponchio +Changed order of functions intersection_line_box and +intersectuion_ray_box + Revision 1.19 2005/09/30 13:11:39 pietroni corrected 1 compiling error on Ray_Box_Intersection function @@ -457,6 +461,29 @@ bool Intersection_Ray_Box( const Box3 & box, const Ray3 & r, Point3 & c return(Intersection_Line_Box(box,l,coord)); } +// segment-box +template +bool Intersection_Segment_Box( const Box3 & box, const Segment3 & s, Point3 & coord ) +{ + //as first perform box-box intersection + Box3 test; + test.Add(s.P0()); + test.Add(s.P1()); + if (!test.Collide(box)) + return false; + else + { + Line3 l; + Point3 dir=s.P1()-s.P0(); + dir.Normalize(); + l.SetOrigin(s.P0()); + l.SetDirection(dir); + if(Intersection_Line_Box(box,l,coord)) + return (test.IsIn(coord)); + return false; + } +} + template bool Intersection (const Plane3 & plane0, const Plane3 & plane1,