Jump to content
  • Advertisement
Sign in to follow this  

Noob matrix-vector question

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can anyone explain what the result of this operation is? Given Vector V (x, y, z, w) and a Matrix M:
0.5  0    0    0.5
 0  0.5   0    0.5
 0   0   0.5   0.5
 0   0    0     1  
What is VxM? Yeah I've been implementing projective texturing and I'm not entirely sure how this bit works. I tried figuring it out on paper but I just ended up the the same vector V as a the result =/

Share this post


Link to post
Share on other sites
Advertisement
First, just for clarification, VxM implies a cross-product of the vector with the matrix, which can't really be done. I'll assume you mean V*M (multiply the vector by the matrix).

This is all off the top of my head, by the way.

Your matrix appears to be a scale of 0.5 along each axis, and a translation of 0.5 along each axis.

The result vector r, assuming row major matrices (column 3 appears to be a translation):

Notation: m[row,col]

r.x = v.x*m[0,0] + v.y*m[0,1] + v.z*m[0,2] + v.w*m[0,3];
r.y = v.x*m[1,0] + v.y*m[1,1] + v.z*m[1,2] + v.w*m[1,3];
r.z = v.x*m[2,0] + v.y*m[2,1] + v.z*m[2,2] + v.w*m[2,3];
r.w = v.x*m[3,0] + v.y*m[3,1] + v.z*m[3,2] + v.w*m[3,3]; // == v.w*1 in this case

Share this post


Link to post
Share on other sites
Hi there Dom!

Your matrix seesm to be in row major order and it contains two transformations: scaling folllowed by translation. Actually it implements what is called scale and bias.

You have row major matrix, you will also have row major vectors so you will multiply in this order:
V * M
1x4 * 4x4
It's like you said.

after the multiplication V will become (x/2+0.5, y/2+0.5,z/2+0.5,w).

Share this post


Link to post
Share on other sites
Ooops, sorry when I said VxM I did mean multiplication not cross-product >.>

Thanks for your help, it makes sense now. Just out of interest were you able to figure out exactly what the matrix does without doing the calculations? Like just by looking at it?

Share this post


Link to post
Share on other sites
Quote:
Original post by Dom_152
Ooops, sorry when I said VxM I did mean multiplication not cross-product >.>

Thanks for your help, it makes sense now. Just out of interest were you able to figure out exactly what the matrix does without doing the calculations? Like just by looking at it?


Yes, we can figure that out just by looking at it. You will be able to do that soon, so don't worry.

First of all, on the diagonal there are the scaling factors, they are all 0.5.
In the last column there is the translation. These are always in the same position for every (row major) matrix!

Share this post


Link to post
Share on other sites
Quote:
Like just by looking at it?

[WINK]
After majoring in engineering physics with 4+ years of calculus and advanced math, and programming 3D graphics for many years, yeah. Education and experience are wonderful things.

You'll be doing it off the top of your head, too, if you keep asking questions.

EDIT:
Quote:
the translation .. always in the same position for every matrix!
Well, only for row-major mats. In column-major, the last row is the translation.

Share this post


Link to post
Share on other sites
I think this topic needs some clarification.

Row/column major order denotes how the 2 dimensional layout of a matrix is linearized for storage in 1 dimensional computer memory. It is totally independent on whether row or column vectors are used. The OP shows a matrix in 2D layout. Of course it is possible (and probable) that the shown matrix is re-layouted from 1D computer memory and that an error was done by chosing the wrong order.

With v*M it is so that row vectors are used (due to the reason Deliverance has written). With the given matrix the result would be
v*M = [ 0.5*x, 0.5*y, 0.5*z, 0.5*x+0.5*y+0.5*z+w ]

If, on the other hand, the matrix was incorrectly re-layouted, it would correctly look like
0.5  0   0   0 
0 0.5 0 0
0 0 0.5 0
0.5 0.5 0.5 1
and then
v*M = [ 0.5*x+0.5, 0.5*y+0.5, 0.5*z+0.5, 1 ]

It may further be that the matrix is correct but column vectors are used instead of row vectors. In that case
v*M
is the wrong part. Instead, it has to be
M*v
for which, using the OP's matrix, again
M*v = [ 0.5*x+0.5, 0.5*y+0.5, 0.5*z+0.5, 1 ]

Share this post


Link to post
Share on other sites
Quote:
Original post by Deliverance
In the last column there is the translation. These are always in the same position for every (row major) matrix!
The column (for column vectors) or the row (for row vectors) that has the same index as the homogeneous (usually named w) co-ordinate in a vector stores the translation. It is one convention to use the last component for that, but you can find enough examples where w is the first component.

Please bear in mind that vector math has some conventions, and all sort of problems simply arise because the conventions in use are not communicated.

Share this post


Link to post
Share on other sites
Thanks to everyone for clarifying and helping me to understand this stuff =)

I'm making my first proper steps into the realms of 3D graphics programming so hopefully this stuff will become second nature over time!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!