Jump to content
  • Advertisement
Sign in to follow this  
anders211

checking if point is inside traingle doesn't work

This topic is 1040 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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!