#### Archived

This topic is now archived and is closed to further replies.

# Lazy, just plain lazy

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

## Recommended Posts

I remember doing 3d co-ordinate geometry years ago at school, but I can''t for the life of me remember how to work out the point of intersection between a line and a plane if the plane is defined by three vertices. You guessed it, I need to do accurate hit-detection on a polygon. Just thought I might excite someone by wording it slightly differently :-) Anyone close to the ground? I have plenty of talent and vision, I just don''''t give a damn.

##### Share on other sites
This is the way I do it:

  bool LineIntersectTriangle(D3DXVECTOR3 *pLineStart, D3DXVECTOR3 *pLineDirection, D3DXVECTOR3 *pTriPoint0, D3DXVECTOR3 *pTriPoint1, D3DXVECTOR3 *pTriPoint2){ D3DXVECTOR3 Edge1, Edge2, tVector, pVector, qVector; float Determinant, InvDeterminant, t, u, v; Edge1=*pTriPoint1-*pTriPoint0; // Find vectors for two edges sharing pTriPoint0. Edge2=*pTriPoint2-*pTriPoint0; D3DXVec3Cross(&pVector, pLineDirection, &Edge2); // Begin calculating determinant - also used to calculate U parameter. Determinant=D3DXVec3Dot(&Edge1, &pVector); if(DeterminantDeterminant) return(false); // Test U. No intersection, return false. D3DXVec3Cross(&qVector, &tVector, &Edge1); // Prepare to test V. v=D3DXVec3Dot(pLineDirection, &qVector); // Calculate V. if(v<0.0f || (u+v)>Determinant) return(false); // No intersection, return false. // If we get to this point, the RAY intersects the triangle. Note I wrote ray and not line. t=D3DXVec3Dot(&Edge2, &qVector); InvDeterminant=1.0f/Determinant; t*=InvDeterminant; if(t>=1.0f) return(false); // t has to be 1 or greater for the line to intersect the triangle. *pLineDirection=(*pLineDirection)*t; // Truncate line direction to the intersection point. return(true);}

For some reason, most of the formatting of the above code seems to have disappeared. Anyway, hope it helps.

Edited by - justin nixon on June 12, 2001 1:41:40 PM

##### Share on other sites
Thanks a mil Justine. That was considerably easier than wading through my old text books... I got as far as ''Line intersects plane'' when you replied. You have saved me so much time

Cheers,

I have plenty of talent and vision, I just don''''t give a damn.

##### Share on other sites
The name''s Justin.

##### Share on other sites
Sorry. My hands are caffeined out and probably shook at an inappropriate moment.

I have plenty of talent and vision, I just don''''t give a damn.

1. 1
2. 2
Rutin
26
3. 3
4. 4
JoeJ
18
5. 5
gaxio
11

• 14
• 22
• 11
• 11
• 9
×