Week 5 Solution
Question 1
Use the right hand rule to figure this out. Curl your fingers from the x axis to the y axis. You should find z is facing :
(a) out of the page
(b) into the page
(c) into the page
(d) out of the page
Question 2
(a) 
(b)
; 
(c) 
(d)
![\left[\begin{array}{c} -1\times 0 - 0\times 2\\
0\times 4 - (-1)\times 0\\
-1\times 2 - (-1)\times 4\end{array}\right] = \left[\begin{array}{c} 0\\
0\\
2\end{array}\right]
\left[\begin{array}{c} -1\times 0 - 0\times 2\\
0\times 4 - (-1)\times 0\\
-1\times 2 - (-1)\times 4\end{array}\right] = \left[\begin{array}{c} 0\\
0\\
2\end{array}\right]](/~cs3421/latexrender/pictures/de55dc83fa974a3875aed6d2b474a51d.gif)
Question 3
(a) First we have to scale the cubes so that they are the right
size. They start off with size 2 and end up with size 0.7, so we have
to scale by a factor of 0.35, equally in all dimensions. We then have
to translate by (0, 4, 2). Hence we need to find:
=
(b) Orthogonal? Yes … dot product of any pair is equal to zero. Orthonormal? No … the lengths are not equal to 1. Remember, the local to world transformation consists of the basis as the first three columns and the offset in the fourth column (proved in lectures). Doing so yields the same answer as part (a) … which shouldn’t be surprising … they are two different ways of doing the same thing!
Question 3
Consider the following sequence of matrix operations in OpenGL. Show what happens to the modelview matrix stack after each operation:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(3,3,3);
glBegin(GL_POINTS); <-- A
glVertex3f(1,2,1);
glEnd();
glRotatef(90, 0, 1, 0);
glBegin(GL_POINTS);
glVertex3f(2,1,3); <-- B
glEnd();
glPushMatrix();
glTranslatef(1,0,0);
glMultMatrix(1,0,0,0,0,2,0,0,0,0,1,0,0,0,0,1);
glPopMatrix();
glBegin(GL_POINTS);
glVertex3f(0,2,0); <-- C
glEnd();
glTranslatef(0,1,0);
glBegin(GL_POINTS);
glVertex3f(1,0,0); <-- D
glEnd();
Remember that in OpenGL, Scale, rotate, etc work by popping the current matrix (C) off the stack, taking the transform we want to apply (T) post-multiplying (i.e. calculate C.T and NOT T.C) and pushing it back on the stack. pushMatrix() pushes a copy of the current top-of-stack onto the stack.
I’ll put the theoretical values here, and you can expand with actual numbers (Sc = scale, Tr = translate, Ra = rotate about axis a, BOS = bottom of stack).
After glLoadIdentity(): identity matrix.
After glScalef(3,3,3):
Sc(3,3,3) <-BOS
At this point A is transformed; the top of the stack is scale(3,3,3); so the point (1,2,1) is transformed to (3,6,3).
So A ends up at (3,6,3) in world coordinates. After glRotatef(90, 0, 1, 0):
Sc(3,3,3).Ry(90) <-BOS
You can work this matrix out. It is:
![\left[\begin{array}{cccc}
0& 0& 3 &0\\
0& 3& 0& 0\\
-3& 0& 0& 0\\
0& 0& 0& 1\end{array}\right]
\left[\begin{array}{cccc}
0& 0& 3 &0\\
0& 3& 0& 0\\
-3& 0& 0& 0\\
0& 0& 0& 1\end{array}\right]](/~cs3421/latexrender/pictures/5f7ea432aadb33eee8bd6b7113db0ec4.gif)
At this point B (2,1,3) is transformed. Applying the above matrix to B gives: (9,3,-6).
After glPushMatrix(): matrix gets copied.
Sc(3,3,3).Ry(90)
Sc(3,3,3).Ry(90) <-BOS
After glTranslatef(1,0,0):
Sc(3,3,3).R_y(90).Tr(1,0,0) Sc(3,3,3).R_y(90) <-BOS
After glMultMatrix(1,0,0,0,0,2,0,0,0,0,1,0,0,0,0,1) (which is really just Sc(1,2,1))
Sc(3,3,3).R_y(90).Tr(1,0,0).Sc(1,2,1)
Sc(3,3,3).R_y(90) <-BOS
After glPopMatrix():
Sc(3,3,3).R_y(90) <-BOS
At this point we operate on the point C=(0,2,0). This is the same as the original matrix that was applied to point B. Hence the results are: (0,6,0). After glTranslatef(0,1,0):
Sc(3,3,3).Ry(90).Tr(0,1,0) <-BOS
At this point we tranform point D. The bottom of the stack is now:
![\left[\begin{array}{cccc}
0& 0& 3 &0 \\
0& 3& 0& 0 \\
-3& 0& 0& 0 \\
0& 0& 0& 1 \end{array}\right]
\left[\begin{array}{cccc}
1& 0& 0 &0 \\
0& 1& 0& 1 \\
0& 0& 1& 0 \\
0& 0& 0& 1 \end{array}\right]=
\left[\begin{array}{cccc}
0& 0& 3 &0 \\
0& 3& 0& 3 \\
-3& 0& 0& 0 \\
0& 0& 0& 1 \end{array}\right]
\left[\begin{array}{cccc}
0& 0& 3 &0 \\
0& 3& 0& 0 \\
-3& 0& 0& 0 \\
0& 0& 0& 1 \end{array}\right]
\left[\begin{array}{cccc}
1& 0& 0 &0 \\
0& 1& 0& 1 \\
0& 0& 1& 0 \\
0& 0& 0& 1 \end{array}\right]=
\left[\begin{array}{cccc}
0& 0& 3 &0 \\
0& 3& 0& 3 \\
-3& 0& 0& 0 \\
0& 0& 0& 1 \end{array}\right]](/~cs3421/latexrender/pictures/e44b196408f770f62c3c0ed2848c3a00.gif)
Applying this matrix to the point D gives us the point (0,3,-3);