Title: Clipping
1Clipping
Polygon Clipping
Polygon Area primitive
Simple Polygon Planar set of ordered points
No line crossings No holes
V3
V4
V1
V2
Hole
Line Crossing
Simple Polygon
2Clipping
Polygon Clipping
Polygon Area primitive
Non-Convex Polygon
Convex Polygon
3Clipping
Polygon Clipping
Sutherland-Hodgman
- Window must be convex
- Polygon to be clipped can be convex or non-convex
Polygon
Polygon
Window
4Clipping
Polygon Clipping
Sutherland-Hodgman
- Window must be convex
- Polygon to be clipped can be convex or non-convex
5Clipping
Polygon Clipping
Sutherland-Hodgman
6Clipping
Polygon Clipping
Sutherland-Hodgman
Approach
- Polygon to be clipped is given as v1, v2, , vn
- Polygon edge is a pair vi, vi1
- Process all polygon edges in succession against
- a window edge
- polygon (v1, v2, , vn) polygon (w1, w2,
, wm) - Repeat on resulting polygon with next window edge
7Clipping
Polygon Clipping
Sutherland-Hodgman
Approach
Four Cases
- s vi is the polygon edge starting vertex
- p vi1 is the polygon edge ending vertex
- i is a polygon-edge/window-edge intersection
point - wj is the next polygon vertex to be output
8Clipping
Polygon Clipping
Sutherland-Hodgman
Approach
Case 1 Polygon edge is entirely inside the
window edge
Outside
Inside
s
- p is next vertex of resulting polygon
- p wj and j1 j
p
Output
9Clipping
Polygon Clipping
Sutherland-Hodgman
Approach
Case 2 Polygon edge crosses window edge going
out
Outside
Inside
- Intersection point i is next vertex
- of resulting polygon
- i wj and j1 j
p
s
i
Output
10Clipping
Polygon Clipping
Sutherland-Hodgman
Approach
Case 3 Polygon edge is entirely outside the
window edge
Outside
Inside
p
s
11Clipping
Polygon Clipping
Sutherland-Hodgman
Approach
Case 4 Polygon edge crosses window edge going in
Outside
Inside
Output
s
p
i
- Intersection point i and p are next two
- vertices of resulting polygon
- i wj and p wj1 and j2 j
12Clipping
Polygon Clipping
Sutherland-Hodgman
Example
s5
s4
Polygon
s3
s2
Window
s1
13Clipping
Polygon Clipping
Sutherland-Hodgman
Example
s5
s4
i1
i2
s3
s2
s1
14Clipping
Polygon Clipping
Sutherland-Hodgman
Example
t3
t4
t2
t1
t5
15Clipping
Polygon Clipping
Sutherland-Hodgman
Example
u2
u3
u1
u5
u4
16Clipping
Polygon Clipping
Sutherland-Hodgman
Example
v1
v2
i3
i6
v5
i5
v4
i4
v3
17Clipping
Polygon Clipping
Sutherland-Hodgman
Example
w6
w1
w5
w4
w3
w2
18Polygon Scan Conversion
Polygon Filling
Consider first triangle
19Polygon Scan Conversion
Polygon Filling
Consider first triangle
Color all pixels inside triangle Inside
(containment) test
20Polygon Scan Conversion
Polygon Filling
Triangle
Use horizontal spans. Process horizontal spans in
scan-line order. For the next spans use edge
slopes
XL
XR
21Polygon Scan Conversion
Polygon Filling
Polygon
How do we decide what parts of the span should be
filled ?
22Polygon Scan Conversion
Polygon Filling
Polygon
How do we decide what parts of the span should be
filled ?
Parity check if odd fill if even dont fill
23Polygon Scan Conversion
Polygon Filling
Polygon
What happens here?
24Polygon Scan Conversion
Polygon Filling
Polygon
What happens here?
25Polygon Scan Conversion
Polygon Filling
Polygon
Recursive seed filling
26(No Transcript)
27Geometrical Transformation
Translation
'
'
'
P
)
,
(
)
,
(
y
x
P
y
x
P
'
'
t
y
y
t
x
x
y
x
P
T
'
T
P
P
,
,
t
t
T
y
x
P
y
x
28Geometrical Transformation
Scaling
'
'
'
y
x
P
y
x
P
)
,
(
)
,
(
'
'
y
s
y
x
s
x
y
x
s
0
ù
é
x
'
'
y
x
y
x
,
,
ú
ê
s
0
û
ë
y
'
S
P
P
.
29Geometrical Transformation
Scaling
'
'
'
y
x
P
y
x
P
)
,
(
)
,
(
'
'
y
s
y
x
s
x
y
x
s
0
ù
é
x
'
'
y
x
y
x
,
,
ú
ê
s
0
û
ë
y
'
S
P
P
.
scaling
uniform
s
s
y
x
¹
scaling
al
differenti
s
s
y
x
30Geometrical Transformation
Rotation
'
'
'
y
x
P
y
x
P
)
,
(
)
,
(
f
r
y
f
r
x
)
sin(
)
cos(
'
?
f
r
x
)
cos(
P
'
?
f
r
y
)
sin(
P
q
f
'
-
?
y
?
x
x
)
sin(
)
cos(
'
?
y
?
x
y
)
cos(
)
sin(
?
?
)
sin(
)
cos(
ù
é
'
'
y
x
y
x
,
,
ú
ê
-
?
?
)
cos(
)
sin(
û
ë
'
R
P
P
.
?
31Geometrical Transformation
General 2x2 Matrix
'
X
X
'
.
T
X
X
b
a
ù
é
'
'
)
(
),
(
,
,
dy
bx
cy
ax
y
x
y
x
ú
ê
d
c
û
ë
If a d 1 and b c 0 T Identity Matrix X
X
32Geometrical Transformation
General 2x2 Matrix
y
If b c 0 X ax, dy Scaling If b c
0 and a -1, d 1 X -x, y Reflection
P
P
x
33Geometrical Transformation
General 2x2 Matrix
0
1
ù
é
Shearing in X
'
'
,
,
,
y
cy
x
y
x
y
x
ú
ê
1
c
û
ë
34Geometrical Transformation
General 2x2 Matrix
1
b
ù
é
Shearing in Y
'
'
,
,
,
y
bx
x
y
x
y
x
ú
ê
1
0
û
ë
35Geometrical Transformation
Homogenous Coordinates
Scale/Rotate/Reflect/Shear X XT Translate X
X T
,
y
x
P
,
,
w
y
x
P
h
Multiple values for the same point e.g., (2, 3,
6) and (4, 6, 12) are same points
36Geometrical Transformation
Homogenous Coordinates
w
(x, y,w)
(x/w, y/w,1)
w1
x
y
37Geometrical Transformation
Homogenous Coordinates
Unifying representation for transformation Transfo
rmation matrix from 2x2 to 3x3
'
X
X
'
.
T
X
X
0
b
a
ù
é
ú
ê
'
'
0
1
,
,
,
,
d
c
y
x
w
y
x
ú
ê
ú
ê
1
m
l
û
ë
1
),
(
),
(
m
dy
bx
l
cy
ax
38Geometrical Transformation
Homogenous Coordinates
Translation
0
0
1
ù
é
ú
ê
0
1
0
T
ú
ê
ú
ê
1
m
l
û
ë
'
XT
X
,
'
,
'
m
y
l
x
y
x
39Geometrical Transformation
Homogenous Coordinates
Scaling/Rotation/Shear
ù
é
0
b
a
ú
ê
0
d
c
T
ú
ê
ú
ê
1
0
0
û
ë
40Geometrical Transformation
Homogenous Coordinates
Successive translations T1 (l1, m1), T2 (l2,
m2)
After T1
After T1 and T2
Successive translations are additive
41Geometrical Transformation
Homogenous Coordinates
Successive scaling S1 (sx1, sy1), S2 (sx2,
sy2)
After S1
After S1 and S2
Successive scaling is multiplicative
42Geometrical Transformation
Homogenous Coordinates
Successive rotations R(q), R(f)
After R(q)
After R(q) and R(f)
Successive rotations are additive
43Geometrical Transformation
Composition of transformation
Rotation about arbitrary point
y
- Rotation about origin is known
- Translate such that P becomes O
- Rotate (about O)
- Translate back to P
P
x
O
44Geometrical Transformation
Composition of transformation
Rotation about arbitrary point
y
- Rotation about origin is known
- Translate such that P becomes O
P
x
O
45Geometrical Transformation
Composition of transformation
Rotation about arbitrary point
y
- Rotation about origin is known
- Rotate about O
x
O
46Geometrical Transformation
Composition of transformation
Rotation about arbitrary point
y
- Rotation about origin is known
- Translate back to P
P
x
O
47Geometrical Transformation
Composition of transformation
Composite transformation
48Geometrical Transformation
Composition of transformation
Reflection about an arbitrary line
B
y
C
A
x
O
49Geometrical Transformation
Composition of transformation
Reflection about an arbitrary line
y
B
Translation
C
A
x
O
50Geometrical Transformation
Composition of transformation
Reflection about an arbitrary line
y
B
Rotation
A
C
x
O
51Geometrical Transformation
Composition of transformation
Reflection about an arbitrary line
y
Reflection
x
O
A
C
B
52Geometrical Transformation
Composition of transformation
Reflection about an arbitrary line
y
Rotation
C
x
O
A
B
53Geometrical Transformation
Composition of transformation
Reflection about an arbitrary line
y
Translation
C
A
x
O
B
54Geometrical Transformation
Composition of transformation
Given T1 and T2 In general,
55Geometrical Transformation
Rigid Transformations
- Square remains square
- Preserves length and angles
- Sequence of rotations and translations
ù
é
0
r
r
12
11
ú
ê
0
r
r
T
ú
ê
22
21
ú
ê
1
m
l
û
ë
56Geometrical Transformation
Affine Transformations
- Preserves parallelism
- Sequence of rotations, translations, scaling and
shear
- Linear transformation is when no translation
57Geometrical Transformation
General Transformation