0% found this document useful (0 votes)
61 views3 pages

Polygon Filling Algorithm

The document discusses two algorithms for filling polygons: the scan line algorithm which works by intersecting a scan line with polygon edges and filling between pairs of intersections, and the flood fill algorithm which replaces the interior color of an object with a fill color by looking for all adjacent pixels of the interior color.

Uploaded by

Nancy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views3 pages

Polygon Filling Algorithm

The document discusses two algorithms for filling polygons: the scan line algorithm which works by intersecting a scan line with polygon edges and filling between pairs of intersections, and the flood fill algorithm which replaces the interior color of an object with a fill color by looking for all adjacent pixels of the interior color.

Uploaded by

Nancy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Polygon Filling Algorithm

Advertisement

Polygon is an ordered list of vertices as shown in the following figure. For filling polygons with
particular colors, you need to determine the pixels falling on the border of the polygon and those
which fall inside the polygon. In this chapter, we will see how we can fill polygons using different
techniques.

Scan Line Algorithm

This algorithm works by intersecting scanline with polygon edges and fills the polygon between
pairs of intersections. The following steps depict how this algorithm works.

Step 1 − Find out the Ymin and Ymax from the given polygon.
Step 2 − ScanLine intersects with each edge of the polygon from Ymin to Ymax. Name each
intersection point of the polygon. As per the figure shown above, they are named as p0, p1, p2, p3.

Step 3 − Sort the intersection point in the increasing order of X coordinate i.e. p0, p1 , p1, p2 ,

and p2, p3 .

Step 4 − Fill all those pair of coordinates that are inside polygons and ignore the alternate pairs.
ADVERTISEMENT

ADVERTISEMENT

Flood Fill Algorithm

Sometimes we come across an object where we want to fill the area and its boundary with
different colors. We can paint such objects with a specified interior color instead of searching for
particular boundary color as in boundary filling algorithm.
Instead of relying on the boundary of the object, it relies on the fill color. In other words, it replaces
the interior color of the object with the fill color. When no more pixels of the original interior color
exist, the algorithm is completed.

Once again, this algorithm relies on the Four-connect or Eight-connect method of filling in the
pixels. But instead of looking for the boundary color, it is looking for all adjacent pixels that are a
part of the interior.

ADVERTISEMENT

ADVERTISEMENT

You might also like