Jump to content
• Advertisement

# How do I get the point in the triangle intersected with a ray

This topic is 3628 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

How do I get the point in the triangle intersected with a ray? The dist is the distance between the intersected point in trainagle and the origin of the ray? D3DXIntersectTri(&v_tri[0],&v_tri[1],&v_tri[2],&originW,&dirW,&U,&V,&dist);

#### Share this post

##### Share on other sites
Advertisement
Quote:
 Original post by akira32How do I get the point in the triangle intersected with a ray?
U and V are the Barycentric coordinates of the intersection point.

Quote:
 Original post by akira32The dist is the distance between the intersected point in trainagle and the origin of the ray?
Yes.

Did you read the Documentation?

#### Share this post

##### Share on other sites
D3DXIntersectTri(&v1,&v2,&v3,&originW,&dirW,&U,&V,&dist);D3DXVECTOR3 vec1=originW+dist*dirW;float W=1-(U+V);D3DXVECTOR3 vec2;//intersected point in trianglevec2.x=(v1.x*W)+(v2.x*U)+(v3.x*V);vec2.y=(v1.y*W)+(v2.y*U)+(v3.y*V);vec2.z=(v1.z*W)+(v2.z*U)+(v3.z*V);

Is the vec1 equal to vec2?

#### Share this post

##### Share on other sites
Yep.

FYI, you don't need to do the coordinates separately. D3DXVECTOR3 overloaded operators allow:

vec2 = v1*W + v2*U + v3*V;

Be aware: dist may be negative, which means dirW is pointing away from the triangle.

Also, be aware of the return value of D3DXIntersectTri. If false, that represents the condition where dirW is parallel to the plane of the triangle.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
Rutin
24
4. 4
JoeJ
18
5. 5
• Advertisement

• 14
• 23
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002232
×

## 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!