From db5320cc641fc5ddf9df6bdc051ac58fd8d617d0 Mon Sep 17 00:00:00 2001 From: cignoni Date: Wed, 11 May 2011 09:56:23 +0000 Subject: [PATCH] Modified IntersectionPlaneSegment so that it returns always the same intersection independently from the segment orientation Return false if segment is parallel with the plane. --- vcg/space/intersection3.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/vcg/space/intersection3.h b/vcg/space/intersection3.h index 0cc66fd0..a67236c8 100644 --- a/vcg/space/intersection3.h +++ b/vcg/space/intersection3.h @@ -236,8 +236,16 @@ namespace vcg { inline bool IntersectionPlaneSegment( const Plane3 & pl, const Segment3 & s, Point3 & p0){ T p1_proj = s.P1()*pl.Direction()-pl.Offset(); T p0_proj = s.P0()*pl.Direction()-pl.Offset(); - if ( (p1_proj>0)-(p0_proj<0)) return false; - p0 = s.P0() + (s.P1()-s.P0()) * fabs(p0_proj/(p1_proj-p0_proj)); + if ( (p1_proj>0)-(p0_proj<0)) return false; + + if(p0_proj == p1_proj) return false; + + // check that we perform the computation in a way that is independent with v0 v1 swaps + if(p0_proj < p1_proj) + p0 = s.P0() + (s.P1()-s.P0()) * fabs(p0_proj/(p1_proj-p0_proj)); + if(p0_proj > p1_proj) + p0 = s.P1() + (s.P0()-s.P1()) * fabs(p1_proj/(p0_proj-p1_proj)); + return true; }