You are on page 1of 21

Clipping

Polygon Clipping
Polygon : Area primitive

Simple Polygon: Planar set of ordered points


No line crossings
No holes
V3 V4

V1 V2
Simple Polygon Line Crossing Hole
Clipping
Polygon Clipping
Polygon : Area primitive

Convex Polygon Non-Convex Polygon


Clipping
Polygon Clipping
Sutherland-Hodgman

• Window must be convex


• Polygon to be clipped can be convex or non-convex

Polygon Polygon

Window
Clipping
Polygon Clipping
Sutherland-Hodgman

• Window must be convex


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

Approach
• Polygon to be clipped is given as v1, v2, !, vn
• Polygon edge is a pair [vi, vi+1]
• 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
Clipping
Polygon Clipping
Sutherland-Hodgman

Approach
Four Cases
• s = vi is the polygon edge starting vertex
• p = vi+1 is the polygon edge ending vertex
• i is a polygon-edge/window-edge intersection point
• wj is the next polygon vertex to be output
Clipping
Polygon Clipping
Sutherland-Hodgman

Approach
Case 1: Polygon edge is entirely inside the window edge
Inside Outside

s
• p is next vertex of resulting polygon
• p wj and j+1 j

p
Output
Clipping
Polygon Clipping
Sutherland-Hodgman

Approach
Case 2: Polygon edge crosses window edge going out
Inside Outside

• Intersection point i is next vertex


of resulting polygon
p • i wj and j+1 j
s i Output
Clipping
Polygon Clipping
Sutherland-Hodgman

Approach
Case 3: Polygon edge is entirely outside the window edge
Inside Outside
p

• No output

s
Clipping
Polygon Clipping
Sutherland-Hodgman

Approach
Case 4: Polygon edge crosses window edge going in
Inside Outside
Output s
p i
• Intersection point i and p are next two
vertices of resulting polygon
• i wj and p wj+1 and j+2 j
Clipping
Polygon Clipping
Sutherland-Hodgman
Example s5 s4
Polygon

s3 s2 Window

s1
Clipping
Polygon Clipping
Sutherland-Hodgman
Example s5 s4

i2 i1

s3 s2

s1
Clipping
Polygon Clipping
Sutherland-Hodgman
Example
t4 t3

t2 t1

t5
Clipping
Polygon Clipping
Sutherland-Hodgman
Example
u3 u2

u1 u5

u4
Clipping
Polygon Clipping
Sutherland-Hodgman
Example
v2 i3 v1
i6
v5 i5 v4
i4
v3
Clipping
Polygon Clipping
Sutherland-Hodgman
Example
w1 w6
w5
w4
w3
w2

You might also like