Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

How to calculate a surface normal pointing out of a triangle

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

In Direct3D, we have D3DXVec3Cross, it takes 2 three-dimenional vectors as parameters. I forgot how to work out the surface normal pointing out of a triangle with Cross Product. Can anybody help?
Thanks
Jack

Share this post


Link to post
Share on other sites
Advertisement
Take the cross product of (b - a) and (c - a).
Where a, b, c are the points/vectors of your triangle; (b - a) is the difference vector of b minus a and (c - a) is the difference vector of c minus a.

Pseudo-code (C; untested):

typedef struct
{
D3DXVECTOR3 a;
D3DXVECTOR3 b;
D3DXVECTOR3 c;
} Triangle;

void Normal( D3DXVECTOR3* _out, const Triangle* _in )
{
D3DXVECTOR3 x;
D3DXVECTOR3 y;
if( !_out|| !_in )
{
return;
}
D3DXVec3Subtract( &x, &_in->b, &_in->a );
D3DXVec3Subtract( &y, &_in->c, &_in->a );
D3DXVec3Cross( _out, &x, &y );
}

// ...
Triangle _myTriangle= <...>;
D3DXVECTOR3 _myTriangleNormal;
Normal( &_myTriangleNormal, &_myTriangle );




[Edited by - nr on July 21, 2010 5:45:16 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by nr
Take the cross product of (b - a) and (c - a).
Where a, b, c are the points/vectors of your triangle; (b - a) is the difference vector of b minus a and (c - a) is the difference vector of c minus a.

Pseudo-code (C; untested):
*** Source Snippet Removed ***


Thanks nr, I found some similar code in my references.
Jack

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!