Professional Documents
Culture Documents
08 Clipping Cad Cam
08 Clipping Cad Cam
08 Clipping Cad Cam
Aaron Bloomfield
CS 445: Introduction to Graphics
Fall 2006
(Slide set originally by David Luebke)
Outline
Review
Clipping Basics
Cohen-Sutherland Line Clipping
Clipping Polygons
Sutherland-Hodgman Clipping
Perspective Clipping
Intuitively:
x = ?
(0,0,0)
Desired
result:
P (x, y, z)
d x
x
x'
,
z
z d
d y
y
y'
, zd
z
z d
Example:
x 1
y 0
z 0
z d 0
1 0
0 1
0 1d
,
z d
0 x
0 y
0 z
0 1
y
, d
z d
f
aspect
0
Z near
where
far
Z Z
far
near
1
2 Z far Z near
Z Z
near
far
fov y
f cot
2
Projection Matrices
Outline
Review
Clipping Basics
Cohen-Sutherland Line Clipping
Clipping Polygons
Sutherland-Hodgman Clipping
Perspective Clipping
10
Clipping
11
Why Clip?
12
Clipping
Trivial Accepts
xmax
ymax
ymin
14
Trivial Rejects
xmax
ymax
ymin
15
Outline
Review
Clipping Basics
Cohen-Sutherland Line Clipping
Clipping Polygons
Sutherland-Hodgman Clipping
Perspective Clipping
16
1001
xmax
1000
1010
0000
0010
0100
0110
ymax
0001
ymin
0101
17
1001
xmax
1000
1010
0000
0010
0100
0110
ymax
0001
ymin
0101
18
y < ymin
etc.
1000
1010
0000
0010
0100
0110
19
ymax
0001
ymin
0101
20
Clip top
Clip left
Clip bottom
Clip right
21
Outline
Review
Clipping Basics
Cohen-Sutherland Line Clipping
Clipping Polygons
Sutherland-Hodgman Clipping
Perspective Clipping
22
Clipping Polygons
Input: polygon
Output: polygon, or nothing
Triangletriangle
Trianglequad
Triangle5-gon
25
26
Outline
Review
Clipping Basics
Cohen-Sutherland Line Clipping
Clipping Polygons
Sutherland-Hodgman Clipping
Perspective Clipping
27
Sutherland-Hodgman Clipping
Basic idea:
28
Sutherland-Hodgman Clipping
Basic idea:
29
Sutherland-Hodgman Clipping
Basic idea:
30
Sutherland-Hodgman Clipping
Basic idea:
31
Sutherland-Hodgman Clipping
Basic idea:
32
Sutherland-Hodgman Clipping
Basic idea:
33
Sutherland-Hodgman Clipping
Basic idea:
34
Sutherland-Hodgman Clipping
Basic idea:
35
Sutherland-Hodgman Clipping
Basic idea:
36
Sutherland-Hodgman Clipping
Basic idea:
37
Sutherland-Hodgman Clipping
Show movie
38
Sutherland-Hodgman Clipping
39
Sutherland-Hodgman Clipping
inside
outside
inside
outside
inside
p
p output
s
i output
outside
inside
outside
s
no output
i output
p output
40
Sutherland-Hodgman Clipping
Four cases:
Add p to output
Note: s has already been added
Add nothing
41
Point-to-Plane test
p inside P
p on P
p outside P
p
P
n
42
Point-to-Plane Test
3 multiplies
5 additions
1 comparison (to 0, in this case)
43
E(t) = s + t(p - s)
If t = 0 then E(t) = s
If t = 1 then E(t) = p
Otherwise, E(t) is part way from s to p
44
q is a point on P
n is normal to P
(E(t) - q) n = 0
(s + t(p - s) - q) n = 0
t = [(q - s) n] / [(p - s) n]
Line-Plane Intersections
46
Outline
Review
Clipping Basics
Cohen-Sutherland Line Clipping
Clipping Polygons
Sutherland-Hodgman Clipping
Perspective Clipping
47
3-D Clipping
48
Example:
x
y
z
d
1 0
0 1
0 0 1
0 0 1d
0
0
0
0
x
y
,
z d
y
, d
z d
Clip against
view volume
3-D world
coordinate
primitives
Canonical screen
coordinates
Apply projection
matrix and
homogeneous
divide
Transform into
viewport for
2-D display
2-D device
coordinates
51
52
Perspective Projection
53
Perspective Projection
1
Front or
hither plane
-1
-1
54
3-D world
coordinate
primitives
canonical
view
volume
projection
matrix;
homogeneous
divide
Transform into
viewport for
2-D display
2-D device
coordinates
55
Apply
projection
matrix
3-D world
coordinate
primitives
Clip
against
view
volume
Homogeneous
divide
Transform into
viewport for
2-D display
2-D device
coordinates
56
Other advantages:
57
x, y [-1, 1]
z [0, 1]
58
Clip against
hither and
yon planes
Projection
matrix;
homogeneous
divide
Transform into
screen
coordinates
Clip in 2-D
screen
coordinates
59