Skip to main content
GameDev.net gamedev.net
🔒 Locked

Normals & Vectors

Started by Dooster Apr 16, 2002 at 2:15 PM 6 replies 250+ views
Original Post
Dooster
Dooster
Hello, I''m not up on my trigonometry and am trying to understand things that used to (and often still do) confuse me. One of these encounters is the following problem:
D3DXVECTOR3    vector1;
D3DXVECTOR3    vector2;
D3DXVECTOR3    vector3;

D3DXVECTOR3    result;
 
How do I get the normal vector from the 3 points contained within vector1,2,3 and place them into ''result''? Ultimately I know the three vertex points that define a face within my vertex buffer and need to calculate the face normal vector from those vertices. I''ve tried looking it up in the documentation but nothing seems to calculate the result simply from 3 vectors. I''d appreciate any clarification.
baldurk
baldurk
I think it''s the cross product of two of the points.

------------------------------
Baldur K
"Hey! I hate these Microsoft guys! What a rotten compiler! It only accepts 16,384 local variables in a function!"
Oluseyi
Oluseyi
No, it''s the cross product of two of the edges of the surface defined by the three vectors. If you have a triangle defined by vector1, vector2, vector3, the surface normal is D3DXVec3Cross( &snormal, &(vector2 - vector1), &(vector2 - vector3) ).

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! | Asking Smart Questions | Internet Acronyms ]
Thanks to Kylotan for the idea!
Dooster
Dooster
Many thanks for the response. Now, can anyone explain in English what the cross product actually *is*? I look through some books I have that talk about using them, but non actually explain what they are...
Oluseyi
Oluseyi
The cross product is the orthogonal vector space to both operands. It''s sheer luck that the cross product of two 3D vectors is a 3D vector as well, because the cross product of 4D vectors is 6D, and the cross product of 6D vectors is 15D (in general the cross product of two n-D vectors is nC2).

Within the real of 3D graphics and physics, the cross product describes a vector that is perpendicular to both of its operands. Since two vectors necessarily lie in a common plane (they share the same origin) then the cross product can be considered perpendicular to the plane described by the vectors, which is how we can use it to obtain the surface normal.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! | Asking Smart Questions | Internet Acronyms ]
Thanks to Kylotan for the idea!
Oluseyi
Oluseyi
Oh, and if you want to obtain a cross product by hand:

v1 = (x1, y1, z1)
v2 = (x2, y2, z2)
v3 = v1 x v2
= | i j k |
| x1 y1 z1 | ( determinant of 3x3 matrix)
| x2 y2 z2 |
= ((y1 * z2) - (z1 * y2))i
- ((x1 * z2) - (z1 * x2))j
+ ((x1 * y2) - (y1 * x2))k

where i, j and k are unit vectors along the x-, y- and z-axes respectively.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! | Asking Smart Questions | Internet Acronyms ]
Thanks to Kylotan for the idea!
Dooster
Dooster
Thanks Olu, I think I have a better picture of its works now.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.