Skip to main content
gamedev.net
🔒 Locked

4d vectors and matrices - which operators are defined?

Started by Milamber12345 Sep 18, 2003 at 7:51 AM 8 replies 1.9k views
Original Post
Milamber12345
Milamber12345
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.
Kentaro
Kentaro
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
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 thedouble-barrel shotgun. Eat leaden death, demon... -- Terry Pratchett
alvaro
alvaro
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]
Milamber12345
Milamber12345
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.
Sneftel
Sneftel
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.
python_regious
python_regious
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.
If at first you don't succeed, redefine success.
Kentaro
Kentaro
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. =)
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 thedouble-barrel shotgun. Eat leaden death, demon... -- Terry Pratchett
python_regious
python_regious
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.
If at first you don't succeed, redefine success.

Topic Locked

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

Sign in to reply to this topic.