SlideShare a Scribd company logo
1 of 16
Download to read offline
PROGRAM 9
Program to fill any given polygon using scan-line area
filling algorithms. (Use appropriate data structures.)
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, ... )
Scanline Fill Algorithm Example
+X
+Y
P1
5, 10
P2
20, 15
P3
15, 25
P4
0, 20
Scanline Fill Algorithm Example
+X
+Y
P1
5, 10
P2
20, 15
P3
15, 25
P4
0, 20
Line
No.
Points Y co-ordinates Le Re
L1 P1 - P2 10 - 15 5 20
L2 P2 - P3 15 - 25 20 15
L3 P3 - P4 25 - 20 swap 20 - 25 0 15
L4 P4 - P1 20 - 10 swap 10 - 20 5 0
Scanline Fill Algorithm Example
+X
+Y
P1 5, 10
P2 20, 15
P3 15, 25
P4 0, 20
Line
No.
Points Y co-
ordinates
Le Re
L1 P1 - P2 10 - 15 Le[10]=5 Le[15]=20 Re[10]=5 Re[15]=20
L2 P2 - P3 15 - 25 Le[15]=20 Le[25]=15 Re[15]=20 Re[25]=15
L3 P3 - P4 20 – 25 Le[20]=0 Le[25]=15 Re[20]=17.5 Re[25]=15
L4 P4 - P1 10 – 20 Le[10]=5 Le[20]=0 Re[10]=5 Re[20]=17.5
#include <GL/glut.h>
float x1, x2, x3, x4, y1, y2, y3, y4;
void edgedetect(float x1,float y1,float x2,float y2,int *le,int *re)
{
float mx, x, temp;
int i;
if((y2-y1)<0) // if(y2<y1)
{ temp=y1; y1=y2; y2=temp; // swap y1 & y2
temp=x1; x1=x2; x2=temp; // swap x1 & x2
}
if((y2-y1)!=0) // if(y2!=y1)
mx=(x2-x1)/(y2-y1);
else
mx=x2-x1;
x=x1;
for(i=y1;i<=y2;i++)
{
if(x<(float)le[i])
le[i]=(int)x;
if(x>(float)re[i])
re[i]=(int)x;
x+=mx;
}
}
void draw_pixel(int x,int y)
{
glColor3f(1.0,0.0,0.0);
glBegin(GL_POINTS);
glVertex2i(x,y);
glEnd();
glFlush(); // filling points with delay
}
void scanfill (float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4)
{
int le[500],re[500],i,y;
for(i=0;i<500;i++)
{
le[i]=500;
re[i]=0;
}
edgedetect(x1,y1,x2,y2,le,re);
edgedetect(x2,y2,x3,y3,le,re);
edgedetect(x3,y3,x4,y4,le,re);
edgedetect(x4,y4,x1,y1,le,re);
+X
+Y
P1 5, 10
P2 20, 15
P3 15, 25
P4 0, 20
for(y=0;y<500;y++)
{
if(le[y]<=re[y])
for(i=(int)le[y];i<(int)re[y];i++)
draw_pixel(i,y);
}
}
void display()
{ x1=300.0; y1=200.0;
x2=100.0; y2=300.0;
x3=200.0; y3=400.0;
x4=300.0; y4=300.0;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_LINE_LOOP);
glVertex2f(x1,y1); glVertex2f(x2,y2);
glVertex2f(x3,y3); glVertex2f(x4,y4);
glEnd();
P1 300, 200
P2 100, 300
P3 200, 400
P4 300, 300
scanfill(x1,y1,x2,y2,x3,y3,x4,y4);
glFlush();
}
void myinit()
{
glClearColor(1.0,1.0,1.0,1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,499.0,0.0,499.0);
}
P1 300, 200
P2 100, 300
P3 200, 400
P4 300, 300
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();
}
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.
void display()
{
x1=100.0; y1=100.0;
x2=50.0; y2=200.0;
x3=150.0; y3=300.0;
x4=250.0; y4=200.0;
x5=200; y5=100;
----
----
glBegin(GL_LINE_LOOP);
glVertex2f(x1,y1);
glVertex2f(x2,y2);
glVertex2f(x3,y3);
glVertex2f(x4,y4);
glVertex2f(x5,y5);
glEnd();
scanfill(x1,y1,x2,y2,x3,y3,x4,y4,x5,y5);
glFlush();
}
void scanfill(float x1,float y1,float x2,float y2,float x3,float y3,float
x4,float y4,float x5, float y5)
{
----
----
edgedetect(x1,y1,x2,y2,le,re);
edgedetect(x2,y2,x3,y3,le,re);
edgedetect(x3,y3,x4,y4,le,re);
edgedetect(x4,y4,x5,y5,le,re);
edgedetect(x5,y5,x1,y1,le,re);
----
----
}
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.
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

More Related Content

What's hot

Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesAnkit Garg
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesOmprakash Chauhan
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmNeha Kaurav
 
Bressenham’s Midpoint Circle Drawing Algorithm
Bressenham’s Midpoint Circle Drawing AlgorithmBressenham’s Midpoint Circle Drawing Algorithm
Bressenham’s Midpoint Circle Drawing AlgorithmMrinmoy Dalal
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.Mohd Arif
 
Mid point circle algorithm
Mid point circle algorithmMid point circle algorithm
Mid point circle algorithmMani Kanth
 
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSEAU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSEThiyagarajan G
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer GraphicsKamal Acharya
 
Lesson 1 Feb 10 2010
Lesson 1 Feb 10 2010Lesson 1 Feb 10 2010
Lesson 1 Feb 10 2010ingroy
 
Mate ejercicios de factorización por binomio - 2º
Mate   ejercicios de factorización por binomio - 2ºMate   ejercicios de factorización por binomio - 2º
Mate ejercicios de factorización por binomio - 2ºbrisagaela29
 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivationMazharul Islam
 
Reed Solomon encoder and decoder \ ريد سلمون
Reed Solomon encoder and decoder \ ريد سلمونReed Solomon encoder and decoder \ ريد سلمون
Reed Solomon encoder and decoder \ ريد سلمونMuhammed Abdulmahdi
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
Finite elements : basis functions
Finite elements : basis functionsFinite elements : basis functions
Finite elements : basis functionsTarun Gehlot
 
數學測試
數學測試數學測試
數學測試s9007912
 
Max and min trig values
Max and min trig valuesMax and min trig values
Max and min trig valuesShaun Wilson
 

What's hot (20)

Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniques
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing Algorithm
 
Bressenham’s Midpoint Circle Drawing Algorithm
Bressenham’s Midpoint Circle Drawing AlgorithmBressenham’s Midpoint Circle Drawing Algorithm
Bressenham’s Midpoint Circle Drawing Algorithm
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
 
Mid point circle algorithm
Mid point circle algorithmMid point circle algorithm
Mid point circle algorithm
 
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSEAU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
AU QP Answer key NOv/Dec 2015 Computer Graphics 5 sem CSE
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
Matlab file
Matlab file Matlab file
Matlab file
 
Lesson 1 Feb 10 2010
Lesson 1 Feb 10 2010Lesson 1 Feb 10 2010
Lesson 1 Feb 10 2010
 
Quadratic
QuadraticQuadratic
Quadratic
 
2.circle
2.circle2.circle
2.circle
 
Mate ejercicios de factorización por binomio - 2º
Mate   ejercicios de factorización por binomio - 2ºMate   ejercicios de factorización por binomio - 2º
Mate ejercicios de factorización por binomio - 2º
 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivation
 
Reed Solomon encoder and decoder \ ريد سلمون
Reed Solomon encoder and decoder \ ريد سلمونReed Solomon encoder and decoder \ ريد سلمون
Reed Solomon encoder and decoder \ ريد سلمون
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Finite elements : basis functions
Finite elements : basis functionsFinite elements : basis functions
Finite elements : basis functions
 
數學測試
數學測試數學測試
數學測試
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Max and min trig values
Max and min trig valuesMax and min trig values
Max and min trig values
 

Viewers also liked

Viewers also liked (20)

Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Lecture filling algorithms
Lecture  filling algorithmsLecture  filling algorithms
Lecture filling algorithms
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fill
 
region-filling
region-fillingregion-filling
region-filling
 
Julieta Sieyra - CV Especialidades
Julieta Sieyra - CV EspecialidadesJulieta Sieyra - CV Especialidades
Julieta Sieyra - CV Especialidades
 
Engineering Math
Engineering MathEngineering Math
Engineering Math
 
regularized boolean set operations
regularized boolean set operationsregularized boolean set operations
regularized boolean set operations
 
Area filling algo
Area filling algoArea filling algo
Area filling algo
 
Numerical method (curve fitting)
Numerical method (curve fitting)Numerical method (curve fitting)
Numerical method (curve fitting)
 
Fill area algorithms
Fill area algorithmsFill area algorithms
Fill area algorithms
 
Curve fitting
Curve fittingCurve fitting
Curve fitting
 
Statistics for Engineers
Statistics for EngineersStatistics for Engineers
Statistics for Engineers
 
Introduction to solid modeling
Introduction to solid modelingIntroduction to solid modeling
Introduction to solid modeling
 
Curve fitting
Curve fitting Curve fitting
Curve fitting
 
Engineering Mathematics-IV_B.Tech_Semester-IV_Unit-I
Engineering Mathematics-IV_B.Tech_Semester-IV_Unit-IEngineering Mathematics-IV_B.Tech_Semester-IV_Unit-I
Engineering Mathematics-IV_B.Tech_Semester-IV_Unit-I
 
Probability and statistics
Probability and statisticsProbability and statistics
Probability and statistics
 
Probability and statistics (basic statistical concepts)
Probability and statistics (basic statistical concepts)Probability and statistics (basic statistical concepts)
Probability and statistics (basic statistical concepts)
 
Solid modelling cg
Solid modelling cgSolid modelling cg
Solid modelling cg
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 

Similar to 10CSL67 CG LAB PROGRAM 9

Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and PolynomialAroosa Rajput
 
Lowest common ancestor
Lowest common ancestorLowest common ancestor
Lowest common ancestorShakil Ahmed
 
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscationguest9006ab
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
A/B Testing for Game Design
A/B Testing for Game DesignA/B Testing for Game Design
A/B Testing for Game DesignTrieu Nguyen
 
Frsa
FrsaFrsa
Frsa_111
 
Open GL 09 scan conversion
Open GL 09 scan conversionOpen GL 09 scan conversion
Open GL 09 scan conversionRoziq Bahtiar
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
An Algorithm to Find the Visible Region of a Polygon
An Algorithm to Find the Visible Region of a PolygonAn Algorithm to Find the Visible Region of a Polygon
An Algorithm to Find the Visible Region of a PolygonKasun Ranga Wijeweera
 
Output Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and MultimediaOutput Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and Multimediasaranyan75
 
Computer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivesComputer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivessaranyan75
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4Roziq Bahtiar
 
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing DesignV Tripathi
 

Similar to 10CSL67 CG LAB PROGRAM 9 (20)

Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
Lowest common ancestor
Lowest common ancestorLowest common ancestor
Lowest common ancestor
 
Palm ch1
Palm ch1Palm ch1
Palm ch1
 
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscation
 
Struct examples
Struct examplesStruct examples
Struct examples
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
A/B Testing for Game Design
A/B Testing for Game DesignA/B Testing for Game Design
A/B Testing for Game Design
 
Frsa
FrsaFrsa
Frsa
 
Array
ArrayArray
Array
 
Open GL 09 scan conversion
Open GL 09 scan conversionOpen GL 09 scan conversion
Open GL 09 scan conversion
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
An Algorithm to Find the Visible Region of a Polygon
An Algorithm to Find the Visible Region of a PolygonAn Algorithm to Find the Visible Region of a Polygon
An Algorithm to Find the Visible Region of a Polygon
 
Klmpk matik
Klmpk matikKlmpk matik
Klmpk matik
 
Klmpk matik
Klmpk matikKlmpk matik
Klmpk matik
 
C programs
C programsC programs
C programs
 
Output Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and MultimediaOutput Primitives in Computer Graphics and Multimedia
Output Primitives in Computer Graphics and Multimedia
 
Computer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivesComputer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitives
 
Open GL T0074 56 sm4
Open GL T0074 56 sm4Open GL T0074 56 sm4
Open GL T0074 56 sm4
 
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing Design
 
Cs580
Cs580Cs580
Cs580
 

More from Vanishree Arun

10CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 1010CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 10Vanishree Arun
 
10CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 810CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 8Vanishree Arun
 
10CSL67 CG LAB PROGRAM 7
10CSL67 CG LAB PROGRAM 710CSL67 CG LAB PROGRAM 7
10CSL67 CG LAB PROGRAM 7Vanishree Arun
 
10CSL67 CG LAB PROGRAM 6
10CSL67 CG LAB PROGRAM 610CSL67 CG LAB PROGRAM 6
10CSL67 CG LAB PROGRAM 6Vanishree Arun
 
10CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 510CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 5Vanishree Arun
 
10CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 310CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 3Vanishree Arun
 
10CSL67 CG LAB PROGRAM 2
 10CSL67 CG LAB PROGRAM 2 10CSL67 CG LAB PROGRAM 2
10CSL67 CG LAB PROGRAM 2Vanishree Arun
 
10CSL67 CG LAB PROGRAM 1
10CSL67 CG LAB PROGRAM 110CSL67 CG LAB PROGRAM 1
10CSL67 CG LAB PROGRAM 1Vanishree Arun
 

More from Vanishree Arun (8)

10CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 1010CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 10
 
10CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 810CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 8
 
10CSL67 CG LAB PROGRAM 7
10CSL67 CG LAB PROGRAM 710CSL67 CG LAB PROGRAM 7
10CSL67 CG LAB PROGRAM 7
 
10CSL67 CG LAB PROGRAM 6
10CSL67 CG LAB PROGRAM 610CSL67 CG LAB PROGRAM 6
10CSL67 CG LAB PROGRAM 6
 
10CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 510CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 5
 
10CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 310CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 3
 
10CSL67 CG LAB PROGRAM 2
 10CSL67 CG LAB PROGRAM 2 10CSL67 CG LAB PROGRAM 2
10CSL67 CG LAB PROGRAM 2
 
10CSL67 CG LAB PROGRAM 1
10CSL67 CG LAB PROGRAM 110CSL67 CG LAB PROGRAM 1
10CSL67 CG LAB PROGRAM 1
 

Recently uploaded

Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 

Recently uploaded (20)

Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
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, ... )
  • 3. Scanline Fill Algorithm Example +X +Y P1 5, 10 P2 20, 15 P3 15, 25 P4 0, 20
  • 4. Scanline Fill Algorithm Example +X +Y P1 5, 10 P2 20, 15 P3 15, 25 P4 0, 20 Line No. Points Y co-ordinates Le Re L1 P1 - P2 10 - 15 5 20 L2 P2 - P3 15 - 25 20 15 L3 P3 - P4 25 - 20 swap 20 - 25 0 15 L4 P4 - P1 20 - 10 swap 10 - 20 5 0
  • 5. Scanline Fill Algorithm Example +X +Y P1 5, 10 P2 20, 15 P3 15, 25 P4 0, 20 Line No. Points Y co- ordinates Le Re L1 P1 - P2 10 - 15 Le[10]=5 Le[15]=20 Re[10]=5 Re[15]=20 L2 P2 - P3 15 - 25 Le[15]=20 Le[25]=15 Re[15]=20 Re[25]=15 L3 P3 - P4 20 – 25 Le[20]=0 Le[25]=15 Re[20]=17.5 Re[25]=15 L4 P4 - P1 10 – 20 Le[10]=5 Le[20]=0 Re[10]=5 Re[20]=17.5
  • 6. #include <GL/glut.h> float x1, x2, x3, x4, y1, y2, y3, y4; void edgedetect(float x1,float y1,float x2,float y2,int *le,int *re) { float mx, x, temp; int i; if((y2-y1)<0) // if(y2<y1) { temp=y1; y1=y2; y2=temp; // swap y1 & y2 temp=x1; x1=x2; x2=temp; // swap x1 & x2 } if((y2-y1)!=0) // if(y2!=y1) mx=(x2-x1)/(y2-y1); else mx=x2-x1; x=x1;
  • 7. for(i=y1;i<=y2;i++) { if(x<(float)le[i]) le[i]=(int)x; if(x>(float)re[i]) re[i]=(int)x; x+=mx; } } void draw_pixel(int x,int y) { glColor3f(1.0,0.0,0.0); glBegin(GL_POINTS); glVertex2i(x,y); glEnd(); glFlush(); // filling points with delay }
  • 8. void scanfill (float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4) { int le[500],re[500],i,y; for(i=0;i<500;i++) { le[i]=500; re[i]=0; } edgedetect(x1,y1,x2,y2,le,re); edgedetect(x2,y2,x3,y3,le,re); edgedetect(x3,y3,x4,y4,le,re); edgedetect(x4,y4,x1,y1,le,re); +X +Y P1 5, 10 P2 20, 15 P3 15, 25 P4 0, 20
  • 9. for(y=0;y<500;y++) { if(le[y]<=re[y]) for(i=(int)le[y];i<(int)re[y];i++) draw_pixel(i,y); } } void display() { x1=300.0; y1=200.0; x2=100.0; y2=300.0; x3=200.0; y3=400.0; x4=300.0; y4=300.0; glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0, 0.0, 1.0); glBegin(GL_LINE_LOOP); glVertex2f(x1,y1); glVertex2f(x2,y2); glVertex2f(x3,y3); glVertex2f(x4,y4); glEnd(); P1 300, 200 P2 100, 300 P3 200, 400 P4 300, 300
  • 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.
  • 13. void display() { x1=100.0; y1=100.0; x2=50.0; y2=200.0; x3=150.0; y3=300.0; x4=250.0; y4=200.0; x5=200; y5=100; ---- ---- glBegin(GL_LINE_LOOP); glVertex2f(x1,y1); glVertex2f(x2,y2); glVertex2f(x3,y3); glVertex2f(x4,y4); glVertex2f(x5,y5); glEnd(); scanfill(x1,y1,x2,y2,x3,y3,x4,y4,x5,y5); glFlush(); }
  • 14. void scanfill(float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4,float x5, float y5) { ---- ---- edgedetect(x1,y1,x2,y2,le,re); edgedetect(x2,y2,x3,y3,le,re); edgedetect(x3,y3,x4,y4,le,re); edgedetect(x4,y4,x5,y5,le,re); edgedetect(x5,y5,x1,y1,le,re); ---- ---- }
  • 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