For each scan line crossing a polygon, the area-fill algorithm locates the intersection points of the scan line with the polygon edges. These intersection points are then sorted from left to right, and the corresponding frame-buffer positions between each intersection pair are set to the specified fill color. Scan line algorithm works by intersecting scan line 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 Fig. 2.21 shown, 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.