U of I Math Ping Hu

Homogeneous Coordinates in OpenGL

There are three fundamental transformations: Translation, Scaling and Rotation. And in OpenGL, there are corresponding functions.

Translation: glTranslate(x,y,z) produces a translation by $(x,y,z)$. For example, the vertex $(a,b,c)$ will be translated to $(a+x,b+y,c+z)$.

Scaling: glScale(x,y,z) produces a nonuniform scaling along the x, y, and z axis.The three parameters indicate the desired scale factor along each of the three axes. For example, the vertex $(a,b,c)$ will be scaled to $(ax,by,cz)$.

Rotation: glRotate(angle, x, y, z) produces a rotation of angle degrees around the vector $(x,y,z)$. But when we use this function, we usually set one of $x,y,z$ be $1$ and others be $0$. For example, glRotate($\alpha, 1, 0, 0$) means a rotation about $x$-axis of $\alpha$ degrees.

In OpenGL, you need to compute the composition of some transformations, so all these transformations are denoted by transformation matrices. Then when we compute the composition, what we really do is multiply several matrices, which can be accelerated by hardware. Because of this, we want to use Homogeneous Coordinates $(x,y,z,w)$ instead of Cartesian Coordinates $(x,y,z)$. Here the homogeneous coordinate $(x,y,z,w)$ is $(x/w,y/w,z/w)$ in cartesian coordinate when $w\ne 0$. And when $w=0$, it means an infinity point and this infinity point is obtained by moving the point $(x,y,z)$ to infinity along the vector $(x,y,z)$.

The reason we use Homogeneous Coordinates is by using this instead of Cartesian Coordinates, we can denote every transformation by a $4\times 4$ matrix. For Cartesian Coordinates $t=(x,y,z)$, if $M$ is a $3\times 3$ matrix, then $tM$ cannot be a translation of $t$. But in Homogeneous Coordinates, glTranslate(x,y,z) can be denoted by $\left(\begin{array}{cccc}1 & 0 & 0 & x \\0 & 1 & 0 & y \\0 & 0 & 1 & z \\0 & 0 & 0 & 1\end{array}\right)$ becasue $\left(\begin{array}{cccc}1 & 0 & 0 & x \\0 & 1 & 0 & y \\0 & 0 & 1 & z \\0 & 0 & 0 & 1\end{array}\right)\left(\begin{array}{c}a\\b\\c\\1\end{array}\right)=\left(\begin{array}{c}a+x\\b+y\\c+z\\1\end{array}\right)$. And similarly, glScale(x,y,z) can be denoted by $\left(\begin{array}{cccc}x & 0 & 0 & 0 \\0 & y & 0 & 0 \\0 & 0 & z & 0 \\0 & 0 & 0 & 1\end{array}\right)$ glRotate($\alpha, 1, 0, 0$): $\left(\begin{array}{cccc}1 & 0 & 0 & 0 \\0 & \cos \alpha & -\sin\alpha & 0 \\0 & \sin\alpha & \cos\alpha & 0 \\0 & 0 & 0 & 1\end{array}\right)$ glRotate($\alpha, 0, 1, 0$): $\left(\begin{array}{cccc}\cos \alpha & 0 & \sin\alpha & 0 \\0 & 1 & 0 & 0 \\-\sin\alpha & 0 & \cos\alpha & 0 \\0 & 0 & 0 & 1\end{array}\right)$ glRotate($\alpha, 0, 0, 1$): $\left(\begin{array}{cccc}\cos \alpha & -\sin\alpha & 0 & 0 \\\sin\alpha & \cos\alpha & 0 & 0 \\0 & 0& 1 & 0 \\0 & 0 & 0 & 1\end{array}\right)$