# MATH 3600 - HW17

Date: ________________

## Perspective and Homogeneous Coordinates

We start with the standard $x, y, z$ vector coordinates and add a fourth coordinate, $w$, with a value of 1.  The term "homogeneous coordinates" means that two of these 4-dimensional vectors are equivalent if one is a multiple of the other.  In other words, given a set of equivalent vectors $\left[x, y, z, w\right]^T$, we can choose the representative of the set to be the vector with $w=1$ except for the case where $w=0$. We will find that we can treat those vectors as points at infinity.

In this coordinate system we can introduce 4-x-4 matrices which accomplish all the standard 3-dimensional Eulidean transformations and leave us with coordinates that can be easily rescaled to provide illustrations with perspective.

Translation:  The following three matrices translate the $\left[x,y,z,1\right]^T$ vector $a$ units in the $x$ direction, or $b$ units in the $y$ direction, or $c$ units in the $z$ direction, respectively

${{\bf{T}}_x} = \left[ {\begin{array}{*{20}{c}} 1&0&0&a\\ 0&1&0&0\\ 0&0&1&0\\ 0&0&0&1 \end{array}} \right],\quad {{\bf{T}}_y} = \left[ {\begin{array}{*{20}{c}} 1&0&0&0\\ 0&1&0&b\\ 0&0&1&0\\ 0&0&0&1 \end{array}} \right],\quad {{\bf{T}}_z} = \left[ {\begin{array}{*{20}{c}} 1&0&0&0\\ 0&1&0&0\\ 0&0&1&c\\ 0&0&0&1 \end{array}} \right]$

# Tetrahedron # Build the 4 homogeneous vectors, one for each corner # Step one # Write the usual coordinates for each corner corners = [[0,0,0],[1,0,0],[0,1,0],[0,0,1]] # Step two # Add 1 to each of the corner vectors for v in corners: v.append(1) print corners # Step 3 # Build the 4 x n matrix, where n is the number of corners Tetra = matrix(RDF,corners) Tetra = Tetra.transpose() print '\nTetra' print Tetra # Step 4 # Make a list of the edges Tetra_Edges = [(0,1),(0,2),(0,3),(1,2),(1,3),(2,3)] print '\nTetra Edges' print Tetra_Edges
Ident = matrix(RDF,[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]) print 'Identity' print Ident Tx2 = copy(Ident) Tx2[0,3] = 2 print '\nTx2' print Tx2 print '\nTetra translated by 2 along x' print Tx2*Tetra

Rotation:  The following three matrices rotate the $\left[x,y,z,1\right]^T$ vector $a$ radians around the $z$ axis, or $b$ radianss around the $y$ axis, or $c$ radians around the $x$ axis, respectively.

${{\bf{R}}_z} = \left[ {\begin{array}{*{20}{c}} {\cos (a)}&{ - \sin (a)}&0&0\\ {\sin (a)}&{\cos (a)}&0&0\\ 0&0&1&0\\ 0&0&0&1 \end{array}} \right],\quad {{\bf{R}}_y} = \left[ {\begin{array}{*{20}{c}} {\cos (b)}&0&{ - \sin (b)}&0\\ 0&1&0&0\\ {\sin (b)}&0&{\cos (b)}&0\\ 0&0&0&1 \end{array}} \right],\quad {{\bf{R}}_x} = \left[ {\begin{array}{*{20}{c}} 1&0&0&0\\ 0&{\cos (c)}&{ - \sin (c)}&0\\ 0&{\sin (c)}&{\cos (c)}&0\\ 0&0&0&1 \end{array}} \right]$

theta = 2*pi/6.0 ct = cos(theta) st = sin(theta) Rz = matrix(RDF,[[ct,-st,0,0,],[st,ct,0,0],[0,0,1,0],[0,0,0,1]]) print 'Rz' print Rz print '\nRotate Tetra around the z axis' print Rz*Tetra Ry = matrix(RDF,[[ct,0,-st,0,],[0,1,0,0],[st,0,ct,0],[0,0,0,1]]) print '\nRy' print Ry print '\nRotate Tetra around the y axis' print Ry*Tetra Rx = matrix(RDF,[[1,0,0,0],[0,ct,-st,0,],[0,st,ct,0],[0,0,0,1]]) print'\nRx' print Rx print '\nRotate Tetra around the x axis' print Rx*Tetra
# Rotate it by pi/3 about the y axiz, lower it by 0.5 units, and move it back 1 unit Tetra1 = Ry*Tetra T = matrix(RDF,[[1,0,0,0],[0,1,0,-0.5],[0,0,1,1],[0,0,0,1]]) print T Tetra1 = T*Tetra1 print Tetra1
frame_corners = [(-1,-1),(1,-1),(1,1),(-1,1)] frame_lines = [(-1,-1),(1,-1),(1,1),(-1,1),(-1,-1)] print frame_corners print frame_lines
print type(Tetra) Tetra
g = Graphics() g += point(frame_corners) g += line(frame_lines) corners = [(Tetra[0,k],Tetra[1,k]) for k in range(Tetra.ncols())] g += point(corners) for s,t in Tetra_Edges: g += line([corners[s],corners[t]]) show(g,aspect_ratio=1)
g = Graphics() g += point(frame_corners) g += line(frame_lines) corners = [(Tetra1[0,k],Tetra1[1,k]) for k in range(Tetra1.ncols())] g += point(corners) for s,t in Tetra_Edges: g += line([corners[s],corners[t]]) show(g,aspect_ratio=1)
g = Graphics() g += point(frame_corners) g += line(frame_lines) corners = [(Tetra1[0,k]/Tetra1[2,k],Tetra1[1,k]/Tetra1[2,k]) for k in range(Tetra1.ncols())] print corners g += point(corners) for s,t in Tetra_Edges: g += line([corners[s],corners[t]]) show(g,aspect_ratio=1)

Exercise 1:  Construct and display a pyramid.  The base should be a square 2 units on a side.  The peak should be in the center and 1 unit higher than the base.  Build the basic pyramid so that the 4 corners of the base are: (-1,0,-1), (1,0,-1), (1,0,1), (-1,0,1). Display the construction with no perspective.

Exercise 2:  Construct and display a box.  The box should have a width and depth of 1 unit, and it should have a height of 2 units.  The 8 corners of the box are: (-1/2,0,-1/2), (1/2,0,-1/2), (1/2,0,1/2), (-1/2,0,1), (-1/2,2,-1/2), (1/2,2,-1/2), (1/2,2,1/2), (-1/2,2,1/2). Display the box with no perspective.

Exercise 3:  Translate the pyramid up 2 units (y+2) so that it sits on top of the box.  Then rotate the combined construction by $\pi/6$ around the y axis. Next translate the combined construction back by 3 units (z+3) and down by 1 unit (y-1).  Finally display it with perspective scaling.