Project2 Phase3 solution

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:

Draw Square

PushMatrix

Scale(2,2)

Translate(2,1)

Scale(-1,1)

Draw Square

PopMatrix

Rotate 90

Translate -3,0

Draw Square

http://www.cs.wisc.edu/graphics/Courses/559-f2007/wiki/pub/project2/simple1-ans.png

Question 1:

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)
(4,-2), (6,-2), (6,-4), (4,-4)
Hint: the reflection changes the direction of rotation.

Question 2:

Write a program that creates the following picture, without using PushMatrix or PopMatrix.

Note: there are many possible answers, this is just one:

 

translate(5,0);

draw Square();

translate(-2,0);

scale(2,2);

draw Square();

scale(1.5,1.5);

translate(-1,0);

draw Square();

http://www.cs.wisc.edu/graphics/Courses/559-f2007/wiki/pub/project2/simple2.png

Question 3:

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).

Question 3A:

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

or

scale 320, -240

translate 1, -1

Question 3B:

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

Question 4:

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

Question 5:

Give the program that creates a rotation of 45 degrees around the point 3,4.

translate 3,4

rotate 45

translate -3,-4

 

Question 6:

Consider the desk lamp in this picture:

http://www.cs.wisc.edu/graphics/Courses/559-f2007/wiki/pub/project2/P2-1-6.png

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.

http://www.cs.wisc.edu/graphics/Courses/559-f2007/wiki/pub/project2/lamp-ans.png

 

 

Question 7

http://www.cs.wisc.edu/graphics/Courses/559-f2007/wiki/pub/project2/P2-3-5.png

Question 8

Basis matrix of Catmull-Rom:

0

1

0

0

-1/2

0

1/2

0

1

-5/2

2

-1/2

-1/2

3/2

-3/2

1/2


a0 = (0, 2)
 
a1 = (2, 1)
a2 = (6, -3/2)
a3 = (-4, 1/2)

Where is the point at t=1/2?
f(1/2) = (2, 35/16)
(there's no real shortcut here, compute u B p with u = [1 1/2 1/4 1/8])
 

What direction is it facing? 
f'(1/2) = (5, -1/8) - if you normalized this vector, that's an even better answer, but messier
(the easiest way to do this is to notice that only the u vector depends on the parameter, so u' = [ 0 1 2u 3u^2 ] = [ 0 1 1 3/4], and compute u' B p)

 What is the magnitude of its velocity?
sqrt(5*5 + (-1/8)*(-1/8)) = sqrt(1601)/8

Question 9

f'(0) = 4(P1 - P0) = (0, 8)
f'(1) = 4(P4 - P3) = (0, -8)

(4, 0), (4, -8/3), (0, -8/3), (0, 0)

Question 10

DeCastlejau algorithm:
(0,0), (0,2), (2,4), (4,2), (4,0)
-> (0, 1), (1, 3), (3, 3), (4, 1)
-> (1/2, 2), (2, 3), (7/2, 2)
 
-> (5/4, 5/2), (11/4, 5/2)
->(2, 5/2)

Segment 1: (0, 0), (0, 1), (1/2, 2), (5/4, 5/2), (2, 5/2)
Segment 2: (2, 5/2), (11/4, 5/2), (7/2, 2), (4, 1), (4, 0)