Assignment #3 solution ()

advertisement
EECE 478 Computer Graphics
HW #3 Solution
Note: All the transformation matrices in this assignment are supposed to work on column vectors.
Problem 1
The DDA is an algorithm derived from the slope-intercept form of a line. From the DDA
algorithm, which is first adapted for faster graphics, the Bresenham’s algorithm is derived.
(a) Bresenham’s has more characteristics than the DDA. List them.
Answer:
Some properties of Bresenham’s algorithm from the textbook are:
1. No rounding function
2. Only integer arithmetic
3. Calculation for the point (xi+1, yi+1) based on the point (xi, yi) only.
4. Applicable to the integer computation of circles
5. Line and integer circle algorithms provide the best-fit approximation
Points 1 – 3 imply that the Bresenham’s algorithm is faster than the DDA since rounding,
floating arithmetic and non-incremental technique take more computing time.
From the assignments of students, some points NOT the advantages of Bresenham’s algorithm
over the DDA are:
1. endpoints are (x0, y0) and (x1, y1)
2. slope is between 0 and 1.
3. description of the Bresenham’s algorithm
4. no multiplication or division. (Both DDA and Bresenham’s algorithm do not have these in the
main loop.)
5. list of the variables used in the algorithms
(b) Consider the Figure below where a line is to be placed on the grid from the circle in the lower
left-hand corner to the circle in the upper right-hand corner by Bresenham’s algorithm.
Graphically show how Bresenham’s algorithm will generate the line by making appropriate gridpoints. For the critical points, carry out simple calculations for the decision what needs to be
done. Explain how you arrived at your answer.
12
11
9
8
7
5
6
7
8
9
10 11 12 13 14 15 16
Answer:
The basic idea of the Bresenham’s algorithm is that for a point P at (xp, yp) for a line of slope
between 0 and 1, the point at x = xp + 1 can be either E (y = yp) or NE (y = yp+1) depending on
which one the line is close to.
To determine which points to turn on, a line is first drawn between the two end-points.
12
11
9
8
7
5
6
7
8
9
10 11 12 13 14 15 16
5
5
25 52

The line has slope
and has equation y  x  b where b = 7 
.
11
11
11 11
Then, scan from left to right along the x-axis to decide which points to turn on based on the idea
shown above.
For point at x = 6, y =7.45. Point (6,7) will be turned on. The points at x = 7 to x = 14 are very
obvious. For point at x = 15, y  11.55 . Point (15,12) will be turned on.
Therefore, the result is:
12
11
9
8
7
5
6
7
8
9
10 11 12 13 14 15 16
Problem 2
Consider the operation of double shearing, that is, shearing in the x-axis direction followed by
shearing in the y-axis direction or vice versa.
(a) Is double shearing commutative? Show algebraically, using homogenous coordinates, that
your answer is correct.
Answer:
No, double shearing is not commutative.
Proof:
The matrices for x and y shear transformations are:
1 a 0
1 0 0


SH x  0 1 0
SH y  b 1 0
0 0 1
0 0 1
The transformation matrix for shearing along the x-axis followed by shearing along the y-axis is:
a
0
1 0 0 1 a 0 1





Txy  SH y  SH x b 1 0 0 1 0  b ab  1 0
0 0 1 0 0 1 0
0
1
Remark: This order of the matrices is correct since the matrix closest to the vector transforms the
vector first! Column vector to be transformed is placed to the right of the transformation matrix.
The transformation matrix for shearing along the y-axis followed by shearing along the x-axis is:
1 a 0 1 0 0 ab  1 a 0
T yx  SH x  SH y 0 1 0 b 1 0   b
1 0
0 0 1 0 0 1  0
0 1
Since Txy and Tyx are not the same, shearing is not commutative.
(b) Can double shearing be carried out simultaneously, that is, be represented by a single matrix?
Attempt to derive the transformation matrix and show that this is or not possible.
Answer:
Yes, double shearing can be carried out simultaneously represented by a single matrix. As shown
in part (a), each type of double shearing can be represented by a single matrix.
1 a 0
Remark: the matrix T  b 1 0 is not a double shearing matrix based on the definition of
0 0 1
double shearing given above. The effect of this matrix is different from the two matrices
obtained in part a.
Problem 3
Explain the effect of the following matrices as related to transformation:
0 1
1 0 0 0 
 cos 50 0 sin 50 0
 1 0
0 1 0 0
 0


1
0
0
0  1 0 1




(a)
(b)
(c)
 4 3 0 0
 sin 50 0 cos 50 0
0
0  1 0






0
0
1
0
0 1
0 0 0 1 
 0
0
Answer:
1 0
0 1
(a) 
4 3

0 0
0 0  x   x 
0 0  y   y 

0 0  z   4 x  3 y 
  

0 1  1   1 
From the result, this matrix shears the vector along the z-axis by an amount of 4x+3y where x
and y are the x- and y-coordinates of the vectors.
(b) I think there is a mistake in the matrix in the original question sheet, it should be
 cos 50 0 sin 50 0
 0
1
0
0

instead.
 sin 50 0 cos 50 0


0
0
1
 0
Thus it is obviously a matrix for the rotation around the y-axis by 50 degree.
 1 0 0 1  x    x  1
 0  1 0 1  y   y  1
   

(c) 
 0 0  1 0  z    z 

  

 0 0 0 1  1   1 
From the result, this matrix performs reflection at the origin followed by translation in the xdirection by 1 and in the y-direction by 1.
Problem 4
A square as shown in (a) is converted to a parallelogram as in (b) using composite transformation
matrix M. Determine such matrix. Explain your work.
(2,2)
(0.5,1.5)
(1.1)
(0,1)
(1.5,0.5)
(0,0)
(1,0)
(a)
(0,0)
(b)
Answer:
Based on the data in the graph above:
0 0.5
1 1.5 




M 1  1.5 
M 0  0.5
1  1 
1  1 
1 2
M 1  2
1 1 
Then,
0 1 1 0.5 1.5 2
M 1 0 1  1.5 0.5 2
1 1 1  1
1 1
Therefore,
1.5 0.5 0
M  0.5 1.5 0
 0
0 1
Problem 5
Develop a Cohen-Sutherland outcode for 3D and example your steps.
Answer:
Add two more bits to the code to make a 6-bit code so that :
First bit
Second bit
Third bit
Fourth bit
Fifth bit
Sixth bit
y
y
x
x
z
z
>
<
>
<
>
<
ymax
ymin
xmax
xmin
zmax
zmin
Y
X
Z
For the small cube in the center of the large cube shown above consider as the clip region, the
outcodes for each small cubes surrounding the central cube are:
Z min < Z <
Zmax
Z < Z min
Z > Z
max
100100
100000
101000
100110
100010
101010
100101
100001
101001
000100
000000
001000
000110
000010
001010
000101
000001
001001
010100
010000
011000
010010
011010
010101
010001
011001
Y
max
Ymin
X
min
X max
010110
X
min
X max
X
min
X max
Problem 6
Generate the necessary Edge Table and Active Edge Table to fill the polygon in Figure below.
(4,9)
A
(4,5) D
B
(1,1) C
(7,1)
Why was it necessary to generate these tables?
Answer:
(4,9)
A
(4,5) D
B
(1,1) C
(7,1)
Edge Table:
9
6
9
3
2
0
0
CD
5
AB
1 3/4
9
7 -3/8
1/m
1
4
X
5
4
AD
Ymax
Y- coordinate
8
Active Edge Table for Scan Line 1 to 9:
AET
pointer
CD
5
Scan Line 1:
AET
pointer
AET
pointer
AET
pointer
AET
pointer
Scan Line 5:
9
2 3/4
3 3/4
9
4 3/4
6 -3/8
AB
9
CD
5
7 -3/8
AB
CD
5
Scan Line 4:
2 3/4
7 -3/8
AB
CD
5
Scan Line 3:
9
CD
5
Scan Line 2:
1 3/4
AB
6 -3/8
AB
9
5 -3/8
AET
pointer
9
Scan Line 6:
AET
pointer
AET
pointer
AET
pointer
Scan Line 9:
0
9
4
0
4
0
9
4
0
5 -3/8
AB
9
4 -3/8
AB
AD
9
5 -3/8
AB
AD
9
Scan Line 8:
4
AD
9
Scan Line 7:
AB
AD
9
4 -3/8
This algorithm takes advantage of the edge coherence to calculate x intersections and scanline
coherence to calculate spans. The edge table stores the information for each edge and sorts the
edges on their minimum y-coordinates and their corresponding x-coordinates. The active edge
table keeps track of each scanline so that edges intersect with this scanline are sorted in
ascending order on their x-coordinates of the intersections. Due to the edge coherence and
scanline coherence, only a small amount of work is required to update the active edge table for
each scanline.
Problem 7
What are the computer graphics system main components? Give example on each component.
What are the state-of-the-art computer graphics software package available in the market? Have
you used any? Explain what you did with them.
Answer:
A computer graphics system includes:
1. input devices
e.g. keyboard, mouse, trackball, joystick, cyberglove, scanner, etc
2. output devices
e.g. monitor, printer etc
3. processing unit
e.g. CPU, video controller, etc
4. softwares
e.g. OpenGL, SRGP, Alias, Director, Animator, etc
State-of-the-art computer graphics software packages:
1. OpenGL
2. Alias
3. Director
4. Photoshop
5. CorelDraw
6. AutoCad
and many many more……
Problem 8
Binary Space Partition (BSP) tree is an efficient method for determining object visibility by
painting surfaces onto the screen from back to front, as in painter’s algorithm. Explain how does
this algorithm work using a simple example (but not a trivial one).
Answer:
The algorithm of the BSP tree is shown as follows:
1. pick any surface of an object to put on the root of the tree
2. any other surfaces of the object totally behind the surface picked in 1 will be on the left side
of the tree.
3. all surfaces of the object totally in front of the surface picked in 1 will be on the right side of
the tree.
4. a surface lying on both sides is split and the two halves are assigned to the two groups in
steps 2 and 3.
5. for each side of the tree, repeat steps 1 to 4 until there is only one surface left for each node.
Example:
There are four objects or surfaces in the diagram above. If the blue rectangular surface is chosen
to be the root of the BSP tree, we will get in the first loop of the algorithm:
Then, in the second loop, the yellow surface on the left side of the tree is shown as the root of
this sub-tree. In the third loop, the red rectangle is chosen as the root of the sub-tree of the subtree obtained in the second loop. The final BSP tree is:
Download