Current Server Time - 4:39:51 AM                     
GameDev.Net Forums Math and Physics 4d vectors and matrices - which operators are defined?
Send Topic To a Friend | View Forum FAQ | Watch this thread
Post Reply
 
Reply to Message Edit Message Milamber12345   Member since: 9/18/2003   From: New South Wales, Australia   Show Profile Email Poster
Posted - 18 September 2003 8:51:37 AM
I am writing some c++ classes to handle vector, matrix, and quaternion math, but I can't work out how to implement some of the operators, eg. should scalar addition be defined for a 4d vector? If so, I don't think it should apply to the w coordinate. Also, what is the definition of the cross product of 2 4d vectors? Similar questions for the 4d matrices.

 
Reply to Message Edit Message Kentaro   Member since: 11/28/2002   From: Canada   Show Profile Email Poster
Posted - 18 September 2003 10:35:29 AM
As far as I can tell, the cross product of two vectors is only defined in 3 dimensions. I've never even heard of adding a scalar to a vector. The basic vector operations apply in n dimensions.

v + u = (v1 + u1, ..., vn + un)
v (dot) u = v1(u1) + ... + vn(un)

You can also prove some other properties in n dimensions (distributivity and whatnot).

As for matrices, for two matrices A and B that have dimensions m x n, their sum is an m x n matrix with each entry being the sum of that entry in A and that entry in B.

A + B[i, j] = A[i,j] + B[i, j]

Determinants... I'm not even sure why you're asking this. Most operations that I know of apply in any dimension! (Well, I have no clue about quaternions)

Over the centuries, mankind has tried many ways of combating the forces of evil...prayer,
fasting, good works and so on. Up until Doom, no one seemed to have thought about the
double-barrel shotgun. Eat leaden death, demon...
-- Terry Pratchett

 
Reply to Message Edit Message Anonymous Poster
Posted - 18 September 2003 2:19:56 PM
What you use will depend on whether these are true 4d vectors, or 3d vectors in homogeneous coordinates. I.e., for a true 4d vector, the cross product is undefined, while it is for a homogenous 3d vector.

I.e. given two 3d vectors in homogenous coordinates, V1,w1, and V2,w2. The cross product would be defined as (1/w1)*V1 x (1/w2)V2,1.

I suggest you read up on the theory of homogenous coordinates and fully understand the theory before getting too far in code.

 
Reply to Message Edit Message alvaro   Member since: 3/7/2002   From: USA   Show Profile Email Poster
Posted - 18 September 2003 2:22:25 PM
By the definition of vector space, sum of vectors and product of a number (a scalar) and a vector are always defined.

nxn matrices are vectors too (in a space with n^2 dimensions), so those two operations apply.

Adding a number to a vector is not meaningful. The cross product is only defined in dimension 3. There is something called external product that is defined in other dimensions, but the result is not a regular vector and it's probably not very interesting for your purposes.

Dot product is defined in R^n as Kentaro did.

A very important operation is multiplying a matrix by a [column] vector, with the result begin a [column] vector.

There are several other things that you can do, but you can add them as you need them. For instance, there is no point in implementing the double ratio of four points if you are never going to use it.



[edited by - Alvaro on September 18, 2003 2:23:23 PM]

 
Reply to Message Edit Message Milamber12345   Member since: 9/18/2003   From: New South Wales, Australia   Show Profile Email Poster
Posted - 18 September 2003 5:36:17 PM
Thanks for your replies everyone, and just to clarify, the 4d vectors and matrices are for handling 3d translations, so, yes, I'd say homogeneous coordinates. I'm working my way through a book called "Mathematics for 3d game programming and computer graphics". The first 3 chapters - vectors, matrices, and transforms - are intended for revision, though, and are a little brief for learning the basic concepts from. Any other pointers for how operatoors are defined for these would be useful. BTW, how would you implement the determinant and inverse of a 4x4 matrix for homogeneous coords? They are defined for n dimensions, but is the w coordiate treated normally? Also, when making the transpose of a 4x4 matrix, do you shift the translation vector as well? If not, do you change it in any way? Thx in advance for any further clarification.

 
Reply to Message Edit Message Sneftel   Moderator   Member since: 7/7/2001   From:   Show Profile Email Poster
Posted - 18 September 2003 5:42:08 PM
Determinants, inverses, and transpositions all treat the w component just like all the rest of 'em. Note, however, that it is unlikely you will ever take the transposition of a matrix with anything other than (0,0,0,1) in the fourth column--consider the possibility of a logic error if this ever happens.


How appropriate. You fight like a cow.

 
Reply to Message Edit Message python_regious   Member since: 2/28/2001   From: Somewhere in the vauge vicinity of Betelgeuse   Show Profile Email Poster
Posted - 18 September 2003 6:06:13 PM
Hmm... Couldn't the cross product in 4 dimensions just be the expansion of the equivilent 4x4 determinant? That makes more sense than just "it's undefined"...

I mean, in two dimensions it could be considered that:

|i j|
|x y|


would be correct, and if you expand it you have the function for finding a normal vector to another vector in 2D space.

Now, using 3 4-dimensional vectors, couldn't a normal to a 3D space be found?

You have to remember that you're unique, just like everybody else.

 
Reply to Message Edit Message Anonymous Poster
Posted - 18 September 2003 8:31:54 PM
If one defines the cross product by these properties:
1) Works on two vectors, say A and B
2) Produces a vector C, perpendicular to both A and B
3) The length of C is |A||B|sin theta, where theta is the angle in-between A and B.

Then, the cross product can only be defined in 3, and 7 dimensions. See: http://www.helsinki.fi/~lounesto/cross.product

 
Reply to Message Edit Message Kentaro   Member since: 11/28/2002   From: Canada   Show Profile Email Poster
Posted - 18 September 2003 11:54:27 PM
The link you give is actually even more general than that. It defines the cross product of k vectors in n dimensions:

k = 2, n = 3 or 7
k = 3, n = 8

... and some others. That's very interesting. I was having a debate with someone in my multi-variable calc course who said he could define the cross product of two vectors in any dimension so I should show this to him. I intuitively thought that the cross product of two vectors could not be defined in 4-space. Thankfully, the dot product is a lot easier to define and I seem to have gotten it right. =)

 
Reply to Message Edit Message python_regious   Member since: 2/28/2001   From: Somewhere in the vauge vicinity of Betelgeuse   Show Profile Email Poster
Posted - 19 September 2003 11:51:26 AM
quote:

Definition (generalized): The cross product of k vectors is a vector
perpendicular to the k vectors and of length equal to the k-volume
of the parallelepiped of the k vectors.

Theorem: The cross product of k vectors in R^n exists only for the following
pairs (n,k): (3,2), (7,2), (8,3), (n,n-1) and when n is even also for (n,1).



Yes, this is what I thought, so, using the ( n, n-1 ) formulae, it can be seen that the cross product is valid for 4 dimensional space. I presume this calculates the vector perpendicular to the volume defined by the 3 4D vectors...

You have to remember that you're unique, just like everybody else.

All times are ET (US)

Post Reply
 
Jump To:

Administrative Options:
Close Thread   Move/Archive Thread   Delete Thread   Reopen Thread


0.0635

About Us | Advertise on GameDev.net | Write for us
© 1999-2004 Gamedev.net, LLC. All rights reserved. Terms of Use Privacy Policy
Comments? Questions? Feedback? Click here!
GameDev.netTM, the GameDev.net logo, and GDNetTM are trademarks of GameDev.net, LLC