# why use homogeneous coordinates?

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

## Recommended Posts

hi, I'm positing this because I don't really understand the use of homogeneous coordinates in a 4x4 matrix. I understand that the extra dimension is just a dividing factor so...
[ 1 0 0 px ]
[ 0 1 0 py ]
[ 0 0 1 pz ]
[ 0 0 0 1  ]


makes sense as the x, y and z axis would extend to infinity and the point p would remain the same. When adding a vector though, if the w component of each vector in this matrix remain the same, will the resultant vectors w component not be the same as the point/vector to be translated? eg.
[ 1 0 0 0 ]   [ 10 ]   [ 10 ]
[ 0 1 0 0 ]   [ 10 ]   [ 10 ]
[ 0 0 1 0 ] X [ 10 ] = [ 10 ]
[ 0 0 0 1 ]   [  1 ]   [  1 ]


or do the values in the w components in the matrix change?

##### Share on other sites
Since nobody answered yet, I will try to add my 2 cents. 4x4 matrices are useful because they let you use linear and affine transformations in the 3x3 space. If you wanted to translate a point, with a 3x3 matrix (and 3-components vectors) you should perform it separately from rotation and scale. Using 4x4 matrices you can perform scale, translation and rotation using just one matrix. Using 4-components vectors lets you use the same classes for vectors and point, since they are semantically different: i.e you can't translate a direction, or get a point length. If you use w = 0 for directions and w = 1 for points, translation wont apply on directions (w = 0). In addition, point + vector = point (1+0=1), point - point = direction (1-1=0), point+direction = point (1+0=1) and so on. Of course, you cannot do point + point or direction - point directly (because these operations are not legal really).
4x4 matrices make possible to apply transformations such as translation with the same matrix you use for rotations and scaling.

Hope this help

##### Share on other sites
Homogeneous coordinates are used for projections
e.g.: perspective projections

set w=0 would translate the point infinitely far away after dehomogenization

here is a derivation of the perspective transformation matrix

http://www.cs.kuleuven.ac.be/cwis/research/graphics/INFOTEC/viewing-in-3d/node8.html

there are also some nice properties that you will likely learn when studying computer science

##### Share on other sites
I thought that perspective projection was achieved by dividing the x and y components of the translated coordinate by the z component?

##### Share on other sites
Quote:
 4x4 matrices make possible to apply transformations such as translation with the same matrix you use for rotations and scaling.

Right.

Quote:
 I thought that perspective projection was achieved by dividing the x and y components of the translated coordinate by the z component?

Kinda. The typical projection matrix is most real-time 3D graphics applications looks like
A 0 0 00 B 0 00 0 C D0 0 1 0

so when a vertex is multiplied by this vector, we have
x y z w * A 0 0 0 = xA yB zC + wD zE          0 B 0 0          0 0 C E          0 0 D 0

(for row vectors, like D3D; transpose everything for column vectors), and typically E and w are both 1, so we end up with a clip-space vector (xA, yB, zC + D, z). Once clipping is performed, the vector is component-wise divided by it's w component, which is proportional to the original z component of the vector.

So while technically the pipeline performs division by w, in practice, the value of w is usually proportional to the view-space z of the vertex.

Quote:
 When adding a vector though, if the w component of each vector in this matrix remain the same, will the resultant vectors w component not be the same as the point/vector to be translated?

How the w component is handled depends on the context in which you are handling it; frequently most CPU-side manipulation uses 3-vectors, and the API understands that 3-vectors should be extended to 4-vectors by setting w to one.

##### Share on other sites
in the last matrix diagram - would the result vector not be:

xA
yB
zC + wE
zD

?

##### Share on other sites
Quote:
 Original post by staticVoid2in the last matrix diagram - would the result vector not be:xAyBzC + wEzD?

In his example, [x y z w] is a row on the left. In your examples, the vector is a column on the right.

##### Share on other sites
Quote:
 in the last matrix diagram - would the result vector not be:

Nope.

Looking at the multiplication visually and isolated to this specific scenario, we calculate element i of the result matrix as the dot product of the left vector and column i from the right matrix, for example:
X: (x y z w) <dot> (A 0 0 0) = (xA + 0  + 0  + 0)  = xAY: (x y z w) <dot> (0 B 0 0) = (0  + yB + 0  + 0)  = xBZ: (x y z w) <dot> (0 0 C D) = (0  + 0  + zC + wD) = zC + wDW: (x y z w) <dot> (0 0 E 0) = (0  + 0  + zE + 0)  = zE

The columns, above, are written as rows to save space.

You can achive the answer you thought would be correct, as JohnBolton says. However, in doing so you change the result of the operation. As I said before, if you want to use columns on the right (and still want to have the same result, but obtained through a different process), you should transpose the matrix as well (consider a translation matrix).

##### Share on other sites
so if was to code a camera class that stored a 3x4 matrix:

a b c d
1 0 0 0
0 1 0 0
0 0 1 0

where a was the x axis vector, b - the y axis vector, c - the z axis vector and d the camera location. then I had a function to transform a 3d point.

eg.
1 0 0 10    500 1 0 10 x 1000 0 1 10    50            -1   40=  90   40

then with the new coordinate (40, 90, 40), divide the x and y components by z
(x/z, y/z) = (1, 2) to give the 2d screen coord.

why do you need an extra component(w) for each vector?

##### Share on other sites
Quote:
 divide the x and y components by z(x/z, y/z) = (1, 2) to give the 2d screen coord.

The actual pipeline is more complex than this; the projection matrix which is applied after the view matrix brings the view-space vertices into clip space, where clipping is performed. The vertices that survive are divided by their w coordinates to bring them into normalized-device-coordinate space, which is then offset and scaled by further matrices to bring them into actual pixel coordinates.

Quote:
 why do you need an extra component(w) for each vector?

Because otherwise you cannot use a 4x4 matrix. If you don't use a 4x4 matrix, you can't use a single matrix to represent rotational, scaling, and translation.

You can't actually multiply a 3x4 matrix and a 3x1 vector. It's mathematically impossible for the accepted definition of matrix multiplication.

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 20
• 14
• ### Forum Statistics

• Total Topics
632950
• Total Posts
3009385
• ### Who's Online (See full list)

There are no registered users currently online

×