Public Group

checking if point is inside traingle doesn't work

This topic is 1130 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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?

Edited by anders211

1. 1
2. 2
3. 3
4. 4
Rutin
21
5. 5

• 9
• 13
• 19
• 14
• 9
• Forum Statistics

• Total Topics
632938
• Total Posts
3009317
• Who's Online (See full list)

There are no registered users currently online

×