#### Archived

This topic is now archived and is closed to further replies.

# Can somebody please explain homogenous coordinates to me?

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

## Recommended Posts

I know that for 2D theres (x,y,w) and in 3D theres (x,y,z,w). I don''t understand why we need the ''w'' factor in there. All that I know about h-coordinates is that if w == 1, then the transformation inside that matrix has un-altered values so to speak.

##### Share on other sites
To use matrices to transform a 3D point, (x,y,z), you multiply by a 3x3 matrix. Unfortunately, there''s no way to translate with a 3x3 multiplication. So we add a fourth component, so that we can multiply by a 4x4 matrix to get translation into the matrix easily. That''s basically the only reason you need one more coordinate than the number of dimensions. The same goes for 2D.

There''s a neat Nvidia demo about messing with the w coordinate; IIRC changing the values affects the scaling of the vertices used, since rendering projects the coordinates back into w=1 space.

##### Share on other sites
quote:
Original post by Ekim_Gram
I know that for 2D theres (x,y,w) and in 3D theres (x,y,z,w). I don''t understand why we need the ''w'' factor in there. All that I know about h-coordinates is that if w == 1, then the transformation inside that matrix has un-altered values so to speak.

Well, there''s an explanation as to what the w represents but the main reason the we are required to add the ''w'' parameter is because when we perform transformations and translations we use 4x4 matricies.

Hence, when we bring in the matix multiplication necessary to achieve our transformation or translation, the 4th column in our row vector([x,y,z,w]), ''w'' is required to make the multiplication legal by simple laws of matrix multiplication.

When we set w = 1, this allows translations of single points to translate correctly. When we set w = 0, this allows translations of vectors to translate correctly.

(yes i''m horrible at explaining things.)

cheers,

vizuäl

##### Share on other sites
Another way of thinking of it is that a homogenous coordinate with w = 1 is a point in space, and an h-coord with w = 0 is a vector or ''point at infinity'', i.e. a direction but not a location.

When you consider this definition when applying 4X4 matrices, it works out. A vector cannot be translated, and in fact the w = 0 prevents it from being translated when the matrix is applied. A point, however, will be translated, as it should be, due to the w = 1.

In practice, we hardly ever go to all this trouble, because we end up with a number of multiplications by 1 and 0. So usually we just multiply the x, y, z components by the 3X3 portion of the matrix, and add the translation separately.

Also, to find the point in space that an h-coord represents, divide the x, y and z by the w component. So, for example [5, 5, 5, 1] and [10, 10, 10, 2] represent the same point in space.

These days most of us let the graphics API handle projection, but if you''re doing it yourself, the w component comes in handy.

Does that help at all?

##### Share on other sites
Google for projective geometry if you want to read all about it. Its easier to start by understanding 2d homogeneous space projected on a plane using 3x3 matrices rather than go the whole 3d and 4x4 approach. Linear algebra will be helpful for understanding it.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

##### Share on other sites
Consider two 4vectors (with w <> 0) and as equivalent when w2* == w1*
this is an equivalency relationship. if (w1 == 0) != (w2 == 0) then the 2 vectors are not equivalent, and if w1==w2==0 then the two vectors are equivalent <=> x1==x2 and y1==y2 and z1 == z2
Now consider the equivalency classes of the vector space (mathworld that).
the equivalency classes with w != 0 map to the R^3 vector space using this formula
maps to in R^3.
the equivalency classes with w == 0 map to the unit sphere.
so we have a bijection between the equivalency classes and R^3 U
the unit sphere (direction vectors)
(note that two equivalent 4vectors map to the same element in R^3)
the linear operations (4x4 matrices) in the 4 space map to operations that include translations and perspective projections, that are not linear operations.
The trick of using this 4x4 representation is that it is possible to represent non limear operations in a lower dimensional space by linear operations in a higher dimensional space. Linear operations are computationally fast, an benefit from a strong mathematical basis, plus most (tech) people are able to reason correctly using liear algebra.
The homogenous representation is a bit ad hoc, but has the benefit of fitting extremely well with the geometry used in rendering. It is a trick, because the w coordinate does not mean anything, but mathematically, it is a strong concept.

##### Share on other sites
I corrected the brackets. Let''s see if it makes more sense now.
quote:
Original post by janos
Consider two 4vectors (with w <> 0) (x1,y1,z1,w1) and (x2,y2,z2,w2) as equivalent when w2*(x1, y1, z1) == w1*(x2,y2,z2)
this is an equivalency relationship. if (w1 == 0) != (w2 == 0) then the 2 vectors are not equivalent, and if w1==w2==0 then the two vectors are equivalent <=> x1==x2 and y1==y2 and z1 == z2
Now consider the equivalency classes of the vector space (mathworld that).
the equivalency classes with w != 0 map to the R^3 vector space using this formula
[x,y,z,w] maps to (x/w, y/w, z/w) in R^3.
the equivalency classes with w == 0 map to the unit sphere.
so we have a bijection between the equivalency classes and R^3 U
the unit sphere (direction vectors)
(note that two equivalent 4vectors map to the same element in R^3)
the linear operations (4x4 matrices) in the 4 space map to operations that include translations and perspective projections, that are not linear operations.
The trick of using this 4x4 representation is that it is possible to represent non limear operations in a lower dimensional space by linear operations in a higher dimensional space. Linear operations are computationally fast, an benefit from a strong mathematical basis, plus most (tech) people are able to reason correctly using liear algebra.
The homogenous representation is a bit ad hoc, but has the benefit of fitting extremely well with the geometry used in rendering. It is a trick, because the w coordinate does not mean anything, but mathematically, it is a strong concept.

##### Share on other sites
No, it''s still wrong.

Take the non-zero vectors of R^4 modulo the equivalence class of being proportional. That''s the 3-dimensional projective space. You can identify R^3 with a subset of that space by mapping (x,y,z) to [x,y,z,1]. The classes not covered are [x,y,z,0], which is in itself a projective plane that we shall call "plane at infinity".

I am pretty sure that''s the right picture. I happened to take Projective Geometry in college, 6 hours a week for an entire year, and it was my favourite class.

##### Share on other sites
Mathematically, the w component is the place for holding the perspective divide when multiplying by the perspective projection matrix used by opengl. Don''t quote me on this, however, I haven''t fully lerned perspective projection yet.

##### Share on other sites
hi,

I am reading 3D since last few days and today I have got stuck with Homogenous Coordinates.

I could not understand why and where do I need this w because It is not making any difference at all.

If I am multiplying

[x y z] * [ 3 by 3 matrix]

[x y z 1] * [4 by 4 matrix]

results r same except ''1'' (it remains as it is).

So please help me what is this ''w''. Where from it has come and what difference does it make. And what would happen if I''ll not use it.

thanks in anticipation

• 36
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631359
• Total Posts
2999539
×