# D3DXVec4Cross function

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

## Recommended Posts

Hello I', writing my own math library. I wrote my own cross product function for 4D vectors, like this: ECVector4 ECVector4::Cross( const ECVector4& CrossVec )const { Real32 X = (m_X * CrossVec.m_Y - m_Y*CrossVec.m_X) + (m_X * CrossVec.m_Z - m_Z*CrossVec.m_X) + (m_Y * CrossVec.m_Z - m_Z*CrossVec.m_Y); Real32 Y = (m_Z * CrossVec.m_Y - m_Y*CrossVec.m_Z) + (m_Y * CrossVec.m_W - m_W*CrossVec.m_Y) + (m_Z * CrossVec.m_W - m_W*CrossVec.m_Z); Real32 Z = (m_X * CrossVec.m_Z - m_Z*CrossVec.m_X) + (m_W * CrossVec.m_X - m_X*CrossVec.m_W) + (m_Z * CrossVec.m_W - m_W*CrossVec.m_Z); Real32 W = (m_Y * CrossVec.m_X - m_X*CrossVec.m_Y) + (m_W * CrossVec.m_X - m_X*CrossVec.m_W) + (m_W * CrossVec.m_Y - m_Y*CrossVec.m_W); return ECVector4( X, Y, Z, W ); } when I was about to find out if my calculations where correct using the D3DXVec4Cross function i found out that it had 3 vectors as in parameters. Isn't cross product just used like V1 cross V2?? I admit that my knowledge about 4D vectors is very limited.

##### Share on other sites
They are 3 points, from which two vectors are created with which the cross product is calculated.

##### Share on other sites
For a cross product in n dimensions you need (n-1) vectors. For a 2D cross product you need 1 vector. For a 3D cross product, 2 vectors. In 4D, 3 vectors, and so on. A cross product finds you a vector that is perpendicular to all the other vectors, that's why 2 vectors are not enough in 4D. The cross product is calculated by taking the sub-determinants for the first column of a matrix where the first column is the vector you're looking for and the other columns are the given vectors.

##### Share on other sites
Thnx.. I had to to a litle googleing how to get the sub determinants but here is the result:

void
ECVector4::Cross( const ECVector4& CrossVec1, const ECVector4& CrossVec2, const ECVector4& CrossVec3 )
{

//Create som determinants using CrossVec2 & CrossVec3
Real32 XY = CrossVec2.m_X*CrossVec3.m_Y - CrossVec3.m_X*CrossVec2.m_Y;
Real32 XZ = CrossVec2.m_X*CrossVec3.m_Z - CrossVec3.m_X*CrossVec2.m_Z;
Real32 XW = CrossVec2.m_X*CrossVec3.m_W - CrossVec3.m_X*CrossVec2.m_W;
Real32 YZ = CrossVec2.m_Y*CrossVec3.m_Z - CrossVec3.m_Y*CrossVec2.m_Z;
Real32 YW = CrossVec2.m_Y*CrossVec3.m_W - CrossVec3.m_Y*CrossVec2.m_W;
Real32 ZW = CrossVec2.m_Z*CrossVec3.m_W - CrossVec3.m_Z*CrossVec2.m_W;

m_X = CrossVec1.m_Y * ZW - CrossVec1.m_Z * YW + CrossVec1.m_W * YZ;
m_Y = CrossVec1.m_Z * XW - CrossVec1.m_X * ZW - CrossVec1.m_W * XZ;
m_Z = CrossVec1.m_X* YW - CrossVec1.m_Y * XW + CrossVec1.m_W * XY;
m_W = CrossVec1.m_Y * XZ - CrossVec1.m_X * YZ - CrossVec1.m_Z * XY;

}

nice doing codeing with you ^^

##### Share on other sites
Quote:
 Original post by 84rFor a cross product in n dimensions you need (n-1) vectors.

The crossproduct, by definition, is a binary operation. It is only defined in three and seven dimensions.

1. 1
2. 2
Rutin
21
3. 3
4. 4
A4L
15
5. 5
khawk
14

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633737
• Total Posts
3013608
×