# How to calculate a surface normal pointing out of a triangle

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

## 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 on other sites
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 on other sites
Quote:
 Original post by nrTake 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

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 13
• 14
• 9
• ### Forum Statistics

• Total Topics
633366
• Total Posts
3011524
• ### Who's Online (See full list)

There are no registered users currently online

×