SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Polygon (Definition)
1
Polygon is a figure having many slides. It may be represented as a number of line segments end to end to form a
closed figure.
The line segments which form the boundary of polygon are called as edges or slides of polygon.
The end of the side are called the polygon vertices.
Triangle is the most simple form of polygon having three side and three vertices.
The polygon may be of any shape.
Types of Polygon
2
1. Convex
2. Concave
3. Complex
Convex
3
Convex polygon is a polygon in which if we take any points which are
surely inside the polygon and if we draw a joining these two points and
if all the points on that line lies into the polygon, then such a polygon is
called as convex polygon.
Concave
4
Concave polygon is a polygon in which if we take any two points which are
surely inside the polygon and if we draw a line joining these two points and
if all the points on that line are not lying inside the polygon, then such a
polygon is called as concave polygon.
Complex
5
In a computer graphics, a polygon which is neither convex nor concave is
referred as complex polygons.
The complex polygon includes any polygon which intersects itself of the
polygon which overlaps itself.
The complex polygon has a boundary.
Polygon Representation
6
OP X Y
6 5 5
2 7 5
2 9 3
2 7 1
2 5 1
2 3 3
2 5 5
A(5,5)
F(3,3)
E(5,1) D(7,1)
B(7,5)
C(9,3)
Inside Test Methods
7
1. Even-odd Method
2. Winding Number Method
Even - Odd Methods
8
x4,y4
x3,y3
x2,y2
x1,y1 Count even
Outside
Point ‘B’
A
Fig. 3.2.2
Fig. 3.2.3 Fig. 3.2.4
Outside
Point ‘B’
AC
Count Odd
Fig. 3.2.5
ACB
A
B C D A
Winding Number Methods
9
1
-1 1
Fig. 3.2.7
Fig. 3.2.8
Fig. 3.2.9
AB
C
1
Newly
drawn line
+1 -1
DC
B A
Winding Number Methods
10
Fig. 3.2.10 (c)
Fig. 3.2.10 (a) Fig. 3.2.10 (b)
-1
-1+1
D
AB
C
Case I
Case II
Case III
B
C
A
D
-1
-1+1
B
C D
A
-1-1
+1
Polygon Filling
11
Polygon Filling
Algorithm
1. Boundary Fill Algorithm
2. Flood Fill (Seed Fill) Algorithm
3. Edge Fill Algorithm
4. Fence Fill Algorithm
1. Scan Line Algorithm
Pixel Level Geometric Level
4-connected Method
12
In this 4 neighboring points of a current test point are tested.
These are pixel positions that are right, left, above and below of current pixels as shown in figure 2.26
8-connected Method
Here 8 neighboring pixels of current test pixel are tested.
These pixel positions are left, right, above and 4 – diagonal positions of current pixel as shown in figure
2.27
Boundary Fill Algorithm
13
bfill (x, y, newcolor)
{
current = getpixel (x, y);
if (current != newcolor)) && (current != boundarycolor)
{
putpixel (x, y, newcolor);
bfill (x+1, y, newcolor);
bfill (x-1, y, newcolor);
bfill (x, y+1, newcolor);
bfill (x, y-1, newcolor);
}
}
The following procedure illustrate a recursive method for boundary fill by using 4-connected method.
Flood Fill (Seed fill) Algorithm
14
F-fill (x, y, newcolor)
{ current = getpixel (x, y);
if (current != newcolor)
{ putpixel (x, y, newcolor);
f-fill (x-1, y, newcolor);
f-fill (x+1, y, newcolor);
f-fill (x, y-1, newcolor);
f-fill (x, y+1, newcolor);
}
}
The following procedure illustrate a recursive method for flood fill by using 4-connected method.
Scan line Algorithm
15
(0,0)
y min
y max
A(x1, y1)
B(x2,y2)
C(x3, y3)
D(x4, y4)
Fig. 3.4.1
Edge y
max
x
max
y
min
x
min
Slope
AB y2 x2 y1 x1 m1
AD y4 x4 y1 x1 m2
CD y3 x4 Y4 x4 m3
BC y2 x2 y3 x3 m4
Fig. 3.4.1
Scan line Algorithm
16
Edge y
max
x
max
y
min
x
min
Slope
AB y2 x2 y1 x1 m1
BC y2 x2 y3 x3 m4
CD y3 x3 Y4 x4 m3
AD y4 x4 y1 x1 m2
Fig. 3.4.2
y max =y2
y2-2
y2-2
y min
A(x1,y1)
B(x2, y2)
Scan line Algorithm
17
Fig. 3.4.3 Fig. 3.4.4
Edge y
max
x
max
y
min
x
min
Slope
AB y1 x1 y2 x2 m1
BC y1 x1 y5 x3 m2
CD y3 x3 Y2 x2 m3
AD y x y x m4
A(x1,y1)
D(x4,y4)
C(x3,y3)
B(x2,y2)
max
min
A
(x1,y1)
C
(x3,y3)
D(x4,y4)
B
(x2,y2)
E
(x5,y5)
Y max
Y min
Scan line Algorithm
18
Fig. 3.4.5
Fig. 3.4.6
A
C
D
B
E
P2 P3 P4P1
yp
P3
P2P1
Flood fill Vs Boundary fill Vs Edge fill Vs Fence fill Vs Scan line fill
19
Flood fill Boundary Fill Edge fill Fence Fill Scan line fill
Need Seed point to
start.
Need Seed point to
start.
Based on
complimenting the
pixels.
Based on
complimenting the
pixels.
Based on line
drawing, polygon is
filled.
Current pixels color
is compared with
new pixel color.
Current pixels color
is compared with
new pixel color and
boundary color.
Pixels which are on
right side of an edge
are getting
complemented.
Pixels which are on
right side of an edge
and to the left of
fence as well as left
side of edge and
right side of fence
are getting
complemented.
Intersection of
polygon edges are
found with the scan
line and then the
solid lines are drawn
between two such
intersection points.
Useful for polygons
having single color
boundary.
Useful for polygons
having multi color
boundary.
More number of
pixels are
unnecessarily
accessed.
Less number of
pixels are accessed
as compared to
edge fill.
Need separate
attention to handle
concave polygons.
Connected boundary fill Algorithm
boundary_fill (x, y, f_colour, b_colour)
{
if (getpixel (x, y) != b_colour && getpixel (x, y) != f_colour)
{
putpixel (x, y, f_colour);
boundary_fill (x+1, y, f_colour, b_colour);
boundary_fill (x-1, y, f_colour, b_colour);
boundary_fill (x, y+1, f_colour, b_colour);
boundary_fill (x, y-1, f_colour, b_colour);
boundary_fill (x+1, y+1, f_colour, b_colour);
boundary_fill (x-1, y-1, f_colour, b_colour);
boundary_fill (x+1, y-1, f_colour, b_colour);
boundary_fill (x-1, y+1, f_colour, b_colour);
}
}
To enhance speed of filling colour one may look for alternative of 4-connected.
In this algorithm all adjacent pixels will be consider for filling till the match is true. Algorithm is as follows :
20

Weitere ähnliche Inhalte

Was ist angesagt?

Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...
Mani Kanth
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fill
wahab13
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
Mohd Arif
 

Was ist angesagt? (20)

Parallel projection
Parallel projectionParallel projection
Parallel projection
 
Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...Window to viewport transformation&matrix representation of homogeneous co...
Window to viewport transformation&matrix representation of homogeneous co...
 
2D viewing & clipping
2D viewing & clipping2D viewing & clipping
2D viewing & clipping
 
Graphics_3D viewing
Graphics_3D viewingGraphics_3D viewing
Graphics_3D viewing
 
Character generation techniques
Character generation techniquesCharacter generation techniques
Character generation techniques
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removal
 
Anti- aliasing computer graphics
Anti- aliasing computer graphicsAnti- aliasing computer graphics
Anti- aliasing computer graphics
 
Clipping ( Cohen-Sutherland Algorithm )
Clipping ( Cohen-Sutherland Algorithm )Clipping ( Cohen-Sutherland Algorithm )
Clipping ( Cohen-Sutherland Algorithm )
 
region-filling
region-fillingregion-filling
region-filling
 
Spline representations
Spline representationsSpline representations
Spline representations
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fill
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
Segments in Graphics
Segments in GraphicsSegments in Graphics
Segments in Graphics
 
Polygon clipping
Polygon clippingPolygon clipping
Polygon clipping
 
Seed filling algorithm
Seed filling algorithmSeed filling algorithm
Seed filling algorithm
 
Halftoning in Computer Graphics
Halftoning  in Computer GraphicsHalftoning  in Computer Graphics
Halftoning in Computer Graphics
 
Boundary fill algm
Boundary fill algmBoundary fill algm
Boundary fill algm
 
Random scan displays and raster scan displays
Random scan displays and raster scan displaysRandom scan displays and raster scan displays
Random scan displays and raster scan displays
 
3 d viewing
3 d viewing3 d viewing
3 d viewing
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clipping
 

Ähnlich wie Polygons - Computer Graphics - Notes

Notes and formulae mathematics
Notes and formulae mathematicsNotes and formulae mathematics
Notes and formulae mathematics
Zainonie Ma'arof
 
Notes and-formulae-mathematics
Notes and-formulae-mathematicsNotes and-formulae-mathematics
Notes and-formulae-mathematics
Ah Ching
 
2013 sp sa_2_09_mathematics_01_kvs
2013 sp sa_2_09_mathematics_01_kvs2013 sp sa_2_09_mathematics_01_kvs
2013 sp sa_2_09_mathematics_01_kvs
Yagya Malik
 
Lecture filling algorithms
Lecture  filling algorithmsLecture  filling algorithms
Lecture filling algorithms
avelraj
 

Ähnlich wie Polygons - Computer Graphics - Notes (20)

CVGIP_Chia-Pin Tseng
CVGIP_Chia-Pin TsengCVGIP_Chia-Pin Tseng
CVGIP_Chia-Pin Tseng
 
determinants-160504230830_repaired.pdf
determinants-160504230830_repaired.pdfdeterminants-160504230830_repaired.pdf
determinants-160504230830_repaired.pdf
 
determinants-160504230830.pdf
determinants-160504230830.pdfdeterminants-160504230830.pdf
determinants-160504230830.pdf
 
Determinants
DeterminantsDeterminants
Determinants
 
maths sample paper class 9 SA2
maths sample paper class 9 SA2maths sample paper class 9 SA2
maths sample paper class 9 SA2
 
Cbse sample-papers-class-10-maths-sa-ii-solved-4
Cbse sample-papers-class-10-maths-sa-ii-solved-4Cbse sample-papers-class-10-maths-sa-ii-solved-4
Cbse sample-papers-class-10-maths-sa-ii-solved-4
 
Notes and formulae mathematics
Notes and formulae mathematicsNotes and formulae mathematics
Notes and formulae mathematics
 
UNIT2.pptx
UNIT2.pptxUNIT2.pptx
UNIT2.pptx
 
Combinational circuit
Combinational circuitCombinational circuit
Combinational circuit
 
Geometry 1st Edition Kindle Edition by Elayn Martin Gay Solutions Manual
Geometry 1st Edition Kindle Edition by Elayn Martin Gay Solutions ManualGeometry 1st Edition Kindle Edition by Elayn Martin Gay Solutions Manual
Geometry 1st Edition Kindle Edition by Elayn Martin Gay Solutions Manual
 
Notes and Formulae Mathematics SPM
Notes and Formulae Mathematics SPM Notes and Formulae Mathematics SPM
Notes and Formulae Mathematics SPM
 
Notes and-formulae-mathematics
Notes and-formulae-mathematicsNotes and-formulae-mathematics
Notes and-formulae-mathematics
 
Mathematics formulas
Mathematics formulasMathematics formulas
Mathematics formulas
 
Class 9 Cbse Maths Sample Paper Term 1 Model 1
Class 9 Cbse Maths Sample Paper Term 1 Model 1Class 9 Cbse Maths Sample Paper Term 1 Model 1
Class 9 Cbse Maths Sample Paper Term 1 Model 1
 
2013 sp sa_2_09_mathematics_01_kvs
2013 sp sa_2_09_mathematics_01_kvs2013 sp sa_2_09_mathematics_01_kvs
2013 sp sa_2_09_mathematics_01_kvs
 
ag assign1.0.docx
ag assign1.0.docxag assign1.0.docx
ag assign1.0.docx
 
Vistas Learning-Class-Maths
Vistas Learning-Class-MathsVistas Learning-Class-Maths
Vistas Learning-Class-Maths
 
Form 5 Additional Maths Note
Form 5 Additional Maths NoteForm 5 Additional Maths Note
Form 5 Additional Maths Note
 
Lecture filling algorithms
Lecture  filling algorithmsLecture  filling algorithms
Lecture filling algorithms
 
Class 9 Cbse Maths Sample Paper Term 2 Model 1
Class 9 Cbse Maths Sample Paper Term 2 Model 1Class 9 Cbse Maths Sample Paper Term 2 Model 1
Class 9 Cbse Maths Sample Paper Term 2 Model 1
 

Mehr von Omprakash Chauhan

motherboard electronic components and their functions
motherboard electronic components and their functionsmotherboard electronic components and their functions
motherboard electronic components and their functions
Omprakash Chauhan
 
System of units
System of unitsSystem of units
System of units
Omprakash Chauhan
 

Mehr von Omprakash Chauhan (19)

Introduction to curve
Introduction to curveIntroduction to curve
Introduction to curve
 
Stack - Data Structure - Notes
Stack - Data Structure - NotesStack - Data Structure - Notes
Stack - Data Structure - Notes
 
Sorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - NotesSorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - Notes
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Basic of Data Structure - Data Structure - Notes
Basic of Data Structure - Data Structure - NotesBasic of Data Structure - Data Structure - Notes
Basic of Data Structure - Data Structure - Notes
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
 
Basic of computer graphic - Computer Graphic - Notes
Basic of computer graphic - Computer Graphic - NotesBasic of computer graphic - Computer Graphic - Notes
Basic of computer graphic - Computer Graphic - Notes
 
E-R Diagram of College Management Systems
E-R Diagram of College Management SystemsE-R Diagram of College Management Systems
E-R Diagram of College Management Systems
 
Burglar Alarm Micro Project
Burglar Alarm Micro ProjectBurglar Alarm Micro Project
Burglar Alarm Micro Project
 
Simple Calculator Flowchart
Simple Calculator FlowchartSimple Calculator Flowchart
Simple Calculator Flowchart
 
Full Wave Rectifier (FWR) Microproject
Full Wave Rectifier (FWR) MicroprojectFull Wave Rectifier (FWR) Microproject
Full Wave Rectifier (FWR) Microproject
 
A detailed study of guidelines required for presentation skills
A detailed study of guidelines required for presentation skillsA detailed study of guidelines required for presentation skills
A detailed study of guidelines required for presentation skills
 
Fractional-horsepower Motor Report
Fractional-horsepower Motor ReportFractional-horsepower Motor Report
Fractional-horsepower Motor Report
 
motherboard electronic components and their functions
motherboard electronic components and their functionsmotherboard electronic components and their functions
motherboard electronic components and their functions
 
How To Area of irregular shape Using Integration Method.
How To Area of irregular shape Using Integration Method.How To Area of irregular shape Using Integration Method.
How To Area of irregular shape Using Integration Method.
 
Process of ionization
Process of ionizationProcess of ionization
Process of ionization
 
Welcome to the world of ionization
Welcome to the world of ionization Welcome to the world of ionization
Welcome to the world of ionization
 
Printer
PrinterPrinter
Printer
 
System of units
System of unitsSystem of units
System of units
 

Kürzlich hochgeladen

Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
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
dollysharma2066
 
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
rknatarajan
 

Kürzlich hochgeladen (20)

(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
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
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
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
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
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
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
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
 
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...
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
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
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 

Polygons - Computer Graphics - Notes

  • 1. Polygon (Definition) 1 Polygon is a figure having many slides. It may be represented as a number of line segments end to end to form a closed figure. The line segments which form the boundary of polygon are called as edges or slides of polygon. The end of the side are called the polygon vertices. Triangle is the most simple form of polygon having three side and three vertices. The polygon may be of any shape.
  • 2. Types of Polygon 2 1. Convex 2. Concave 3. Complex
  • 3. Convex 3 Convex polygon is a polygon in which if we take any points which are surely inside the polygon and if we draw a joining these two points and if all the points on that line lies into the polygon, then such a polygon is called as convex polygon.
  • 4. Concave 4 Concave polygon is a polygon in which if we take any two points which are surely inside the polygon and if we draw a line joining these two points and if all the points on that line are not lying inside the polygon, then such a polygon is called as concave polygon.
  • 5. Complex 5 In a computer graphics, a polygon which is neither convex nor concave is referred as complex polygons. The complex polygon includes any polygon which intersects itself of the polygon which overlaps itself. The complex polygon has a boundary.
  • 6. Polygon Representation 6 OP X Y 6 5 5 2 7 5 2 9 3 2 7 1 2 5 1 2 3 3 2 5 5 A(5,5) F(3,3) E(5,1) D(7,1) B(7,5) C(9,3)
  • 7. Inside Test Methods 7 1. Even-odd Method 2. Winding Number Method
  • 8. Even - Odd Methods 8 x4,y4 x3,y3 x2,y2 x1,y1 Count even Outside Point ‘B’ A Fig. 3.2.2 Fig. 3.2.3 Fig. 3.2.4 Outside Point ‘B’ AC Count Odd Fig. 3.2.5 ACB A B C D A
  • 9. Winding Number Methods 9 1 -1 1 Fig. 3.2.7 Fig. 3.2.8 Fig. 3.2.9 AB C 1 Newly drawn line +1 -1 DC B A
  • 10. Winding Number Methods 10 Fig. 3.2.10 (c) Fig. 3.2.10 (a) Fig. 3.2.10 (b) -1 -1+1 D AB C Case I Case II Case III B C A D -1 -1+1 B C D A -1-1 +1
  • 11. Polygon Filling 11 Polygon Filling Algorithm 1. Boundary Fill Algorithm 2. Flood Fill (Seed Fill) Algorithm 3. Edge Fill Algorithm 4. Fence Fill Algorithm 1. Scan Line Algorithm Pixel Level Geometric Level
  • 12. 4-connected Method 12 In this 4 neighboring points of a current test point are tested. These are pixel positions that are right, left, above and below of current pixels as shown in figure 2.26 8-connected Method Here 8 neighboring pixels of current test pixel are tested. These pixel positions are left, right, above and 4 – diagonal positions of current pixel as shown in figure 2.27
  • 13. Boundary Fill Algorithm 13 bfill (x, y, newcolor) { current = getpixel (x, y); if (current != newcolor)) && (current != boundarycolor) { putpixel (x, y, newcolor); bfill (x+1, y, newcolor); bfill (x-1, y, newcolor); bfill (x, y+1, newcolor); bfill (x, y-1, newcolor); } } The following procedure illustrate a recursive method for boundary fill by using 4-connected method.
  • 14. Flood Fill (Seed fill) Algorithm 14 F-fill (x, y, newcolor) { current = getpixel (x, y); if (current != newcolor) { putpixel (x, y, newcolor); f-fill (x-1, y, newcolor); f-fill (x+1, y, newcolor); f-fill (x, y-1, newcolor); f-fill (x, y+1, newcolor); } } The following procedure illustrate a recursive method for flood fill by using 4-connected method.
  • 15. Scan line Algorithm 15 (0,0) y min y max A(x1, y1) B(x2,y2) C(x3, y3) D(x4, y4) Fig. 3.4.1 Edge y max x max y min x min Slope AB y2 x2 y1 x1 m1 AD y4 x4 y1 x1 m2 CD y3 x4 Y4 x4 m3 BC y2 x2 y3 x3 m4 Fig. 3.4.1
  • 16. Scan line Algorithm 16 Edge y max x max y min x min Slope AB y2 x2 y1 x1 m1 BC y2 x2 y3 x3 m4 CD y3 x3 Y4 x4 m3 AD y4 x4 y1 x1 m2 Fig. 3.4.2 y max =y2 y2-2 y2-2 y min A(x1,y1) B(x2, y2)
  • 17. Scan line Algorithm 17 Fig. 3.4.3 Fig. 3.4.4 Edge y max x max y min x min Slope AB y1 x1 y2 x2 m1 BC y1 x1 y5 x3 m2 CD y3 x3 Y2 x2 m3 AD y x y x m4 A(x1,y1) D(x4,y4) C(x3,y3) B(x2,y2) max min A (x1,y1) C (x3,y3) D(x4,y4) B (x2,y2) E (x5,y5) Y max Y min
  • 18. Scan line Algorithm 18 Fig. 3.4.5 Fig. 3.4.6 A C D B E P2 P3 P4P1 yp P3 P2P1
  • 19. Flood fill Vs Boundary fill Vs Edge fill Vs Fence fill Vs Scan line fill 19 Flood fill Boundary Fill Edge fill Fence Fill Scan line fill Need Seed point to start. Need Seed point to start. Based on complimenting the pixels. Based on complimenting the pixels. Based on line drawing, polygon is filled. Current pixels color is compared with new pixel color. Current pixels color is compared with new pixel color and boundary color. Pixels which are on right side of an edge are getting complemented. Pixels which are on right side of an edge and to the left of fence as well as left side of edge and right side of fence are getting complemented. Intersection of polygon edges are found with the scan line and then the solid lines are drawn between two such intersection points. Useful for polygons having single color boundary. Useful for polygons having multi color boundary. More number of pixels are unnecessarily accessed. Less number of pixels are accessed as compared to edge fill. Need separate attention to handle concave polygons.
  • 20. Connected boundary fill Algorithm boundary_fill (x, y, f_colour, b_colour) { if (getpixel (x, y) != b_colour && getpixel (x, y) != f_colour) { putpixel (x, y, f_colour); boundary_fill (x+1, y, f_colour, b_colour); boundary_fill (x-1, y, f_colour, b_colour); boundary_fill (x, y+1, f_colour, b_colour); boundary_fill (x, y-1, f_colour, b_colour); boundary_fill (x+1, y+1, f_colour, b_colour); boundary_fill (x-1, y-1, f_colour, b_colour); boundary_fill (x+1, y-1, f_colour, b_colour); boundary_fill (x-1, y+1, f_colour, b_colour); } } To enhance speed of filling colour one may look for alternative of 4-connected. In this algorithm all adjacent pixels will be consider for filling till the match is true. Algorithm is as follows : 20