Main / P2-1-key - CS559 2007
For questions 1-5, we consider a 2D graphics system that works like OpenGL. It uses 3x3 homogeneous matrices and a post-multiply convention. It has a matrix stack, and supports the following commands:
PUSH – makes a copy of the top element of the matrix stack
POP – removes the top element of the matrix stack
TRANS(x,y) - translates by x,y
ROT(t) - rotates counter clockwise by t degrees
SCALE(x,y) - scales by x,y
SQUARE - draws a unit square between (0,0) and (1,1)
Here is an example program and its output:
If we had left out the PushMatrix/PopMatrix commands in the example program, the last square would have appeared in a different place. Where would it have been?
(give the positions of its 4 corners)
(see the blue square in the picture)
Write a program that creates the following picture, without using PushMatrix or PopMatrix.
When dealing with images, we often like to measure the screen in pixels (with 0,0 being the upper left, and width-1, height-1 being the lower right). When dealing with geometry, we often like to have “Normalized Device Coorindates” where the center of the window is 0,0, and 1,1 is the upper right corner (and -1,-1 is the lower left).
Using the 2D transform commands above, write a program that creates the transformation from normalized device coordinates to pixel coordinates for a screen of size 640x280 on the top of the stack. (your answer should be a sequence of commands)
Note: it might be better to use 319.5 and 239.5 instead of 320 and 240, but we accepted both answers in parts A and B.
translate 320, 240 scale 320, -240
scale 320, -240 translate 1, -1
If the screen is 640 by 480 pixels, what would the matrix be? (your answer should be a 3x3 matrix).
Hint: it is probably easier to figure out the answer directly than to multiply out the matrices.
320 0 320 0 -240 240 0 0 1
Give the 3x3 matrix that would transform the unit square (with one of its corners at 0,0, and the opposite corner at 1,1) such that: The corner that was at the origin goes to 1,2. The corner that was at 0,1 goes to 3,4. The corner that was at 1,1 goes to 5,6.
to figure this out, we can easily see what the right column is (since its where things will go with the 0,0 vector)
to get the middle column, we need to subtract off the translation, and then the destination of the Y axis becomes to middle column.
filling in these two columns, we get:
x 2 1 y 2 2 0 0 1
and we know that this matrix, times the vector [1 1 1] must give [5 6 1].so:
x + 2 + 1 = 5 y + 2 + 2 = 6 1 = 1
so, the matrix is:
2 2 1 2 2 2 0 0 1
Give the program that creates a rotation of 45 degrees around the point 3,4.
translate 3,4 rotate 45 translate -3,-4
Consider the desk lamp in this picture:
The lengths of the arms are 5, and the tip of the bulb is 1 unit from the joint. x,y, and theta 0-3 are all parameters to position the lamp. Write an expression that computes the position of the bulb (point B) in the coordinate system of the desk. Your expression should be the product of a set of Matrices T(x,y,z) (that translates by x,y,z) and Rx(theta) that rotates theta degrees around the x axis (or Ry or Rz). These matrices are post-multiply and the rotations are measured counter clockwise in right-handed coordinate systems.
Consider a 3D transformation M (a 4x4 homogeneous coordinate matrix) that is created by composing a rotation and a uniform scale. M maps the unit X vector to (0,1,1), and the unit Y vector to (0,1,-1).
Where does M map the unit Z vector to?
The direction of the unit Z vector will be in the direction of the cross product of where the X and Y vectors go. (since neither rotation nor uniform scale distorts the angles between the axes).
X cross Y = -2,0,0
However, the cross product doesn't necessarily do the right thing with the scale. All three vectors need to have the same length (and X and Y have length sqrt(2)) so the Z vector needs to be:
-sqrt(2), 0, 0
What is the amount of the scale used to make M?