I am following the math in the book Real Time Collision Detection by Christer Ericson. On pages 184 thru 188, he discusses how to test for an intersecting line against a triangle. I replicated the code he provided in his book, but it does not work for some data sets. I realize this is a math site, but I think this is a mathematics problem (since the math is rather unclear to me), so I have a simple psuedocode representation below:
Given line PQ and triangle ABC,
Vector pq = q - p;
Vector pa = a - p;
Vector pb = b - p;
Vector pc = c - p;
Vector m = crossProduct(pq, pc);
u = dotProduct(pb, m);
v = -dotProduct(pa, m);
w = scalarTripleProduct(pq, pb, pa);
if(NotSameSign(u, v)) return NoCollision;
if(NotSameSign(u, w)) return NoCollision;
The data set I am using is as follows, which with my code above returns a collision for some reason:
p: 252.125,2 50.075, 253.225
q: 252.305, 250, 253.168
a: 250.047, 251, 253.149
b: 250.047, 251, 255.149
c: 250.047, 249, 255.149
A visual representation can be seen here: http://puu.sh/3elqB.png It is clear there is no intersection, so why does the above math say that there is an intersection?
EDIT: Additional information concerning this:
During the process, some intermediate calculations are as follows:
Vector m = (-0.205576, -0.227845, -0.349335)
u = -0.45569
v = -0.242981
w = -0.0212998