<p>To solve the problem, we will flow three steps, first, calculate translation matrix, second, calculate rotation matrix, third, get transformation matrix.</p>

<p>Because translation is a <em>affine transformation</em>, we need to use a 4x4 matrix to represent translation. I find you use column vector post-multiply matrix. the result of the translation matrix is same as yours.</p>

<p>Translation matrix = <a href="https://i.sstatic.net/lk5Xn.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/lk5Xn.gif" alt="translation matrix"></a></p>

<p>Then, same as your idea, we use basis vectors(same as unit vectors of the coordinate axes) to calculate rotation matrix.</p>

<ol>
<li><p>basis <strong>z</strong> vector: we can get rotated basis <strong>z</strong> vector by using a vector from VRP to point A, and normalize it.</p>

<p><strong>z</strong> = <strong>b</strong>(VRP) - <strong>a</strong> = [5,-2,1] - [1,1,1] = [4,-3,0] ,then, normalize to [0.8,-0.6,0]</p></li>
<li><p>basis <strong>x</strong> vector: we know basis vector is a vector perpendicular to <strong>z-up</strong> plane, we get the <strong>x</strong> vector by cross product <strong>up</strong> and <strong>z</strong></p>

<p><strong>x</strong> = <strong>up</strong> x <strong>z</strong> = [1,1,1] x [0.8 ,-0.6 ,0] = [0.6, 0.8, 0]</p></li>
<li><p>basis <strong>y</strong> vector, <strong>y</strong> is prependicular to <strong>z-x</strong> plane.</p>

<p><strong>y</strong> = <strong>z</strong> x <strong>x</strong> = [0.8 ,-0.6, 0] x [0.6, 0.8, 0] = [0, 0, 1]</p>

<p>finally, the rotation matrix is:</p>

<p>Rotation Matrix = 
   <a href="https://i.sstatic.net/gmygD.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/gmygD.gif" alt="rotation matrix"></a></p>

<p>The 4x4 matrix is:</p>

<p>Transformation matrix = <a href="https://i.sstatic.net/8ue8L.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8ue8L.gif" alt="enter image description here"></a></p>

<p>The transformation matrix is a matrix from <em>Object Space</em> to <em>World Space</em>, we should invert this matrix to get <em>World Space</em> to <em>Camera Space</em> matrix.(Thanks for @JarkkoL correcting me).</p>

<p>Refer to <a href="https://tfetimes.com/wp-content/uploads/2015/04/F.Dunn-I.Parberry-3D-Math-Primer-for-Graphics-and-Game-Development.pdf" rel="nofollow noreferrer">3D Math Primer for Graphics and Game Developmen</a>.</p></li>
</ol>

<hr>

<p>Following your request for clarification: I just combine the translation matrix and the rotation matrix, actually, It's the result translation matrix(T) multiply rotation matrix(R). </p>

<p>The rotation is a 3x3 matrix, we can extend the matrix to a 4x4 matrix with adding a dimension, the 4x4 rotation matrix is:</p>

<p><a href="https://i.sstatic.net/QOZur.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QOZur.gif" alt="enter image description here"></a></p>

<p>And the translation matrix is:</p>

<p><a href="https://i.sstatic.net/l3FFz.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/l3FFz.gif" alt="enter image description here"></a></p>

<p>So, now we can calculate the transform matrix by translation matrix multiply(T) rotation matrix(R):</p>

<p>Cause the matrix multiply formula is too big for the 4x4 matrix, we just look at the 1st row, In the transform matrix(M), the M11 element equals to T11*R11+T12*R21+T13*R31+T14*R41, cause T12, T13, R41 is 0, so, the M11 equals to R11 right? And in the same way, M14 equals to T11*R14+T12*R24+T13*R34+T14*R44, only R44 equals to 1, so, the M14 equals to T14. so, I just simply put them together in my last answer. For the reason why we put the translation matrix on the left, you can check on the book that I gave you in my previous answer on page 91(translating first and then rotating).</p>

CC BY-SA 3.0
2017-03-02T02:59:47.487Z
You also need to invert the matrix in the end
JarkkoL
CC BY-SA 3.0
2017-03-02T04:06:18.087Z
@JarkkoL, I don't know why it needs to invert, can you explain?
Craig.Li
CC BY-SA 3.0
2017-03-02T04:13:51.003Z
OP is asking for view (world->camera) matrix, while you are building object->world matrix
JarkkoL
CC BY-SA 3.0
2017-03-28T11:18:59.830Z
Hi, I just made a new question: http://computergraphics.stackexchange.com/questions/4917/final-transformation-matrix-to-transform-world-coordinate-into-vrc The problem I am having with your final transformation matrix is that it is not following the steps my lecture slides are telling me. My lecture slides tell me to multiply the rotation matrix with the translation matrix to find the final transformation matrix.
S.A
CC BY-SA 3.0
2017-05-27T18:09:33.243Z
Why do you use the vector A(1, 1, 1) instead of the VUP vector(0,0,1) to work out the first row of the rotation matrix?
link
CC BY-SA 3.0
2017-05-27T19:51:36.523Z
isnt transformation matrix M = R.T , why are you saying to transform it again. I think the question just asked for the transformation matrix
fahad chowdhury
CC BY-SA 3.0
2017-05-28T08:07:57.280Z
@link in object(camera) coordinate space, the z-axis from the eye to a point where the eye looks at. yes, it's point A, `VRP - A` equals to the coordinate of z-axis of object space in world space.
Craig.Li
CC BY-SA 3.0
2017-05-28T08:22:11.757Z
@fahadchowdhury The question starter wants a matrix which can convert world coordinate to object coordinate, this matrix consist of two matrices, one is rotation matrix, another is translation matrix, only if the camera is looking at positive z-axis, the rotation matrix would be an identity matrix.
Craig.Li
CC BY-SA 3.0
2017-03-02T02:12:58.190Z
2017-08-05T21:28:41.683Z
2017-08-05T21:28:41.683Z
Craig.Li
<blockquote>
  <p>For a 3D scene in the world coordinates, its <em>View Reference Point</em> $\mathrm{VRP}$ is at $(5,-2,1)$, and a viewer is looking towards point $A=(1,1,1)$. Construct a transform matrix which will map world coordinate points to a right-handed $(UVN)$ viewing space, so that $\mathrm{VRP}$ is the origin, the line joining $\mathrm{VRP}$ to $A$ is the positive $N$ axis, and the view-up Vector is $(0,0,1)$.</p>
</blockquote>

<p>To my knowledge, the final answer should be a single transform matrix.
To calculate the final matrix, I first find the matrix which translates the coordinate system to the to the origin in homogeneous matrix form:</p>

<p>Translation matrix:</p>

<p>$$
T=
        \begin{bmatrix}
        1 &amp;0 &amp;0 &amp;-5 \\
        0 &amp;1 &amp;0&amp; 2 \\
        0 &amp;0 &amp;1 &amp;-1 \\
        0 &amp;0 &amp;0 &amp;1 \\
        \end{bmatrix}
$$</p>

<p>Using the unit vectors of the coordinate axes, the resulting rotation matrix is:</p>

<p>$$
R=
        \begin{bmatrix}
        -0.6 &amp;-0.8 &amp;0 &amp;0 \\
        0 &amp;0 &amp;0 &amp;1 \\
        -0.8 &amp;0.6 &amp;0 &amp;0 \\
        0 &amp;0 &amp;0 &amp;1 \\
        \end{bmatrix}
$$
Then the final matrix (the final answer for full marks) would be the rotation matrix multiplied by the translation matrix:</p>

<p>$$
M=
        \begin{bmatrix}
        -0.6 &amp;-0.8 &amp;0 &amp;1.4 \\
        0 &amp;0 &amp;0 &amp;1 \\
        -0.8 &amp;0.6 &amp;0 &amp;5.2 \\
        0 &amp;0 &amp;0 &amp;1 \\
        \end{bmatrix}
$$
Is my method and final answer correct?</p>

<hr>

<p>Following the answer to this question, I have calculated the translation matrix:</p>

<p>$$
T=
\begin{pmatrix}
1 &amp; 0 &amp; 0 &amp; -5 \\
0 &amp; 1 &amp; 0 &amp; 2 \\
0 &amp; 0 &amp; 1 &amp; -1 \\
0 &amp; 0 &amp; 0 &amp; 1 \\
\end{pmatrix}
$$</p>

<p>I have calculated the rotation matrix:</p>

<p>$$
R=
\begin{pmatrix}
-0.6 &amp; -0.8 &amp; 0 &amp; 0 \\
0 &amp; 0 &amp; 1 &amp; 0 \\
-0.8 &amp; 0.6 &amp; 0 &amp; 0 \\
0 &amp; 0 &amp; 0 &amp; 1 \\
\end{pmatrix}
$$</p>

<p>But what would the final transformation matrix $M$ be? My lecture slides tell me it would be rotation matrix multiplied by translation matrix, with the last column multiplied by $-1$ except for the $1$. This would equal:</p>

<p>$$
M = R \times T = 
\begin{pmatrix}
-0.6 &amp; -0.8 &amp; 0 &amp; -1.4 \\
0 &amp; 0 &amp; 1 &amp; 1 \\
-0.8 &amp; 0.6 &amp; 0 &amp; -5.2 \\
0 &amp; 0 &amp; 0 &amp; 1 \\
\end{pmatrix}
$$</p>

<p>But the answer here just adds them together somehow. Which one is correct?</p>

CC BY-SA 3.0
2017-02-19T18:32:26.620Z
Have you made any headway on this by yourself, or any ideas?
PeteUK
CC BY-SA 3.0
2017-02-19T18:56:18.617Z
Its pretty common to feel this way in higher education, i know i did. In reality its a issue with yourself. Sure the educators aren't stellar but that is simply because your coming nearer the boundary of know how and your ability to work in several different levels of abstractions and several levels of uncertainty comes to play. (something that is very poison to certain mind frames. You'll get over this in about 5 years). The question itself is quite good. If you ever do any robotics, 3D graphics or engineering you'll be glad. It measures wether you undertood the 3 first thing you were taught.
joojaa
CC BY-SA 3.0
2017-02-26T22:37:10.360Z
Hello PeteUK. Yes, I have edited the question and added my progress so far.
S.A
CC BY-SA 3.0
2017-03-02T00:05:51.620Z
I'm doubting that the third column should be all zeros. It's late here and will try to look at it more tomorrow, but think that column should be the basis vector for your $N$.
PeteUK
CC BY-SA 3.0
2017-03-02T00:09:34.523Z
I'm also doubting that $1$ in row 2, column 4 of your rotation matrix. That's the translation part of the matrix.
PeteUK
<3d><matrix><linear-algebra>
Building view transform matrices
S.A
# Building view transform matrices

(Asked by: username_0 on 2017-02-19)

> For a 3D scene in the world coordinates, its *View Reference Point* $\mathrm{VRP}$ is at $(5,-2,1)$, and a viewer is looking towards point $A=(1,1,1)$. Construct a transform matrix which will map world coordinate points to a right-handed $(UVN)$ viewing space, so that $\mathrm{VRP}$ is the origin, the line joining $\mathrm{VRP}$ to $A$ is the positive $N$ axis, and the view-up Vector is $(0,0,1)$.

To my knowledge, the final answer should be a single transform matrix.
To calculate the final matrix, I first find the matrix which translates the coordinate system to the to the origin in homogeneous matrix form:

Translation matrix:

$$
T=
\begin{bmatrix}
1 &0 &0 &-5 \\
0 &1 &0& 2 \\
0 &0 &1 &-1 \\
0 &0 &0 &1 \\
\end{bmatrix}
$$

Using the unit vectors of the coordinate axes, the resulting rotation matrix is:

$$
R=
\begin{bmatrix}
-0.6 &-0.8 &0 &0 \\
0 &0 &0 &1 \\
-0.8 &0.6 &0 &0 \\
0 &0 &0 &1 \\
\end{bmatrix}
$$
Then the final matrix (the final answer for full marks) would be the rotation matrix multiplied by the translation matrix:

$$
M=
\begin{bmatrix}
-0.6 &-0.8 &0 &1.4 \\
0 &0 &0 &1 \\
-0.8 &0.6 &0 &5.2 \\
0 &0 &0 &1 \\
\end{bmatrix}
$$
Is my method and final answer correct?

---

Following the answer to this question, I have calculated the translation matrix:

$$
T=
\begin{pmatrix}
1 & 0 & 0 & -5 \\
0 & 1 & 0 & 2 \\
0 & 0 & 1 & -1 \\
0 & 0 & 0 & 1 \\
\end{pmatrix}
$$

I have calculated the rotation matrix:

$$
R=
\begin{pmatrix}
-0.6 & -0.8 & 0 & 0 \\
0 & 0 & 1 & 0 \\
-0.8 & 0.6 & 0 & 0 \\
0 & 0 & 0 & 1 \\
\end{pmatrix}
$$

But what would the final transformation matrix $M$ be? My lecture slides tell me it would be rotation matrix multiplied by translation matrix, with the last column multiplied by $-1$ except for the $1$. This would equal:

$$
M = R \times T =
\begin{pmatrix}
-0.6 & -0.8 & 0 & -1.4 \\
0 & 0 & 1 & 1 \\
-0.8 & 0.6 & 0 & -5.2 \\
0 & 0 & 0 & 1 \\
\end{pmatrix}
$$

But the answer here just adds them together somehow. Which one is correct?

**Tags:** 3d, matrix, linear-algebra

> **Comments:**
> **username_1**: Have you made any headway on this by yourself, or any ideas?  
> **username_2**: Its pretty common to feel this way in higher education, i know i did. In reality its a issue with yourself. Sure the educators aren't stellar but that is simply because your coming nearer the boundary of know how and your ability to work in several different levels of abstractions and several levels of uncertainty comes to play. (something that is very poison to certain mind frames. You'll get over this in about 5 years). The question itself is quite good. If you ever do any robotics, 3D graphics or engineering you'll be glad. It measures wether you undertood the 3 first thing you were taught.  
> **username_0**: Hello username_1. Yes, I have edited the question and added my progress so far.  
> **username_1**: I'm doubting that the third column should be all zeros. It's late here and will try to look at it more tomorrow, but think that column should be the basis vector for your $N$.  
> **username_1**: I'm also doubting that $1$ in row 2, column 4 of your rotation matrix. That's the translation part of the matrix.  

---

## 1 answers

### Answer by username_3 on 2017-03-02. Score: 1 | Accepted answer

To solve the problem, we will flow three steps, first, calculate translation matrix, second, calculate rotation matrix, third, get transformation matrix.

Because translation is a *affine transformation*, we need to use a 4x4 matrix to represent translation. I find you use column vector post-multiply matrix. the result of the translation matrix is same as yours.

Translation matrix = [![translation matrix](https://i.sstatic.net/lk5Xn.gif)](https://i.sstatic.net/lk5Xn.gif)

Then, same as your idea, we use basis vectors(same as unit vectors of the coordinate axes) to calculate rotation matrix.

1. basis **z** vector: we can get rotated basis **z** vector by using a vector from VRP to point A, and normalize it.

   **z** = **b**(VRP) - **a** = [5,-2,1] - [1,1,1] = [4,-3,0] ,then, normalize to [0.8,-0.6,0]
2. basis **x** vector: we know basis vector is a vector perpendicular to **z-up** plane, we get the **x** vector by cross product **up** and **z**

   **x** = **up** x **z** = [1,1,1] x [0.8 ,-0.6 ,0] = [0.6, 0.8, 0]
3. basis **y** vector, **y** is prependicular to **z-x** plane.

   **y** = **z** x **x** = [0.8 ,-0.6, 0] x [0.6, 0.8, 0] = [0, 0, 1]

   finally, the rotation matrix is:

   Rotation Matrix =
   [![rotation matrix](https://i.sstatic.net/gmygD.gif)](https://i.sstatic.net/gmygD.gif)

   The 4x4 matrix is:

   Transformation matrix = [![enter image description here](https://i.sstatic.net/8ue8L.gif)](https://i.sstatic.net/8ue8L.gif)

   The transformation matrix is a matrix from *Object Space* to *World Space*, we should invert this matrix to get *World Space* to *Camera Space* matrix.(Thanks for @username_4 correcting me).

   Refer to [3D Math Primer for Graphics and Game Developmen](https://tfetimes.com/wp-content/uploads/2015/04/F.Dunn-I.Parberry-3D-Math-Primer-for-Graphics-and-Game-Development.pdf).

---

Following your request for clarification: I just combine the translation matrix and the rotation matrix, actually, It's the result translation matrix(T) multiply rotation matrix(R).

The rotation is a 3x3 matrix, we can extend the matrix to a 4x4 matrix with adding a dimension, the 4x4 rotation matrix is:

[![enter image description here](https://i.sstatic.net/QOZur.gif)](https://i.sstatic.net/QOZur.gif)

And the translation matrix is:

[![enter image description here](https://i.sstatic.net/l3FFz.gif)](https://i.sstatic.net/l3FFz.gif)

So, now we can calculate the transform matrix by translation matrix multiply(T) rotation matrix(R):

Cause the matrix multiply formula is too big for the 4x4 matrix, we just look at the 1st row, In the transform matrix(M), the M11 element equals to T11\*R11+T12\*R21+T13\*R31+T14\*R41, cause T12, T13, R41 is 0, so, the M11 equals to R11 right? And in the same way, M14 equals to T11\*R14+T12\*R24+T13\*R34+T14\*R44, only R44 equals to 1, so, the M14 equals to T14. so, I just simply put them together in my last answer. For the reason why we put the translation matrix on the left, you can check on the book that I gave you in my previous answer on page 91(translating first and then rotating).

> **Comments:**
> **username_4**: You also need to invert the matrix in the end  
> **username_3**: @username_4, I don't know why it needs to invert, can you explain?  
> **username_4**: OP is asking for view (world->camera) matrix, while you are building object->world matrix  
> **username_0**: Hi, I just made a new question: http://computergraphics.stackexchange.com/questions/4917/final-transformation-matrix-to-transform-world-coordinate-into-vrc The problem I am having with your final transformation matrix is that it is not following the steps my lecture slides are telling me. My lecture slides tell me to multiply the rotation matrix with the translation matrix to find the final transformation matrix.  
> **username_5**: Why do you use the vector A(1, 1, 1) instead of the VUP vector(0,0,1) to work out the first row of the rotation matrix?  
> **username_6**: isnt transformation matrix M = R.T , why are you saying to transform it again. I think the question just asked for the transformation matrix  
> **username_3**: @username_5 in object(camera) coordinate space, the z-axis from the eye to a point where the eye looks at. yes, it's point A, `VRP - A` equals to the coordinate of z-axis of object space in world space.  
> **username_3**: @username_6 The question starter wants a matrix which can convert world coordinate to object coordinate, this matrix consist of two matrices, one is rotation matrix, another is translation matrix, only if the camera is looking at positive z-axis, the rotation matrix would be an identity matrix.  

---

