Angle

cos

sin

0

1

0

30

√3/2

1/2

45

√2/2

√2/2

60

1/2

√3/2

90

0

1

 

 

 

1)      (2 points) We have a tiny 8x4 raster screen.  What size frame buffer in bytes is required to store pixel the colors for an RGB system? 8*4*24/8=96 bytes

 

2)      (2 points) Draw the resulting diagram when I make the following GL calls

 

glBegin(GL_LINES);                                            V1

glVertex3fv(vertex1);                                        *

glVertex3fv(vertex2);                            V2*            *V3

glVertex3fv(vertex3);                               V4*   * V5

glVertex3fv(vertex4);

glVertex3fv(vertex5);

       glEnd();

4)  Given the following polyline, shade only the interior regions.   Show all work.

a)      (3 points)Use the odd-even rule.

Crosses even edges exterior

Cross odd edges interior

 

b) (3 points)Use the non-zero winding rule        R to L add one

L to R subtract one

If nonzero, interior                                                       

 

 

 

 

 

 

Line algorithms and anti-aliasing

6)      (5 points)Consider the line from (7 , 2) to (12 , 4).  Use Bresenham’s algorithm to determine the pixels.  Plot on the Raster Screen.  Show all work.

                           7           2       

K         Pk         Xk+1       Yk+1   

  0         -1          8             2

  1         3          9             3

  2         -3           10         3

  1         1             11       4

  4        -5             12      4

 

 

ΔX=5               2ΔX=10          

ΔY=2               2ΔY=4

M < 1   P0 = 2ΔY – ΔX = 4-5=-1

If Pk < 0, plot Xk +1, Yk: Pk+1  = Pk+2ΔY    Pk+1  = Pk+4

Else  plot Xk +1, Yk+1: Pk+1  = Pk+2ΔY-2ΔX

  Pk+1  = Pk+4-10= Pk-2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

X

X

 

 

 

 

 

 

 

 

 

 

 

X

X

 

 

 

 

 

 

 

 

 

 

 

X

X

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

7)      (5 points) Consider the line from (0 , 3) to (2 , 7).  Use Bresenham’s algorithm to determine the pixels.  Plot on the Raster Screen.  Show all work.

ΔX=2               2ΔX=4             ΔY=4               2ΔY=8

M < 1   P0 = 2ΔX – ΔY = 8-8=0

If Pk < 0, plot Xk, Yk+1 Pk+1  = Pk+2ΔX  Pk+1  = Pk+4

Else  plot Xk +1, Yk+1 Pk+1  = Pk+2ΔX-2ΔY Pk+1  = Pk+4-8= Pk-4

 

 

 

                           0           3       

K         Pk         Xk+1       Yk+1   

  0         0           1             4

  1         -4          1            5

  2         0           2            6

  3       -4            2            7

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

8)      (5 points)Consider the line from (0,0) to (1,3).  Antialias the line using an unweighted 3x3 grid.  Plot the microgrid  and indicate the pixel intensities.

 

M=3/1  X= Xk+1/M = Xk+1/3

Need three values for each pixel in y

There are 4 pixels in y, need 12 values.

 

     0          0

     X         Y     Plot

     1/3        1   0,1

     2/3        2    1,2

1                    3    1,3

1-1/3    4    1,4

1-2/3    5    2,5

2                    6    2,6

2-1/3    7    2,7

2-2/3    8    3,8

3           9   3,9   -2 if stop here

3-1/3    10  3,10

3-2/3    11  4,11

 

 

 

 

 

 


-

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

9)       

 


 


10)   (5 points)Consider the line from (0,0) to (3,2).  Antialias the line using an weighted 3x3 grid.  Plot the microgrid  and indicate the pixel intensities.

11)  –4 if unweighted

M=2/3  Y= Yk+M = Yk+2/3

Need three values for each pixel in y

There are 4 pixels in x, need 12 values.

 

     0          0

     X         Y    Plot

     1     2/3       1,1

2 1-1/3       2,1

3      2        3,2

4    2-2/3    4,3

5    3-1/3    5,3

6       4       6,4

7     4-2/3   7,5

8     5-1/3   8,5

9      6        9,6

10     6-2/3 10,7

11   7-1/3   11,7

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

X

X

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

X

X

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

X

X

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

X

X

 

 

 

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 



10) (10 points)A cylindrical table is defined in its local coordinate system around the origin with a height of 6 and a radius of 2.

 

a)      3 pts It is placed in the world coordinate system so that it is resting on the xz plane centered around (4,3,2).  What is the matrix that transforms the table points from local to world coordinates?  Call it M1

b)      3 pts A goldfish bowl contains fake goldfish.  It is defined in its local coordinate system as centered on the y-axis.  It is of radius 2 extending from 0 to 3 in y.   The goldfish bowl is to be placed on top of the table at the table’s center top surface.  What is the matrix that transforms the goldfish bowl from local to table coordinates?  Call it M2

c)      3 pts A cat jumps up on the front of the table and knocks the goldfish bowl over 90 degrees(an x axis rotation).  (Don’t worry that the bowl has sunk into the table.  It has fallen over toward the center back of the table.)  What is the matrix that describes this rotation?  Call it M3

d)      1 pts What is the location of the center top of the goldfish bowl as seen from the world coordinates?  Show all work!

 

M1 = the translation from the origin in local to the to the world center or

1          0          0          4

0          1          0          3

0          0          1          2

0          0          0          1

 

M2=translation from origin in local to top of table center.  Needs to be lifted by 3

1          0          0          0

0          1          0          3

0          0          1          0         

0          0          0          1

 

 

 

M3=x rotation matrix of  -90

1          0          0          0

 0         0          -1         0

0          1          0          0

0          0          0          1

 

M1 · M2 ·M3

          First rotate the goldfish bowl, then put it on the table, then put the table (with the bowl) in the world.

M1 · M2 = 1 0 0 4                1 0 0 0

                 0 1 0 6                0 0 -1 0

                      0 0 1 2                0 1 0 0

                      0 0 0 1                0 0 0 1

 

M1 · M2· M3 =  1 0 0 4

                                     0 0 -1 6

                              0 1 0 2

                              0 0 0 1

                                   

                       

Center of goldfish bowl originally at (0,3,0,1)

1 0 0 4         0        4

                                     0 0 -1 6       3  =    6

                              0 1 0 2        0        5

                         0 0 0 1        1        1

 

 

12)  (10 points) Consider the line (0,0,0) to (1,0,1).  An object is rotated 45 degrees around this line.  What are the transformation matrices that will achieve this rotation.   You do not have to multiply out the matrices.  Leave in the form of

      M1 · M2· M3··· MFinal

First find the unit vector.  U=(√2/2, 0, √2/2)

3 pts Then project on the yz plane  d=√2(02+√2/22= √2/2

Rx=1 0 0 0

       0 1 0 0

       0 0 1 0

       0 0 0 1

 

3 pts Now rotate around y to z axis:

Ry=√2/2 0 -√2/2 0

         0    1    0     0

       √2/2 0  √2/2 0

        0    0    0     1

 

3 pts Finally rotate around z by 45 degrees

Rz=√2/2   -√2/2  0     0

        √2/2 √2/2    0     0

        0        0       1     0

        0        0       0     1

1 pt Finally the transformation is R-x R-y Rz Ry Rx

13)  12) (10 points)Suppose I have a clipping window from (10,10) to (50, 30)

a.       Transform my clipping window data to a display window from (40,50) to (80,110).  Make sure you use OpenGL normalized viewing coordinates as an intermediate step.  I need to see each step clearly.

 

b.      Has the aspect ratio remained the same?  If the aspect ratio has changed:  In what direction have I scaled and by how much.

Lose 5 pts if plain TS Matrix, because didn’t normalize

Answer to #7a

 First transform from the clipping window to the normalized viewing coordinates.

| Sx   0   Tx|

| 0    Sy  Ty|

| 0     0   1  |

 

Sx=Xvmax-Xvmin/Xwmax-Xwmin

Tx=(Xwmax*Xvmin) – (Xvmax*Xwmin)/Xwmax-Xwmin

 

3 pts The transformation matrix from the clipping window to the normalized viewing coordinates is

| 2/40   0      -60/40 |

| 0        2/20  -40/20|

| 0         0         1     |

 

Now I need to transform the normalized viewing coordinates to the display window.

I use the same equations as above

 

3 pts The transformation matrix from the normalized viewing coordinates to the display window is

| 40/2    0      120/2 |

| 0        60/2     160/2 |

| 0         0          1     |

 

2 pts Now I need to transform in the correct order

| 20     0      60  |   | 1/20    0      -3/2 |

| 0       30     80 |   | 0      1/10   -2 |

| 0        0       1  |   | 0        0       1 |

 

2 pts

| 1        0          30 |

| 0        3          20 |

| 0        0          1   |

 

7b.  I can simply read from the matrix that I have scaled in the y direction by 3 times.

 


 

12. (15 points)Use the Cohen-Sutherland Line clipping Algorithm to clip the lines in the following diagram.  Clip in the order of Left, Right, Bottom, Top.  Show all steps. (Leave clipped vertex values in fractional form.)  CHANGED TO P1, P1prime, P2, P2, prime form

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


First assign region codes to each point. 1 pt

P1=0100

P2=1010

P3=0100

P4=0100

 

Because P3 & P4 have a 1 in the same position 3 pts

The line is completely outside.  CLIP

 

P1=0100

P2=1010

Check Left most bit all 0’s so nothing to do

Check second bit (right edge)

  Intersection with right edge.

X=X0 + t(Xend – X0)

  30 = 15 + t(35-15) = 15+20t

  15=20t  or t=3/4

Y=Y0 + t(Yend – Y0)

 Y=5 + ¾(45-5) = 35   (30,35)   5 pts

 

P1 =0100

P2’=1000

Check the bottom bit, Intersection with bottom edge. 3 pts

 

Y=Y0 + t(Yend – Y0)

10=5 + t(45 – 5)=5+40t    5/40=t  or t=1/8

X=15 + 1/8(35-15)=15+1/8(20) = 15+20/8 =15+5/2 = 35/2 or 17-1/2

 

P1’=0000

P2’=1000

 

Check top, intersection with top 3 pts

 

Y=Y0 + t(Yend – Y0)  30=5+t(40)   25=40t  25/40=t  t=5/8

X=15+5/8(20) = 15+100/8  = 15+25/2  = 27-1/2

 

 

13) (15 points)Use the Liang-Barsky Line clipping algorithm to clip the line from P1to P2.  Show all work.

 

 

 

 

 

 

 

 

 

 

 

 


p1= -Δx   q1 = x0-xwmin                p1= -20   q1 = 15-10=5            r1=-1/4

p2= Δx   q2 = xwmax -x0 p2= 20   q2 = 30 –15=15          r2=3/4

p3= -Δy   q3 = y0-ywmin                p3= -40   q3 = 5-10=-5            r2=1/8

p4= Δy   q4 = ywmax -y0 p4= 40   q4 = 30 –5=25            r2=5/8

 

U1 = max (0, -1/4,1/8) = 1/8

U2=min(1, 5/8, 3/4)=5/8

X=X0 + t(Xend – X0)

Y=Y0 + t(Yend – Y0)

U1=1/8            X=15+1/8(20)  =15+5/2 = 17.5

                        Y=5+1/8(40) = 10

U2=5/8            X=15+5/8(20) = 15+100/8 = 15+25/2 = 27-1/2

                        Y=5+5/8(40)=30

New line  clipped on bottom. 

 

 

 

 

 

 

 

 

5)(10 points) Use the midpoint circle algorithm to plot the pixels of circle centered on (7,7) with a radius of 5      (6 points for table, -4 if forgot to move to origin first –3 if correctly run on radius 7 circle.

                           0           5       

K         Pk         Xk+1       Yk+1    X,Y pt

  0         -4          1           5                     

  1          -1         2           5             

  2           4         3          4

  3           3          4          3

 

 

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

X

X

X

X

X

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

X

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

X

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

X

 

 

 

 

X

 

 

 

 

 

 

 

 

 

X

 

 

 

 

X

 

 

 

 

*

 

 

 

 

X

 

 

 

 

X

 

 

 

 

 

 

 

 

 

X

 

 

 

 

X

 

 

 

 

 

 

 

 

 

X

 

 

 

 

 

X

 

 

 

 

 

 

 

X

 

 

 

 

 

 

 

X

 

 

 

 

 

X

 

 

 

 

 

 

 

 

 

X

X

X

X

X

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Move center to origin for algorithm

P0 = 5/4-5 = 5/4-5 = -4

If    Pk < 0 plot Xk+1, Yk                      Pk+1=Pk + 2Xk+1  +1

else           plot Xk+1, Yk-1                   Pk+1=Pk + 2Xk+1  +1 – 2Yk+1 

 

Extra Credit (10 points)

Build the quaternion matrix for a 180 degree rotation around the arbitrary axis (1,0,1).

(5 points) a. Show the values for S, a, b, c

 

 

 

 

(5 points) b. Show the matrix –2 if in 3x3 form

 

The unit vector is: (√2/2, 0 √2/2)

 

S=cos(θ/2) = cos(90) = 0

A=sin(90)ux = sin(90)√2/2 = √2/2

B= sin(90)uy  = 0

C= sin(90)uz = sin(90)√2/2 = √2/2

The matrix is

 | 1-2b2-2c2                   2ab-2sc            2ac+2sb                0            |

 | 2ab+2sc                    1-2a2-2c2                 2bc-2sa                 0            |

 | 2ac -2sb                    2bc+2sa           1-2a2 -2b2                         0              |

 |        0                                           0                    0                      1                 |

 

Fill in for s,a,b,c

| 1-0-1                         0-0                   1+0                       0            |

 | 0+0                           1-1-1                            0-0                        0            |

 | 1 -0                           0+0                 1-1 -0                                   0              |

 |        0                                           0                    0                      1                 |

 

 | 0                               0                      1                           0            |

 | 0                               -1                                       0                           0            |

 | 1                               0                      0                                                   0              |

 |  0                                     0                    0                      1                 |