Jump to content
  • Advertisement
Sign in to follow this  
uncle_rico

Why homogeneous coordinates?

This topic is 4558 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

I understand how homogeneous coordinates make it possible to do translations using matrix multiplications, but I was wondering why using matrix multiplications is preferable to simply adding two row matrices together: p1 = [ 3 20 11 ] And if you want to translate it three units along the x axis: p1 += [ 3 0 0 ]

Share this post


Link to post
Share on other sites
Advertisement
Because it's unified. A 4x4 matrix can represent any affine transformation, instead of only representing a certain class of affine transformations.

Share this post


Link to post
Share on other sites
Besides unification, the w coordinate can also be very useful: perspective transformations, having things go to infinity (by setting it to 0; for example, if you want to draw your XYZ axes), etc...

Share this post


Link to post
Share on other sites
Quote:
Original post by uncle_rico
Thanks guys.

What does it mean to be unified?


One example. Transforming a direction vs. a position. In 3D, both can be represented by a "vector" object, e.g., 3 floats----one for x, y, and z. But, whereas a position represents a specific location relative to some origin point (and therefore must include translation), the direction is the same everywhere in the 3D space (and should not be affected by translation). (The x direction----represented by the vector <1,0,0>----is the same whether you are at the origin or if you are sitting a point 10 miles north and 2 thousand feed in altitude.) Without homogeneous coordinates, you'd have to have separate blocks of code----one to handle direction vectors and another to handle position vector. Or you could have an expensive conditional/branch statement such as an if/then.

So, the unification is that with homogeneous coordinates you can use exactly the same code---no conditional/branching code whatsoever---to deal with both direction and position vectors. Here, for 3D, you represent all vectors as 4 floats---the first 3 are x, y, and z, and the last one, w, allows you the flexibility in how the vector is transformed. Transformation matrices are 4x4, and include rotation, scale, and translation. Direction vectors should not include translation, and so you'd set w to 0.0. Position vectors do need to include translation, so you'd set w to 1.0 (usually, or some other nonzero number depending on what you're doing exactly).

With specialized processors/GPU's that have special hardware for homogeneous vector operations...homogeneous transformations are not necessarily slower than doing a non-homogeneous operation on a smaller vector. Even with SSE/SSE2/SSE3 instructions, homogeneous operations can even be faster.

SSE2 Overview @ Intel

Share this post


Link to post
Share on other sites
Quote:
Original post by grhodes_at_work
So, the unification is that with homogeneous coordinates you can use exactly the same code---no conditional/branching code whatsoever---to deal with both direction and position vectors.


That will not work for normal vectors, although they are directions too. For normals you have to use the transpose inverse of the transformation matrix.

Share this post


Link to post
Share on other sites
uncle_rico..

Most people in the software only days would implement it just it as you suggested because it was faster.

I'm guessing the usage of the 4x4 became industry-cool because of OpenGL's minimal API and the fact that matrix ops became near zero in most peoples benchmarking (so it didn't matter if the more general code was a little slower.)

However.. When it comes down to it, it is just a clever 'trick' that became the standard that most people talk about.

Share this post


Link to post
Share on other sites
Quote:
Original post by nmi
Quote:
Original post by grhodes_at_work
So, the unification is that with homogeneous coordinates you can use exactly the same code---no conditional/branching code whatsoever---to deal with both direction and position vectors.


That will not work for normal vectors, although they are directions too. For normals you have to use the transpose inverse of the transformation matrix.


True, but you are simply talking about which transformation matrix you multiply the normal vector by. The actual, underlying code to perform the transformation matrix multiply is exactly the same.

Share this post


Link to post
Share on other sites
I think that the best reason for using homogenous coordinates for translations as opposed to simply adding them is because usually, translation is not the only transform you are doing. Meaning - if you are moving something around in world space it probably involves not only a translation but also a rotation and maybe scaling as well. Homogenous coordinates allow you to concatenate all of these transformation matrices together by matrix multiplication, leaving you with a single matrix that you can apply to your point or vertex, as opposed to doing separate multiplication calculations for each transformation.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!