Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
10CSL67 CG LAB PROGRAM 9
1. PROGRAM 9
Program to fill any given polygon using scan-line area
filling algorithms. (Use appropriate data structures.)
2. Scanline Fill Algorithm
• Intersect scanline with polygon edges.
• Fill between pairs of intersections
Basic Structure:
For y=Ymin to Ymax
1) intersect scanline with each edge
2) sort intersections by increasing X
3) fill pairwise ( int0-> int1, int2->int3, ... )
11. void main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(300,300);
glutCreateWindow("Filling a Polygon using Scan-line Algorithm");
glutDisplayFunc(display);
myinit();
glutMainLoop();
}
12. Activity 9
1. Change the shape of the polygon (know the difference
between concave and convex polygon).
Convex polygon
• A convex polygon is a multi-angled shape with straight
sides in which all of the angles are < 1800.
• A line drawn through a convex polygon will intersect the
sides of the polygon exactly twice.
15. Concave polygon
• A concave polygon is a multi-angled shape with straight
sides in which all of the angles are > 1800.
• A line drawn through a convex polygon will intersect
the sides of the polygon exactly twice.
• Concave polygons are polygons for which atleast one
line segment joining any two points in the interior does
not lie completely within the figure.
16. Try this ……
x1=100.0; y1=100.0;
x2=50.0; y2=200.0;
x3=150.0; y3=150.0;
x4=250.0; y4=200.0;
x5=200; y5=100;
Scanline fill algorithm works only for convex polygons,
hence the sides making 1800 are ignored till the
polygon becomes convex and then it is filled with the
pixels.
x1, y1
x2, y2
x3, y3
x4, y4
x5, y5