# how homogenous vectors are dealt with

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

## Recommended Posts

My (probably wrong) initial understanding was that vectors that represent directions have w=0 and points have w=1. So for instance a ray which = p0 + tv would have p0.w = 1 and v.w=0. That way when the ray is transformed p0 can get translated if needed and v will not. Is this the convention?...because it seems that everyone thinks that every vector should just have a tailling 1. If you are dealing with homogenous vectors...shouldn't a dot product of two 4-d vecs not deal with the w component? Same with scaling? Every homogenous vector class I find on the internet treats w just like x,y, and z when doing scaling, dot product, addition etc. But this doesn't make sense to me. If you want to do scale a point by t, when would it be appropriate to multiply w by t (that effectively doesn't do anything to the euclidian equivalent). And if (1,1,1,1) is equivalent to (2,2,2,2) shouldnt' their dot prods be the same (i.e divide by w before performing dot product). Or is it that you wouldn't scale it unless it represented a direction, in which case w=0 and it would be equivalent to its 3d counterpart? On that note, why would you ever want w to be different from 0 or 1 in the first place?

##### Share on other sites
Quote:
 Original post by EODCyismARDEMMy (probably wrong) initial understanding was that vectors that represent directions have w=0 and points have w=1. So for instance a ray which = p0 + tv would have p0.w = 1 and v.w=0. That way when the ray is transformed p0 can get translated if needed and v will not. Is this the convention?

Yup.
Quote:
 If you are dealing with homogenous vectors...shouldn't a dot product of two 4-d vecs not deal with the w component?

It doesn't matter, because you should never be taking the dot product of two points. The w contribution of any meaningful dot product will be zero.
Quote:
 Same with scaling?

If you're talking about a scaling matrix: all scaling matrices scale the w component by 1. If you're talking about scaling the homogeneous vector as a whole, that's a deeper mathematical operation that doesn't really have a quick and easy geometric counterpart. It comes into play once you're doing a perspective division. That's also where points will start having w components other than zero. It's a complicated area. The OpenGL red book, in my opinion, has a great description of how perspective projection works.

##### Share on other sites
Thanks for the quick help man.

I understand that homogenous coords become more important when perspective transformations come into play...but does this mean that people usually internally represent all points and directions and stuff as 3d vecs, and then later convert to 4d vecs. Cause now my code has more 4d vecs with 0 at the end than 1 at the end...which seems inconsistent with almost everyone saying "w=1 usually".

##### Share on other sites
It was my understanding that the w in homogenous vectors or points always was a scalar. 1 represtented that no scaling was necessary. I read that in a book somewhere but I may have mis-understood it may have just been talking about points. In my own engine I only use homogenous arrays just before matrix multiplication, then afterward I go back to 3d arrays. I do the same for points or vectors. Although perhaps with the zero in the 4th spot may cause the vector to be normalized.

##### Share on other sites
As Sneftel was saying, you had it right to begin with. Points should have w=1 and vectors should have w=0. One reason for this is if you have a translation transformation matrix (ie: last column (or row) contains an offset to translate by), then multiplying your point by this matrix gives a translated point and multiplying a vector (w=0) by this gives the same vector as before. In other words, translations don't affect vectors, and they shouldn't. It might be helpful to double check this on paper if you don't see how that works right away.

It helps to distinguish between vectors and points in your code so you don't accidentally take, say, the dot product of 2 points (which again, as Sneftel pointed out, dosn't make sense and shouldn't be done).

Essentially though, if you are working with 4x4 matrices (which presumably you are if you're using Direct3D or OpenGL), then you should work with 4D points and vectors with w=1 for points and w=0 for vectors.

• 12
• 40
• 15
• 10
• 23