You are on page 1of 9

Clipping Polygons

Clipping polygons is more complex than clipping the individual lines Input: polygon Output: original polygon, new polygon, or nothing When can we trivially accept/reject a polygon as opposed to the line segments that make up the polygon?

Sutherland Hodgeman algorithms Weiler Atherton algorithms

Nihar Ranjan Roy

Why Is Clipping Hard?


What happens to a triangle during clipping? Possible outcomes:

How many sides?


Seven

triangle

triangle

triangle

quad

triangle

5-gon

How many sides can a clipped triangle have?


Nihar Ranjan Roy

Nihar Ranjan Roy

Page 1

Why Is Clipping Hard?


A really tough case:

Why Is Clipping Hard?


A really tough case:

concave polygon

multiple polygons

Nihar Ranjan Roy

Nihar Ranjan Roy

Sutherland-Hodgeman Clipping
Basic idea: Consider each edge of the viewport individually Clip the polygon against the viewport edges equation

Sutherland-Hodgeman Clipping
Basic idea:
Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Nihar Ranjan Roy

Nihar Ranjan Roy

Page 2

Sutherland-Hodgeman Clipping
Basic idea:
Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Sutherland-Hodgeman Clipping
Basic idea:
Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Nihar Ranjan Roy

Nihar Ranjan Roy

10

Sutherland-Hodgeman Clipping
Basic idea:
Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Sutherland-Hodgeman Clipping
Basic idea:
Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Nihar Ranjan Roy

11

Nihar Ranjan Roy

12

Page 3

Sutherland-Hodgeman Clipping
Basic idea:
Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Sutherland-Hodgeman Clipping
Basic idea:
Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Nihar Ranjan Roy

13

Nihar Ranjan Roy

14

Sutherland-Hodgeman Clipping
Basic idea:
Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Sutherland-Hodgeman Clipping:
Basic idea:
Consider each edge of the viewport individually Clip the polygon against the edge equation After doing all edges, the polygon is fully clipped

Nihar Ranjan Roy

15

Nihar Ranjan Roy

16

Page 4

Sutherland-Hodgeman Clipping

Input/output for algorithm: Input: list of polygon vertices in order Output: list of clipped poygon vertices consisting of old vertices (maybe) and new vertices (maybe) Note: this is exactly what we expect from the clipping operation against each edge

Sutherland-Hodgeman Clipping
Sutherland-Hodgman basic routine: Go around polygon one vertex at a time Current vertex has position p Previous vertex had position s, and it has been added to the output if appropriate

Nihar Ranjan Roy

17

Nihar Ranjan Roy

18

Sutherland-Hodgeman Clipping
Edge from s to p takes one of four cases:
(Orange line can be a line or a plane)
outside inside outside

Sutherland-Hodgeman Clipping
3

inside

inside

outside

inside

outside

p s

2 4 1 6

p
p output

s
i output

p
no output

s
i output p output

Nihar Ranjan Roy

19

Nihar Ranjan Roy

20

Page 5

Sutherland-Hodgeman Clipping
3

Sutherland-Hodgeman Clipping
3 2` 2 1` 4 1 6

2 4 1 6 5

Nihar Ranjan Roy

21

Nihar Ranjan Roy

22

Sutherland-Hodgeman Clipping
3 2` 2 1 6 5` 4` 5 1` 3` 4

Sutherland-Hodgeman Clipping
2` 1` 3` 5` 4`

Nihar Ranjan Roy

23

Nihar Ranjan Roy

24

Page 6

Weiler Atherton polygon clipping Rule


Walk around the Polygon/window Boundary
(it depends on the direction of traversing)

Weiler Atherton polygon clipping Rule


Calculate the intersection points and mark the points where the polygon enters the window with green color

Here assume that polygons are oriented counter clock wise

Nihar Ranjan Roy

25

Nihar Ranjan Roy

26

Weiler Atherton polygon clipping Rule


Walking rules Out to inside Store the clipped point Follow the polygon boundary (CCW) Inside to outside Store the clipped point Follow the window boundary

Weiler Atherton polygon clipping Rule


Walking rules Out to inside Store the clipped point Follow the polygon boundary (CCW) Inside to outside Store the clipped point Follow the window boundary

Nihar Ranjan Roy

27

Nihar Ranjan Roy

28

Page 7

Weiler Atherton polygon clipping Rule


Walking rules Out to inside Store the clipped point Follow the polygon boundary (CCW) Inside to outside Store the clipped point Follow the window boundary

Weiler Atherton polygon clipping Rule


Walking rules Out to inside Store the clipped point Follow the polygon boundary (CCW) Inside to outside Store the clipped point Follow the window boundary

Nihar Ranjan Roy

29

Nihar Ranjan Roy

30

Weiler Atherton polygon clipping Rule


Walking rules Out to inside Store the clipped point Follow the polygon boundary (CCW) Inside to outside Store the clipped point Follow the window boundary

Comparison of the two techniques

Nihar Ranjan Roy

31

Nihar Ranjan Roy

32

Page 8

Comparison of the two techniques


Sutherland Hodgeman

Comparison of the two techniques


Sutherland Hodgeman

Weiler Atherton

Nihar Ranjan Roy

33

Nihar Ranjan Roy

34

Comparison of the two techniques


Sutherland Hodgeman

Weiler Atherton

Nihar Ranjan Roy

35

Page 9

You might also like