3 DIMENSIONAL VIEWING - Middle East Technical University

Download Report

Transcript 3 DIMENSIONAL VIEWING - Middle East Technical University

Midterm Review
Ceng 477
Introduction to Computer Graphics
Computer Engineering
METU
Review Topics
●
●
●
●
●
The Graphics Pipeline
Output primitives: line drawing, circle drawing
algorithms
Filled Area Primitives: polygon filling algorithms
Geometric transformation: 2D/3D transformation,
composite transformations
2D Viewing: Viewing transformations, line clipping,
polygon clipping algorithms
The Graphics Pipeline
Modeling
Transformations
Model
Viewing
Transformations
M1
Model
M2
3D World
Scene
V
View
Coordinates
Model
M3
WCS
MCS
Projection Transformation
Projection
VCS
Normalization
Transformation and
Clipping
Normalized
coordinates
Viewport
Transformation
2D Image
DCS
SCS
Rasterization
Midterm Review Exercise #1
●
Using the Cohen-Sutherland line clipping
algorithm clip the following line:
P2 = 12,25
y = 20
x= 4
x = 16
y=2
P1 = 2,-5
Solution
bits2,-5 = 0101 bits12,25 = 1000
bits2,-5 & bits12,25 = 0000
25  5 = 3
m=
12  2
LEFT : y p = 5 + 34  2  = 1
LEFTP1   P1' = 4,1
RIGHT:
Both end pointsinside right clippingplane.
Do nothing.
BO TTO M: x p = 4 +
2  1 = 13
3
3
 13 
BOT T OMP1'   P1' ' =  ,2 
3 
13 20  2  31
TO P : x p = +
=
3
3
3
 31 
T OPP2   P2' =  ,20
3

Line = 13 / 3,2 to 31/3,20 
P2 = 12,25
y = 20
x= 4
P1' = 4,1
P1 = 2,-5
P2' = 31/3,20
P1= 13/3,2
y=2
x = 16
Midterm Review Exercise #2
●
We want to put a mirror in a 3D scene. The
mirror is specified as a 3D rectangle specified
with its corner points and with one of its
principle axes parallel to the y axis and the
other parallel to the xz plane (illustrated
P1 = 3,10,-1
below).
y
parallel to xz plane
x
z
P2 = 6,0,2
Give the transformation matrix that will generate mirror objects of all
the objects in the scene (you may assume all the objects are in front
of the mirror). And show the results as a product of matrices.
Solution
●
Basically what we are asked
is reflection with respect to a
plane.
z
●
We can formulate this with a
composite transformation
–
Align the mirror plane with one of
the planes, e.g., yz plane
–
Compute reflection wrt to yz plane
–
Restore the mirror plane’s original
position and orientation
y
P1 = 3,10,-1
x
P2 = 6,0,2
y
Solution
●
1
0
T
0

0
–
0
1
0
0
0  3
0 0 
1 1

0 1
x
z
45o
Rotate the plane so that P2 is on the
z axis.
y
cos 45
 0
R y (45)  
 sin 45

 0
0  sin 45
1
0
0 cos 45
0
0
P2 = 6,0,2
P1= 0,10,0
y
Translate P1 onto the y axis.
x
z
Align the mirror plane with one of
the planes, e.g., yz plane
–
P1 = 3,10,-1
0
0
0

1
z
P2 = 3,0,3
P1= 0,10,0

P2 = 0,0,3 2

x
y
Solution
●
Reflection around yz plane is just
inversion of x coordinate
–
–
0
1
0
0
0
0
1
0
0
0
0

1
x
P2 = 6,0,2
z
P1= 0,10,0
y
Reflection around yz.
 1
0
Ref yz  
0

0
P1 = 3,10,-1
x
z

P2 = 0,0,3 2

Do the reverse transformations:
rotate 45 degrees counterclockwise
and translate P1 back to (3,10,-1) to
finish the composite transformation.
Final Solution: T(3,0,-1)Ry(45)Refyz( )Ry(-45)T(-3,0,1)
Midterm Review Exercise #3
●
●
●
Write the contents of the sorted
edge table for the given
polygon. Assume the scan
conversion starts from the
bottom scan line.
Which edges are in the Active
Edge List at scan line 4?
Show the double or single
counted vertices. But you do not
need to consider their updated
values when filling in the edge
table
Solution
●
●
The vertex A is the
bottommost vertex.
Starting from vertex A fill in
the Sorted Edge table.
E is the only vertex that
need to be counted once,
so we need update the
edge FE to FE’. The other
vertices are not need to be
updated.
Solution
The sorted edge table
Y
E1
E2
1
AB
AG
2
FG
FE’
3
CB
CD
4
ED
Solution
The contents of the sorted edge table
Y
Xinit, Ymax,1/m
Xinit, Ymax,1/m
1
AB: 1,6,0
AG: 1,3,1
2
FG: 6,3,-3
FE’: 6,4,2
3
CB: 6,6,-5/3
CD: 6,6,2/3
4
ED: 10,6,-1
At scanline 4: AB,CB,CD,ED are active (FE’ is just dropped
from the list)