EXPERIMENT NO- 6
EXPERIMENT NO- 6
AIM: To implement the Scan line polygon fill algorithm for coloring a given object.
RESOURCES REQUIRED:
H/W Requirements: RAM 128MB, Printers and Cartridges, Print Out Stationary
S/W Requirements: Turbo C / C++ compiler that supports graphics.h package.
THEORY:
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.
This algorithm works by intersecting scanlines with polygon edges and fills the
polygon between
pairs of intersections. The following steps depict how this algorithm works.
Scan Line Algorithm:
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 pairs of coordinates that are inside polygons and ignore the
alternate pairs.