The scanline fill algorithm is designed to determine the interior parts of a polygon in a rendered image. The algorithm scans the image from top to bottom by avoiding the need to perform complex and time-consuming point-in polygon tests. It has significant applications in rendering engines, games, and 3D modeling tools.
The scanline fill algorithm works with lines (one at a time).
It intersects each line with all polygon edges and determines which intersections are entry or exit points.
The spans between entry and exit points are filled in.
It then processes the polygon line by line, from the defined minimum to maximum y-values.
The
Each entry in the edge table contains the data such as the lowest
The
As we move from one line to the next, we add edges from the ET to the AET when we reach their
The edges in the AET are then sorted by their current
Repeat until the ET and AET are empty.
Move any edges from the ET to the AET where,
Sort the AET on
Fill the desired pixels on the scanline y using pairs of x coordinates from the AET.
Increment
Remove edges from AET where
Update each edge's
Repeat the process.
Case 1:
Intersection is the point where the two edges of the lines meet.
In this diagram,
If we compute the intersection of the scanline with the edge
In order to correctly fill in the shape, we need to count the intersection point twice. Keep both of the points
Case 2:
If we count
In order to fill it up correctly, do not count
Note: A simple solution to handle the cases mentioned above, is to check if the intersection is the
or of both the edge's endpoint. If it is, we count it twice, otherwise, we count it only once.