Professional Documents
Culture Documents
Introduction
Types of Polygons
1
Introduction
2
Filled Area Primitives
Types of Polygons
The classification of polygons is based on where the line
segment joining any two points within the polygon is going to
lie. There are two types of polygons:
•Convex
•Concave
A Convex polygon is a polygon in which the line segment
joining any two points within the polygon lies completely
inside the polygon.
A Concave polygon is a polygon in which the line segment
joining any two points within the polygon may not lie
completely inside the polygon.
3
Inside and Outside Test
Once the polygon is entered in the display file, we can draw the
outline of the polygon. To show polygon as a solid object we have
to set the pixels inside the polygon as well as pixels on the
boundary of it.
Now, the question is how to determine
whether or not a point is inside of a
polygon.
One simple method is to construct a line segment between the
point in question and a point known to be outside the polygon.
Now, count how many intersections of the line segment with the
polygon boundary occur. If there are an odd number of
intersections, then the point in question is inside, otherwise it is
outside.
This method is called even-odd method of determining polygon
inside points
4
Inside and Outside Test
If they lie on opposite sides of the constructed line, then the point
is counted as a single intersection.
5
Filling Polygon
6
Filling Polygon
Filling the polygon means highlighting all the pixels which lie
inside the polygon with any colour other than background
colour. Polygons are easier to fill since they have linear
boundaries.
7
Filling Polygon
8
Boundary Fill Algorithm
9
Boundary Fill Algorithm
10
Boundary Fill Algorithm
11
Boundary Fill Algorithm
• The following procedure illustrates a recursive method for
filling a 4-connected area with an intensity specified in
parameter fill up to a boundary color specified with
parameter boundary.
• We can extend this procedure to fill an 8-connected region
by including four additional statements to test diagonal
positions, such is (x + 1, y + 1).
12
Boundary Fill Algorithm
13
Boundary Fill Algorithm
14
Boundary Fill Algorithm
15
Flood Fill Algorithm
16
Flood Fill Algorithm
17
Scan Line Algorithm
18
Scan Line Algorithm
19
Scan Line Algorithm
Basic algorithm:
– Assume scan line start from the left and is outside the
polygon.
– When intersect an edge of polygon, start to color each
pixel (because now we’re inside the polygon), when
intersect another edge, stop coloring …
– Odd number of edges: inside
– Even number of edges: outside
20
End of Lecture
End of Lecture
21
Acknowledgements
22