Clipping2

15
Polygon Polygon Clipping Clipping When a closed polygon is clipped as When a closed polygon is clipped as a collection of lines, the original a collection of lines, the original closed polygon becomes one or more closed polygon becomes one or more open polygons or discrete lines . open polygons or discrete lines . For polygon clipping we require an For polygon clipping we require an algorithm that will generate one or algorithm that will generate one or more closed areas. more closed areas. The output of a polygon clippers be The output of a polygon clippers be a sequence of vertices that defines a sequence of vertices that defines the clipped polygon boundary. the clipped polygon boundary.

Transcript of Clipping2

Page 1: Clipping2

Polygon ClippingPolygon ClippingWhen a closed polygon is clipped as a collection of When a closed polygon is clipped as a collection of lines, the original closed polygon becomes one or lines, the original closed polygon becomes one or more open polygons or discrete lines .more open polygons or discrete lines .For polygon clipping we require an algorithm that For polygon clipping we require an algorithm that will generate one or more closed areas.will generate one or more closed areas.The output of a polygon clippers be a sequence of The output of a polygon clippers be a sequence of vertices that defines the clipped polygon boundary.vertices that defines the clipped polygon boundary.

Page 2: Clipping2

Sutherland Hodgeman AlgorithmSutherland Hodgeman Algorithm We can correctly clip a polygon by processing a We can correctly clip a polygon by processing a

polygon boundary as a whole against each window polygon boundary as a whole against each window edge.edge.

This could be accomplished by processing all polygon This could be accomplished by processing all polygon vertices against each clip rectangle boundary.vertices against each clip rectangle boundary.

Beginning with the initial set of polygon vertices, we Beginning with the initial set of polygon vertices, we could first clip against the left rectangle boundary to could first clip against the left rectangle boundary to procedure a new sequence of vertices. procedure a new sequence of vertices.

Page 3: Clipping2

Sutherland Hodgeman AlgorithmSutherland Hodgeman Algorithm The new set of vertices could than be successively The new set of vertices could than be successively

passed to a right boundary clipper, a bottom boundary passed to a right boundary clipper, a bottom boundary clipper, & a top boundary clipper.clipper, & a top boundary clipper.

At each step a new sequence of output vertices is At each step a new sequence of output vertices is generated & passed to the next window boundary generated & passed to the next window boundary clipper.clipper.

These are four possible cases when processing These are four possible cases when processing vertices in sequence around the perimeter of a vertices in sequence around the perimeter of a polygon.polygon.

Page 4: Clipping2

Sutherland Hodgeman AlgorithmSutherland Hodgeman Algorithm

Left Clipper Right Clipper

Bottom Clipper

Top Clipper

Page 5: Clipping2

Sutherland Hodgeman AlgorithmSutherland Hodgeman Algorithm As each pair of adjacent polygon vertices is passed to a As each pair of adjacent polygon vertices is passed to a

window boundary clipper we make the following tests.window boundary clipper we make the following tests.

* If the first vertex is outside the window boundary * If the first vertex is outside the window boundary

& the second vertex is inside, the intersection & the second vertex is inside, the intersection

point of the polygon edge with the window point of the polygon edge with the window

boundary & the second vertex are added boundary & the second vertex are added

to the output vertex list.to the output vertex list.

V1 V2V1’

Out – InSave V1’, V2

Page 6: Clipping2

Sutherland Hodgeman AlgorithmSutherland Hodgeman Algorithm

* If both input vertices are inside the window * If both input vertices are inside the window

boundary only the second vertex is added to the boundary only the second vertex is added to the

output vertex list.output vertex list.

V1

V2

In – OutSave V2

Page 7: Clipping2

Sutherland Hodgeman AlgorithmSutherland Hodgeman Algorithm

* * If the vertex is inside the window boundary & the second vertex If the vertex is inside the window boundary & the second vertex is outside; only the edge intersection with the window is outside; only the edge intersection with the window

boundary is added to the output vertex listboundary is added to the output vertex list

V1 V2

In – OutSave V2’

V2’

Page 8: Clipping2

Sutherland Hodgeman AlgorithmSutherland Hodgeman Algorithm

* * If both input vertices are outside the window boundary, If both input vertices are outside the window boundary, nothing is added to the output list.nothing is added to the output list.

V1

V2

Save None

Page 9: Clipping2

Sutherland Hodgeman AlgorithmSutherland Hodgeman Algorithm

Left Edge ListLeft Edge List

a’bcdefghii’a’bcdefghii’

Right Edge ListRight Edge List

bcdd’e’fghii’a’bcdd’e’fghii’a’

Bottom Edge ListBottom Edge List

cdd’e’ff’h’ii’a’bcdd’e’ff’h’ii’a’b

Top Edge ListTop Edge List

c’dd’e’ff’h’ii’a’bb’c’dd’e’ff’h’ii’a’bb’

aa’ b

b’

c

c’

d d’ e

e’f

f’

gh

h’

ii’

Page 10: Clipping2

Sutherland Hodgeman AlgorithmSutherland Hodgeman Algorithm

Convex polygon are correctly clipped by the Convex polygon are correctly clipped by the Sutherland-Hodgeman algorithm but concave Sutherland-Hodgeman algorithm but concave polygon may be displayed with extraneous lines.polygon may be displayed with extraneous lines.

This is occur when the clipped polygon should have This is occur when the clipped polygon should have two or more separate section.two or more separate section.

Since there is only one output vertex list, the last Since there is only one output vertex list, the last vertex in the list is always joined to the first vertex vertex in the list is always joined to the first vertex listlist

Page 11: Clipping2

Weiler-Atherlton Polygon Weiler-Atherlton Polygon ClippingClipping

In this method, vertex processing procedures for In this method, vertex processing procedures for window boundaries are modified so that concave window boundaries are modified so that concave polygons are displayed correctly.polygons are displayed correctly.

This clipping procedure was developed as a method This clipping procedure was developed as a method for identifying visible surfaces, & so it can be applied for identifying visible surfaces, & so it can be applied with arbitrary polygon clipping regions.with arbitrary polygon clipping regions.

The basic idea in this algorithm is that instead of The basic idea in this algorithm is that instead of always processing around the polygon edges as always processing around the polygon edges as vertices are processed, we some times want to follow vertices are processed, we some times want to follow the window boundaries.the window boundaries.

Page 12: Clipping2

Weiler-Atherlton Polygon Weiler-Atherlton Polygon ClippingClipping

Which path we follow depends on the polygon Which path we follow depends on the polygon processing directions (clockwise or counter processing directions (clockwise or counter clockwise) & whether the pair of polygon vertices clockwise) & whether the pair of polygon vertices currently being processed represented an currently being processed represented an outside to outside to insideinside pair or an pair or an inside to outsideinside to outside pair. pair.

For an outside to inside pair of vertices, follow the For an outside to inside pair of vertices, follow the polygon boundary.polygon boundary.

For an inside to outside pair of vertices, follow the For an inside to outside pair of vertices, follow the window boundary in a clockwise direction.window boundary in a clockwise direction.

Page 13: Clipping2

Weiler-Atherlton Polygon Weiler-Atherlton Polygon ClippingClipping

Concave PolygonConcave Polygon

V1 V1’ V2

V3V3’V4

V4’

V5V5’V6

Page 14: Clipping2

Weiler-Atherlton Polygon ClippingWeiler-Atherlton Polygon Clipping

c1

c2 c3

c4

s1

s2

s3s4

s5

s6s7

I1

I2

I3 I4

I5

I6

I7I8

Subject Polygon

Clip Polygon

Page 15: Clipping2

Weiler-Atherlton Polygon Weiler-Atherlton Polygon ClippingClipping

Subject Polygon ListSubject Polygon List Clip Polygon List Clip Polygon List s1s1 c1c1

I2I2 I1I1I3I3 I2I2s2s2 c2c2I4I4 I3I3s3s3 I4I4I5I5 c3c3s4s4 I5I5I6I6 I6I6I7I7 c4c4s5s5 I7I7I8I8 I8I8s6s6 c1c1I1I1s7s7s1s1