Sign in to follow this  

checking if point is inside traingle doesn't work

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

If you intended to correct an error in the post then please contact us.

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

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this