Hi
My algorithm:
bool isPointInTriangle(D3DXVECTOR3 P, D3DXVECTOR3 A, D3DXVECTOR3 B, D3DXVECTOR3 C)
{
//A,B,C has to be in clock counterwise
D3DXVECTOR3 v0 = P - A;
D3DXVECTOR3 v1 = P - B;
D3DXVECTOR3 v2 = P - C;
D3DXVECTOR3 w0 = B - A;
D3DXVECTOR3 w1 = C - B;
D3DXVECTOR3 w2 = A - C;
float dot0 = D3DXVec3Dot(&v0, &w0);
float dot1 = D3DXVec3Dot(&v1, &w1);
float dot2 = D3DXVec3Dot(&v2, &w2);
// Check if point is in triangle
return (dot0 > 0) && (dot1 > 0) && (dot2 > 0);
}
It returns true for input data:
P = 0.00500, 1.29503, -0.527091
A (1) = -0.14968, 1.22912, -0.51883
B (2) = -0.16333, 1.3743, -0.46981
C (3) = -0.10280, 1.3691, -0.48294
what is wrong because point isn't inside triangle, I visualized triangle and point on the attachment. What to correct in order to have algorithm properly working?