Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / Matrices: 3x3 versus 4x4 - Which are best? Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
ROME

March 12, 1999, 03:32 PM

Hi, Why are 4x4 matrices used for 3-Space sometimes instead of 3x3? I assume that 4x4 is used because it provides a place to put transformations, but is this is so, then how can translations be done using 3x3 matrices? Are the translations done manually (outside of a matrix)? What is matrix is most commonly used in engines, 3x3 or 4x4? Why is it important to have a homogeneous coordinate system matrix thing? =) Thanks.

 
Jeroen

March 13, 1999, 03:51 AM


ROME wrote:
>Hi, Why are 4x4 matrices used for 3-Space sometimes instead of 3x3? I assume that 4x4 is
>used because it provides a place to put transformations, but is this is so, then how can
>translations be done using 3x3 matrices? Are the translations done manually (outside of
>a matrix)? What is matrix is most commonly used in engines, 3x3 or 4x4? Why is it important
>to have a homogeneous coordinate system matrix thing? =) Thanks.

When using 3x3 matrices, a complete tranformation (ie. rotation and translation) is split in
two operations: 1 matrix multiplication (for rotation) and 1 vector addition (for translation).
Using homogeneous coordinates means the complete transformation can be done using one multiply,
but also very easy clipping and other nifty stuff.

Cheers,

Jeroen

 
colas

March 13, 1999, 07:27 AM



rotations + translation can easily be done only with 3*3 matricies
even for hiearchies etc (for hiearchies i sujest to use quaternions)

rotations can be concatened by mattrix mult
translations can be concatened with vectors additions/substractions

you only need your 4 th dimentions for the transformations wich use it
the only one that i use is perspective transformations

some peaple only use 4*4 matrices for rotaions+translations 'coz this is easier to code
this is the only reason. IMHO

Colas


 
ROME

March 13, 1999, 02:49 PM



colas wrote:
>>
>>
>>rotations + translation can easily be done only with 3*3 matricies
>>even for hiearchies etc (for hiearchies i sujest to use quaternions)

Why is it better to use quaternions for hierarchies?
>>
>>rotations can be concatened by mattrix mult
>>translations can be concatened with vectors additions/substractions
>>
>>you only need your 4 th dimentions for the transformations wich use it
>>the only one that i use is perspective transformations
>>
>>some peaple only use 4*4 matrices for rotaions+translations 'coz this is easier to code
>>this is the only reason. IMHO

There must be other reasons.. doesn't it reduce the number of multiplies??
>>
>>Colas
>>
>>

 
ROME

March 13, 1999, 02:52 PM



Jeroen wrote:
>>
>>ROME wrote:
>>>Hi, Why are 4x4 matrices used for 3-Space sometimes instead of 3x3? I assume that 4x4 is
>>>used because it provides a place to put transformations, but is this is so, then how can
>>>translations be done using 3x3 matrices? Are the translations done manually (outside of
>>>a matrix)? What is matrix is most commonly used in engines, 3x3 or 4x4? Why is it important
>>>to have a homogeneous coordinate system matrix thing? =) Thanks.
>>
>>When using 3x3 matrices, a complete tranformation (ie. rotation and translation) is split in
>>two operations: 1 matrix multiplication (for rotation) and 1 vector addition (for translation).
>>Using homogeneous coordinates means the complete transformation can be done using one multiply,
>>but also very easy clipping and other nifty stuff.
>>

I see.. This is by far the best reply that I could have hoped for. Everything is explained perfectly. One more question however, is the one multiply instead of two faster or is it the same because more mulitiplies must be done when using a 4x4 matrix over that of a 3x3?? I will go and work it out onpaper now to see.. =) Thanks. ROME.
>>Cheers,
>>
>>Jeroen

 
Jeroen

March 14, 1999, 02:51 PM



colas wrote:
>>
>>rotations + translation can easily be done only with 3*3 matricies
>>even for hiearchies etc (for hiearchies i sujest to use quaternions)
>>
>>rotations can be concatened by mattrix mult
>>translations can be concatened with vectors additions/substractions
>>
>>you only need your 4 th dimentions for the transformations wich use it
>>the only one that i use is perspective transformations
>>
>>some peaple only use 4*4 matrices for rotaions+translations 'coz this is easier to code
>>this is the only reason. IMHO

That's not enturely true. Of course everything can be done using 3x3 matrices. But the
advantage of homogeneous coordinates is that _every_ transformation can be implemented
using the same operation: a matrix multiply. This means your code can be much more trans-
parant, expandable and maintainable.
On top of that, while processing homogeneous coordinates, your vectors temprarily reside in
a very usefull space: Perspective space.
After the perspective transform, but before the transform to screen-space, your coordinates
live in a sort of conical world, where hyperbolic interpolation becomes linear! This means
things like perspective texturemapping can be done using linear interpolation.

Jeroen

 
Jeroen

March 14, 1999, 02:51 PM



colas wrote:
>>
>>rotations + translation can easily be done only with 3*3 matricies
>>even for hiearchies etc (for hiearchies i sujest to use quaternions)
>>
>>rotations can be concatened by mattrix mult
>>translations can be concatened with vectors additions/substractions
>>
>>you only need your 4 th dimentions for the transformations wich use it
>>the only one that i use is perspective transformations
>>
>>some peaple only use 4*4 matrices for rotaions+translations 'coz this is easier to code
>>this is the only reason. IMHO

That's not enturely true. Of course everything can be done using 3x3 matrices. But the
advantage of homogeneous coordinates is that _every_ transformation can be implemented
using the same operation: a matrix multiply. This means your code can be much more trans-
parant, expandable and maintainable.
On top of that, while processing homogeneous coordinates, your vectors temprarily reside in
a very usefull space: Perspective space.
After the perspective transform, but before the transform to screen-space, your coordinates
live in a sort of conical world, where hyperbolic interpolation becomes linear! This means
things like perspective texturemapping can be done using linear interpolation.

Jeroen

 
ROME

March 14, 1999, 06:31 PM



Jeroen wrote:
>>
>>
>>colas wrote:
>>>>
>>>>rotations + translation can easily be done only with 3*3 matricies
>>>>even for hiearchies etc (for hiearchies i sujest to use quaternions)
>>>>
>>>>rotations can be concatened by mattrix mult
>>>>translations can be concatened with vectors additions/substractions
>>>>
>>>>you only need your 4 th dimentions for the transformations wich use it
>>>>the only one that i use is perspective transformations
>>>>
>>>>some peaple only use 4*4 matrices for rotaions+translations 'coz this is easier to code
>>>>this is the only reason. IMHO
>>
>>That's not enturely true. Of course everything can be done using 3x3 matrices. But the
>>advantage of homogeneous coordinates is that _every_ transformation can be implemented
>>using the same operation: a matrix multiply. This means your code can be much more trans-
>>parant, expandable and maintainable.
>>On top of that, while processing homogeneous coordinates, your vectors temprarily reside in
>>a very usefull space: Perspective space.
>>After the perspective transform, but before the transform to screen-space, your coordinates
>>live in a sort of conical world, where hyperbolic interpolation becomes linear! This means
>>things like perspective texturemapping can be done using linear interpolation.
>>
>>Jeroen

Alright. It seems that 4x4 matrices may have a slight advantage. However, If I were to change my Matrix3 class (which is a 3x3 matrix) into a 4x4 matrix class, would I not also have to add another point in my Vector Class so that a vector could be multiplied by a matrix?? So, instead of having X,Y,Z in my Vector Class.. I would have, for instance, X,Y,Z,W.. so that the multiplites woudl work out. Let me know and then I will descide whether or not I should implement the changes. I hope to hear from you soon, ROME.

 
Jorrit Tyberghein

March 15, 1999, 03:20 AM


>>That's not enturely true. Of course everything can be done using 3x3 matrices. But the
>>advantage of homogeneous coordinates is that _every_ transformation can be implemented
>>using the same operation: a matrix multiply. This means your code can be much more trans-
>>parant, expandable and maintainable.

There are other ways to do this. In Crystal Space I use a 3x3 matrix and a vector
because it is more efficient. However, the user does not need to worry about that
because both are wrapped in a transform class which takes care of hiding that
detail. So in fact you can have both the advantages of a 3x3 matrix/vector (efficiency)
as the advantages of a 4x4 matrix (simplicity) with one Transform class that does
the same.

Greetings,

 
cschrett

March 15, 1999, 04:44 AM



ROME wrote:

>> Why is it better to use quaternions for hierarchies?

a complete 3d transformation can be represented by a quaternion.
if you want to concate two transformation then you can multiply two quaternion
mutltiply two quaternion is faster than matmault (less muls)
BUT there is a drwaback the conversion from the quaternion rep^resentation to
matrix representation is costly. So Quats is usefulle only if you use many
successive transformations.

i know that some peaple use entire quaterion math even for the rotation of the
points this save cpu time.

some people claim that quaterion give beter interpolation between two rotations.
with the slerp (spherical interpolation)
but i find tha simply interpolate the angles with a spline do the work.


>> There must be other reasons.. doesn't it reduce the number of multiplies??

3x3 mult take 27 muls and 4*4 = 36 muls

some people assume thas some values of their 4*4 matrix are zero valued.
but what is the sense to use 4*4 matricies then ? if your mat mul is not
a real mat mult and vector mult are not true one.

i use 3*3 matrices + a vector to represent a rotation + translation

Colas

 
ROME

March 15, 1999, 10:44 AM



Jorrit Tyberghein wrote:
>>
>>>>That's not enturely true. Of course everything can be done using 3x3 matrices. But the
>>>>advantage of homogeneous coordinates is that _every_ transformation can be implemented
>>>>using the same operation: a matrix multiply. This means your code can be much more trans-
>>>>parant, expandable and maintainable.
>>
>>There are other ways to do this. In Crystal Space I use a 3x3 matrix and a vector
>>because it is more efficient. However, the user does not need to worry about that
>>because both are wrapped in a transform class which takes care of hiding that
>>detail. So in fact you can have both the advantages of a 3x3 matrix/vector (efficiency)
>>as the advantages of a 4x4 matrix (simplicity) with one Transform class that does
>>the same.

I did not know that you came on here Jorrit. I have been looking through your code for a couple of weeks now. Concerning your Transform class, Do you just give it a vector and a matrix to switch between coordinate systems?
>>
>>Greetings,

 
ROME

March 15, 1999, 10:49 AM



cschrett wrote:
>>
>>
>>ROME wrote:
>>
>>>> Why is it better to use quaternions for hierarchies?
>>
>>a complete 3d transformation can be represented by a quaternion.
>>if you want to concate two transformation then you can multiply two quaternion
>> mutltiply two quaternion is faster than matmault (less muls)
>>BUT there is a drwaback the conversion from the quaternion rep^resentation to
>>matrix representation is costly. So Quats is usefulle only if you use many
>>successive transformations.
>>
>>i know that some peaple use entire quaterion math even for the rotation of the
>>points this save cpu time.
>>
>>some people claim that quaterion give beter interpolation between two rotations.
>>with the slerp (spherical interpolation)
>>but i find tha simply interpolate the angles with a spline do the work.
>>
>>
>>>> There must be other reasons.. doesn't it reduce the number of multiplies??
>>
>>3x3 mult take 27 muls and 4*4 = 36 muls
>>
>>some people assume thas some values of their 4*4 matrix are zero valued.
>>but what is the sense to use 4*4 matricies then ? if your mat mul is not
>>a real mat mult and vector mult are not true one.

Exactly my point! I have seen some engines that actually tweak their matrix classes etc so that they do not do the regualt amount of muls. I must stress, THAT IS WRONG, math can not be changed. It is what t is. 'Tweaking' your math code so that it does not follow th emath rules is just silly. Sorry for the emotions, ROME. :) 3x3 does seem to be the best.
>>
>>i use 3*3 matrices + a vector to represent a rotation + translation
>>
>>Colas

 
Jorrit Tyberghein

March 16, 1999, 03:24 AM

>>>>There are other ways to do this. In Crystal Space I use a 3x3 matrix and a vector
>>>>because it is more efficient. However, the user does not need to worry about that
>>>>because both are wrapped in a transform class which takes care of hiding that
>>>>detail. So in fact you can have both the advantages of a 3x3 matrix/vector (efficiency)
>>>>as the advantages of a 4x4 matrix (simplicity) with one Transform class that does
>>>>the same.
>>
>> I did not know that you came on here Jorrit. I have been looking through your
>> code for a couple of weeks now. Concerning your Transform class, Do you just
>> give it a vector and a matrix to switch between coordinate systems?

Indeed.

Greetings,

 
Louis TRemblay

May 11, 1999, 06:21 PM

[clip]
>> Alright. It seems that 4x4 matrices may have a slight advantage. However, If I were to
>>change my Matrix3 class (which is a 3x3 matrix) into a 4x4 matrix class, would I not also
>>have to add another point in my Vector Class so that a vector could be multiplied by a
>>matrix?? So, instead of having X,Y,Z in my Vector Class.. I would have, for instance,
>>X,Y,Z,W.. so that the multiplites woudl work out. Let me know and then I will descide
>>whether or not I should implement the changes. I hope to hear from you soon, ROME.

If you only want to use a matrix for transformations and rotations, then you can always assume your coord to be in the format X, Y, Z, W where W is always 1.

For example, suppose you have a vertex( or vector ) (X, Y, Z) then it will be (X, Y, Z, 1) before the multiplication by the matrix. After the multiplication, your vertex will be (X', Y', Z', 1 ).

Now, if you want to do some fancy stuff, like including a projection matrix, you cant do that. You'll be in homogeneous coordinate and W wont be equal to 1. There is many advantage of this techniques: the clipping is very easy in homogeneous coordinate( after you have a good understanding of the theory. ). Also, all the object-space to screen to the canonical view can be done with only 1 matrix. It is a very efficient way of doing things.

The only problem is tranfroming a point from homogeneous coordinate to screen space. You have to divide X, Y Z by W. BUT, some accelerator card does that in hardware( like the voodoo 2&3).

I hope I'm clear enough. :) My english is far from perfect. If you have some others questions, I'll do my best. :)

 
This thread contains 14 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.