• ### Announcements

#### Archived

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

# Can somebody please explain homogenous coordinates to me?

## 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

##### Share on other sites
You can''t do a translation in 3-space with a 3x3 matrix. The origin remains fixed, since a matrix represents a "linear mapping" function such that

f(a+b) = f(a) + f(b)
and f(ka) = kf(a) where k is a constant.

Hence f(0a) = 0f(a) = 0.

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

##### Share on other sites
thanks alvaro for the bracket correction

##### Share on other sites
"Paradigm Shifter" ! thanks for responding.

may u explain it in more detail ?

regards
dotcdotc

##### Share on other sites
Google for "Projective Geometry" or get a book on the subject. You need a solid linear algebra background to fully grasp it.

##### Share on other sites
its the same as with .. how are they called? well those numbers with division in:
     ac = ---     b

with w being below the line, and the x,y,z above the line. now, with w == 1, as most the time, we get directly the point, as anything/1 == anything. with b going close to 0, c gets close to infinity. reaching zero, c "is" infinity (yeah, hang me on this).

same happens with the (x,y,z)/w.. if w = 0, xyz reaches infinity, in the direction of x,y,z.

its not the same, and c is not infinity, and all bla bla, but the idea is similar. more about this in google if you search for projective geometry, and check the stuff from others.

hope this gives an idea (and some people can check wich word i''m always searching for. i always forget this).

If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net

##### Share on other sites
In opengl I believe the w component is actually used after perspective tranformation. Look up opengl perspective matrix, or opengl perspective projection and look at the matrix, it uses the w component, and i don''t think the tranformation can be completed without use of it, so when you send just 3-vectors (w/o w) it''s thes ame as with a w as 1, and the use of it is implicit, and if matrix multiplication in opengl is done fully with a 4x4 matrix, then there is a temporary memory location that stores the w for completing the transformation. This was purely speculation but it makes sense to me.

##### Share on other sites
temp:
I agree. I think even if you are in 2D ortho view, the positions are treated with 4D vectors, and I think the GPUs are also designed and optimized for 4x4 matrix operations. The texture coordinates are also 4D, even if you mostly determine 2 of them.

##### Share on other sites
hi all,

I understand some Geometry like what is Euclid space, coordinate system(2D,3D), Left/Right Handed System etc. simple things.

Then I tried to implement it on computer screen which infact left me confused.

some confusions are (while doing perspective projection)

1) which System (Left handed or Right Handed) has to b used and why ?

2) In both the systems Left and Right handed System Y increases upwards but in practice (on computer screen) it increases downward so what is the optimum way of eliminate this problem.

3) and still ''w'' the fourth coordinate is a mystry to me. Anyway I didn''t try to use it. In my Perspective Projection code I did like this

to calculate X-axis of object on projection screen

xp = d*X/Z;

where xp is projeted X-axis of object
d is focal length (distance from camera to projection screen)
X is actual X- axis of object
Z is distance from camera to Object

please dont get angry if u feel my questions r silly.Iam completly confused.

regards
dotc

##### Share on other sites
When you multiply a vector by a projection matrix, the w coordinate should end up Z/d. You do a post-projective divide by w, and end up with xp=d*x/Z, yp=d*y/Z, zp = d.

[edited by - impossible on May 31, 2004 12:15:28 AM]

##### Share on other sites

please suggest me a good book on mathematics which must be easy to understand

topics that must be insidet the book

1) Geometry (specially Perspective Geometry)
2) Linear Algebra

I shall be very thankful.

regards
dotc

• ### Forum Statistics

• Total Topics
628290
• Total Posts
2981856

• 11
• 10
• 10
• 11
• 17