Clipping - PowerPoint PPT Presentation

1 / 57
About This Presentation
Title:

Clipping

Description:

Clipping Polygon Clipping Polygon : Area primitive Simple Polygon: Planar set of ordered points No line crossings No holes V3 V4 V1 V2 Hole Line Crossing – PowerPoint PPT presentation

Number of Views:76
Avg rating:3.0/5.0
Slides: 58
Provided by: MR22304
Category:

less

Transcript and Presenter's Notes

Title: Clipping


1
Clipping
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
2
Clipping
Polygon Clipping
Polygon Area primitive
Non-Convex Polygon
Convex Polygon
3
Clipping
Polygon Clipping
Sutherland-Hodgman
  • Window must be convex
  • Polygon to be clipped can be convex or non-convex

Polygon
Polygon
Window
4
Clipping
Polygon Clipping
Sutherland-Hodgman
  • Window must be convex
  • Polygon to be clipped can be convex or non-convex

5
Clipping
Polygon Clipping
Sutherland-Hodgman

6
Clipping
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

7
Clipping
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

8
Clipping
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
9
Clipping
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
10
Clipping
Polygon Clipping
Sutherland-Hodgman
Approach
Case 3 Polygon edge is entirely outside the
window edge
Outside
Inside
p
  • No output

s
11
Clipping
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

12
Clipping
Polygon Clipping
Sutherland-Hodgman
Example
s5
s4
Polygon
s3
s2
Window
s1
13
Clipping
Polygon Clipping
Sutherland-Hodgman
Example
s5
s4
i1
i2
s3
s2
s1
14
Clipping
Polygon Clipping
Sutherland-Hodgman
Example
t3
t4
t2
t1
t5
15
Clipping
Polygon Clipping
Sutherland-Hodgman
Example
u2
u3
u1
u5
u4
16
Clipping
Polygon Clipping
Sutherland-Hodgman
Example
v1
v2
i3
i6
v5
i5
v4
i4
v3
17
Clipping
Polygon Clipping
Sutherland-Hodgman
Example
w6
w1
w5
w4
w3
w2
18
Polygon Scan Conversion
Polygon Filling
Consider first triangle
19
Polygon Scan Conversion
Polygon Filling
Consider first triangle
Color all pixels inside triangle Inside
(containment) test
20
Polygon Scan Conversion
Polygon Filling
Triangle
Use horizontal spans. Process horizontal spans in
scan-line order. For the next spans use edge
slopes
XL
XR
21
Polygon Scan Conversion
Polygon Filling
Polygon
How do we decide what parts of the span should be
filled ?
22
Polygon 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
23
Polygon Scan Conversion
Polygon Filling
Polygon
What happens here?
24
Polygon Scan Conversion
Polygon Filling
Polygon
What happens here?
25
Polygon Scan Conversion
Polygon Filling
Polygon
Recursive seed filling
26
(No Transcript)
27
Geometrical 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
28
Geometrical 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
.
29
Geometrical 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
30
Geometrical 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
.
?
31
Geometrical 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
32
Geometrical 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
33
Geometrical Transformation
General 2x2 Matrix
0
1
ù
é
Shearing in X
'
'




,



,


,

y
cy
x
y
x
y
x
ú
ê
1
c
û
ë
34
Geometrical Transformation
General 2x2 Matrix
1
b
ù
é
Shearing in Y
'
'




,



,


,

y
bx
x
y
x
y
x
ú
ê
1
0
û
ë
35
Geometrical 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
36
Geometrical Transformation
Homogenous Coordinates
w
(x, y,w)
(x/w, y/w,1)
w1
x
y
37
Geometrical 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
38
Geometrical Transformation
Homogenous Coordinates
Translation
0
0
1
ù
é
ú
ê

0
1
0

T
ú
ê
ú
ê
1
m
l
û
ë

'
XT
X




,


'
,
'

m
y
l
x
y
x
39
Geometrical Transformation
Homogenous Coordinates
Scaling/Rotation/Shear
ù
é
0
b
a
ú
ê

0

d
c
T
ú
ê
ú
ê
1
0
0
û
ë
40
Geometrical Transformation
Homogenous Coordinates
Successive translations T1 (l1, m1), T2 (l2,
m2)
After T1
After T1 and T2
Successive translations are additive
41
Geometrical Transformation
Homogenous Coordinates
Successive scaling S1 (sx1, sy1), S2 (sx2,
sy2)
After S1
After S1 and S2
Successive scaling is multiplicative
42
Geometrical Transformation
Homogenous Coordinates
Successive rotations R(q), R(f)
After R(q)
After R(q) and R(f)
Successive rotations are additive
43
Geometrical 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
44
Geometrical Transformation
Composition of transformation
Rotation about arbitrary point
y
  • Rotation about origin is known
  • Translate such that P becomes O

P
x
O
45
Geometrical Transformation
Composition of transformation
Rotation about arbitrary point
y
  • Rotation about origin is known
  • Rotate about O

x
O
46
Geometrical Transformation
Composition of transformation
Rotation about arbitrary point
y
  • Rotation about origin is known
  • Translate back to P

P
x
O
47
Geometrical Transformation
Composition of transformation
Composite transformation
48
Geometrical Transformation
Composition of transformation
Reflection about an arbitrary line
B
y
C
A
x
O
49
Geometrical Transformation
Composition of transformation
Reflection about an arbitrary line
y
B
Translation
C
A
x
O
50
Geometrical Transformation
Composition of transformation
Reflection about an arbitrary line
y
B
Rotation
A
C
x
O
51
Geometrical Transformation
Composition of transformation
Reflection about an arbitrary line
y
Reflection
x
O
A
C
B
52
Geometrical Transformation
Composition of transformation
Reflection about an arbitrary line
y
Rotation
C
x
O
A
B
53
Geometrical Transformation
Composition of transformation
Reflection about an arbitrary line
y
Translation
C
A
x
O
B
54
Geometrical Transformation
Composition of transformation
Given T1 and T2 In general,
55
Geometrical 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
û
ë
56
Geometrical Transformation
Affine Transformations
  • Preserves parallelism
  • Sequence of rotations, translations, scaling and
    shear
  • Linear transformation is when no translation

57
Geometrical Transformation
General Transformation
  • 3x3 matrix
Write a Comment
User Comments (0)
About PowerShow.com