[sldev] bug in LLTriangleLineSegmentIntersect
Maurizio de Pascale
mdepascale at dii.unisi.it
Sun Oct 14 19:43:33 PDT 2007
Hi,
I've found a bug (or a feature, depending on the points of view) in the
LLTriangleLineSegmentIntersect function, which causes false positives.
the condition:
if (t > 0) return FALSE;
should actually be replaced with:
if (t<-1 || t>0) return FALSE;
an example:
intersecting a segment (-A,0,0)->(-B,0,0) where B>A>0 with a triangle on
the plane X=0 with norm (1,0,0) will always produce a t<-1 given the
formula used by the code:
dotprod = norm*vect;
t = -(norm * (linept-pt1))/dotprod;
in fact:
vect = (A-B,0,0) and (A-B) is always negative given B>A
dotprod = (A-B) which is always negative
linept-pt1 = (-B,#,#)
norm * (linept-pt1) = -B
t = - (-B) / (A-B) = - B/(B-A) which given B>A>0 is always strictly less
than -1
is this an innocuous bug or is there code depending on it to work this way?
regards,
Maurizio de Pascale
mdepascale at dii.unisi.it
More information about the SLDev
mailing list