Skip to main content
Engineering LibreTexts

5.6: Three-Dimensional Homogeneous Coordinates

  • Page ID
    9980
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    We now consider the storage and manipulation of three-dimensional objects. We will continue to use homogeneous coordinates so that translation can be included in composite operators. Homogeneous coordinates in three dimensions will also allow us to do perspective projections so that we can view a three-dimensional object from any point in space.

    Image Representation

    The three-dimensional form of the point matrix in homogeneous coordinates is

    \[\mathrm{G}=\left\{\begin{array}{lllll}
    x_{1} & x_{2} & x_{3} & \ldots & x_{n} \\
    y_{1} & y_{2} & y_{3} & \ldots & y_{n} \\
    z_{1} & z_{2} & z_{3} & \ldots & z_{n} \\
    1 & 1 & 1 & \ldots & 1
    \end{array}\right\} \in \mathscr{R}^{4 \times n} \nonumber \]

    The line matrix \(H\) is exactly as before, pointing to pairs of columns in \(G\) to connect with lines. Any other grouping matrices for objects, etc., are also unchanged.

    Image manipulations are done by a 4×4 matrix \(A\). To ensure that the fourth coordinate remains a 1, the operator \(A\) must have the structure

    \[A=\left[\begin{array}{llll}
    a_{11} & a_{12} & a_{13} & a_{14} \\
    a_{21} & a_{22} & a_{23} & a_{24} \\
    a_{31} & a_{32} & a_{33} & a_{34} \\
    0 & 0 & 0 & 1
    \end{array}\right] \nonumber \]

    The new image has point matrix

    \[\mathrm{G}_{\text {new }}=A G \nonumber \]

    Exercise \(\PageIndex{1}\)

    If the coordinates of the \(i^{th}\) point in \(G\) are \((x_i,y_i,z_i,1)\), what are the coordinates of the \(i^{th}\) point in \(\mathrm{G}_{\text {new }}=A G\) when \(A\) is as given in Equation 2?

    Exercise \(\PageIndex{2}\)

    Write down the point matrix \(G\) for the unit cube (the cube with sides of length 1, with one corner at the origin and extending in the positive direction along each axis). Draw a sketch of the cube, numbering the vertices according to their order in your point matrix. Now write down the line matrix \(H\) to complete the representation of the cube.

    Left- and Right-Handed Coordinate Systems

    In this book we work exclusively with right-handed coordinate systems. However, it is worth pointing out that there are two ways to arrange the axes in three dimensions. Figure 1(a) shows the usual right-handed coordinates, and the left-handed variation is shown in Figure 1(b). All possible choices of labels \(x\), \(y\), and \(z\) for the three coordinate axes can be rotated to fit one of these two figures, but no rotation will go from one to the other.

    Screen Shot 2021-08-12 at 6.32.59 PM.png(a)
    Screen Shot 2021-08-12 at 6.33.11 PM.png(b)
    Figure \(\PageIndex{1}\): Three-Dimensional Coordinate Systems; (a) Right-handed, and (b) Left-handed

    Be careful to sketch a right-handed coordinate system when you are solving problems in this chapter. Some answers will not be the same for a left-handed system.

    Image Transformation

    Three-dimensional operations are a little more complicated than their two-dimensional counterparts. For scaling and translation we now have three independent directions, so we generalize the operators of Equation 10 from "Vector Graphics: Homogeneous Coordinates" as

    \[\mathrm{S}\left(s_{x}, s_{y}, s_{z}\right)=\left\{\begin{array}{llll}
    s_{x} & 0 & 0 & 0 \\
    0 & s_{y} & 0 & 0 \\
    0 & 0 & s_{z} & 0 \\
    0 & 0 & 0 & 1
    \end{array}\right\} \nonumber \]

    \[\mathrm{T}\left(t_{x}, t_{y}, t_{z}\right)=\left[\begin{array}{llll}
    1 & 0 & 0 & t_{x} \\
    0 & 1 & 0 & t_{y} \\
    0 & 0 & 1 & t_{z} \\
    0 & 0 & 0 & 1
    \end{array}\right] \text { . } \nonumber \]

    Exercise \(\PageIndex{3}\)

    Show that T\((−t_x,−t_y,−t_z)\) is the inverse of T\((t_x,t_y,t_z)\. T\(^{-1}\) undoes the work of \(T\).

    Rotation may be done about any arbitrary line in three dimensions. We will build up to the general case by first presenting the operators that rotate about the three coordinate axes. R\(_x(\theta)\) rotates by angle \(\theta\) about the x-axis, with positive \(\theta\) going from the y-axis to the z-axis, as shown in Figure 2. In a similar fashion, positive rotation about the y-axis using R\(_y(\theta)\) goes from \(z\) to \(x\), and positive rotation about the z-axis goes from \(x\) to \(y\), just as in two dimensions. We have the fundamental rotations

    \[\mathrm{R}_{x}(\theta)=\left\{\begin{array}{llll}
    1 & 0 & 0 & 0 \\
    0 & \cos \theta & -\sin \theta & 0 \\
    0 & \sin \theta & \cos \theta & 0 \\
    0 & 0 & 0 & 1
    \end{array}\right\} \nonumber \]

    \[\mathrm{R}_{y}(\theta)=\left\{\begin{array}{llll}
    \cos \theta & 0 & \sin \theta & 0 \\
    0 & 1 & 0 & 0 \\
    -\sin \theta & 0 & \cos \theta & 0 \\
    0 & 0 & 0 & 1
    \end{array}\right\} \nonumber \]

    \[\mathrm{R}_{z}(\theta)=\left\{\begin{array}{llll}
    \cos \theta & -\sin \theta & 0 & 0 \\
    \sin \theta & \cos \theta & 0 & 0 \\
    0 & 0 & 1 & 0 \\
    0 & 0 & 0 & 1
    \end{array}\right\} \nonumber \]

    A more general rotation about any line through the origin can be constructed by composition of the three fundamental rotations. Finally, by composing translation with the fundamental rotations, we can build an operator that rotates about any arbitrary line in space.

    Screen Shot 2021-08-12 at 6.39.13 PM.png
    Screen Shot 2021-08-12 at 6.39.25 PM.png
    Screen Shot 2021-08-12 at 6.39.35 PM.png
    Figure \(\PageIndex{2}\):Directions of Positive Rotation
    Example \(\PageIndex{1}\)

    To rotate by angle \(\psi\) about the line \(\mathscr{L}\), which lies in the \(x−y\) plane in Figure 3, we would

    1. rotate \(\mathscr{L}\) to the x-axis with R\(_z(−\theta)\);
    2. rotate by \(\psi\) about the x-axis with R\(_x(\psi)\); and
    3. rotate back to \(\mathscr{L}\) with R\(_z(\theta)\).

    The composite operation would be

    \[\mathrm{A}(\theta, \varphi)=\mathrm{R}_{z}(\theta) \mathrm{R}_{x}(\varphi) \mathrm{R}_{z}(-\theta) \nonumber \]

    Screen Shot 2021-08-12 at 6.44.31 PM.png
    Figure \(\PageIndex{3}\): Composition of Rotations

    Direction Cosines

    As discussed in the chapter on Linear Algebra, a vector vv may be specified by its coordinates \((x,y,z)\) or by its length and direction. The length of \(\nu\) is ||\(\nu\)||, and the direction can be specified in terms of the three direction cosines \((\cos{\theta_x}, \cos{\theta_y}, \cos{\theta_z})\). The angle \(\theta_x\) is measured between the vector \(\nu\) and the x-axis or, equivalently, between the vector \(\nu\) and the vector \(e_x=[100]^T\). We have

    \[\cos \theta_{x}=\frac{\left(\mathrm{v}, \mathrm{e}_{x}\right)}{\|\mathrm{v}\|\left\|\mathrm{e}_{x}\right\|}=\frac{x}{\|\mathrm{v}\|} \nonumber \]

    Likewise, \(\theta_y\) is measured between \(\nu\) and \(e_y=[010]^T\), and \(\theta_z\) is measured between \(\nu\) and \(e_z=[001]^\). Thus

    \[\cos \theta_{y}=\frac{y}{\|\mathrm{v}\|} \nonumber \]

    \[\cos \theta_{z}=\frac{z}{\|v\|} \nonumber \]

    The vector

    \[\mathrm{u}=\left\{\begin{array}{c}
    \cos \theta_{x} \\
    \cos \theta_{y} \\
    \cos \theta_{z}
    \end{array}\right\} \nonumber \]

    s a unit vector in the direction of \(\nu\), so we have

    \[\mathrm{v}=\|\mathrm{v}\| \mathrm{u}=\|\mathrm{v}\|\left\{\begin{array}{l}
    \cos \theta_{x} \\
    \cos \theta_{y} \\
    \cos \theta_{z}
    \end{array}\right\} \nonumber \]

    Exercise \(\PageIndex{4}\)

    Show that \(u\) is a unit vector (i.e. 1 u||=1u||=1).

    The direction cosines are useful for specifying a line in space. Instead of giving two points \(P_1\) and \(P_2\) on the line, we can give one point \(P_1\) plus the direction cosines of any vector that points along the line. One such vector is the vector from \(P_1\) to \(P_2\).

    Arc tangents

    Consider a vector \(\mathrm{v}=\left\{\begin{array}{l}
    x \\
    y
    \end{array}\right\}\) in two dimensions. We know that

    \[\tan \theta=\frac{y}{x} \nonumber \]

    for the angle \(\theta\) shown in Figure 4. If we know \(x\) and \(y\), we can find \(\theta\) using the arc tangent function

    \[\theta=\tan ^{-1}\left(\frac{y}{x}\right) \nonumber \]

    Screen Shot 2021-08-12 at 6.52.42 PM.png
    Figure \(\PageIndex{4}\): Tangent and Arc Tangent

    In MATLAB,

    theta = atan(y/x)

    Unfortunately, the arc tangent always gives answers between \(−\frac{\pi}{2}\) and \(\frac{\pi}{2}\) corresponding to points \(\nu\) in quadrants I and IV. The problem is that the ratio \(\frac{-y}{-x}\) is the same as the ratio −−−\(x\)A so quadrant III cannot be distinguished from quadrant I by the ratio \(\frac{y}{x}\) Likewise, quadrants II and IV are indistinguishable.

    The solution is the two-argument arc tangent function. In MATLAB,

    theta = atan2(y,x)

    will give the true angle \(\theta\) \(-\pi\) and \(\pi\) in any of the four quadrants.

    Example \(\PageIndex{2}\)

    Consider the direction vector \(\mathrm{u}=\left\{\begin{array}{l}
    \cos \theta_{x} \\
    \cos \theta_{y} \\
    \cos \theta_{z}
    \end{array}\right\}\) as shown in Figure 5. What is the angle \(\psi_y\) between the projection of \(u\) into the \(x−y\) plane and the y-axis? This is important because it is R\(_z(\psi_y)\)that will put \(u\) in the \(y−z\) plane, and we need to know the angle \(\psi_y\) in order to carry out this rotation. First note that it is not the same as \(\theta_y\). From the geometry of the figure, we can write

    \[\tan \varphi_{y}=\frac{\cos \theta_{x}}{\cos \theta_{y}} \nonumber \]

    This gives us a formula for \(\psi_y\) in terms of the direction cosines of \(u\). With the two-argument arc tangent, we can write

    \[\varphi_{y}=\tan ^{-1}\left(\cos \theta_{x}, \cos \theta_{y}\right) \nonumber \]

    Screen Shot 2021-08-12 at 6.58.42 PM.png
    Figure \(\PageIndex{5}\): Angles in Three Dimensions
    Exercise \(\PageIndex{5}\)
    1. Suppose point \(p'\) is in the \(y−z\) plane in three dimensions, \(p′=(0,y′,'',1)\). Find \(\theta\) so that R\(_x(\theta)\) will rotate \(p'\) to the positive z-axis. (Hint: Use the two-argument arc tangent. \(\theta\) will be a function of \(y'\) and \(z'\).)
    2. Let \(p\) be any point in three-dimensional space, \(p=(x,y,z,1)\). Find \(\psi\) so that R\(_z(\psi)\) rotates \(p\) into the \(y−z\) plane. (Hint: Sketch the situation in three-dimensions, then sketch a two-dimensional view looking down at the \(x−y\) plane from the positive z-axis. Compare with Example 2.) Your answers to parts (a) and (b) can be composed into an operator Z(p) that rotates a given point \(p\) to the positive z-axis, Z(p)=R\(_x(\theta)\)R\(_z(\psi)\).
    3. Let \(\mathscr{L}\) be a line in three-dimensional space specified by a point 1 = \((x,y,z,1)\) and the direction cosines \((\cos{\theta_x}, \cos{\theta_y}, \cos{\theta_z})\). Use the following procedure to derive a composite operator R\((\psi,\mathscr{L})\) that rotates by angle \(\psi\) about the line \(\mathscr{L}\):
    4. translate 1 to the origin;
    5. let u=\((\cos{\theta_x}, \cos{\theta_y}, \cos{\theta_z}, 1)\) and use Z(u) to align \(\mathscr{L}\) with the z-axis;
    6. rotate by \(\psi\) about the z-axis;
    7. undo step (ii); and
    8. undo step (i)

    This page titled 5.6: Three-Dimensional Homogeneous Coordinates is shared under a CC BY 3.0 license and was authored, remixed, and/or curated by Louis Scharf (OpenStax CNX) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?