SlideShare una empresa de Scribd logo
1 de 34
TOPICS:
   Mid-point Circle Algorithm,
   Filling Algorithms &
   Polygons.


                                  




                                      1/2
                                      -1
   To determine the closest pixel position to the
    specified circle path at each step.
   For given radius r and screen center position
    (xc, yc), calculate pixel positions around a circle
    path centered at the coordinate origin (0,0).
   Then, move each calculated position (x, y) to its
    proper screen position by adding xc to x and
    yc to y .


                                                          3
   8 segments of octants for a circle:
   Circle function:    fcircle (x,y) = x2 + y2 –r2




                          {
                                  > 0, (x,y) outside the circle

              fcircle (x,y) =     < 0, (x,y) inside the circle

                                  = 0, (x,y) is on the circle
                                     boundary
midpoint                          midpoint
yk                               yk

yk-1                             yk-1


        xk    Xk+1   Xk+2                       Xk+1   Xk+2
                                         Xk
              Pk < 0                            Pk >= 0
             yk+1 = yk                        yk+1 = yk - 1
       Next pixel = (xk+1, yk)          Next pixel = (xk+1, yk-1)
We know xk+1 = xk+1,

   Pk = fcircle(xk+1, yk- ½)

   Pk = (xk +1)2 + (yk - ½)2 - r2       -------- (1)

   Pk+1 = fcircle(xk+1+1, yk+1- ½)

   Pk+1 = [(xk +1)+1]2 + (yk+1 - ½)2 - r2 -------- (2)



                                                         6
By subtracting eq.1 from eq.2, we get

  Pk+1 –Pk = 2(xk+1) + (y2k+1 – y2k) - (yk+1 – yk) + 1

   Pk+1 = Pk + 2(xk+1) + (y2k+1 – y2k) - (yk+1 – yk) + 1

   If Pk < 0,             Pk+1 = Pk + 2xk+1+1


   If Pk >= 0,        Pk+1 = Pk + 2xk+1+1 – 2yk+1
For the initial point, (x0 , y0 ) = (0, r)

             p0 = fcircle (1, r-½ )
               = 1 + (r-½ )2 – r2
               = 5–r
                 4
              ≈ 1–r
   Taking input radius ‘r’ and circle center (xc , yc), we obtain the
    first point on the circumference of a circle centered on the
    origin as:
                   (x0 , y0) = (0,r)
   Next we will calculate the initial value of the decision
    parameter as
                    p0 = 5/4-r
   At each x position, starting at k=0 , perform the following test:
    if p<0 the next point along the circle centered on (0,0) is
    (xk+1, yk) and
                    pk+1= pk+ 2 xk+1 +1


                                                                         10
Otherwise, the next point along the circle is (xk+1, yk -1) and
                 pk+1 = pk +2 xk+1 +1+ 2 yk+1
        where,
              2 xk+1 =2 xk+2 and 2 yk+1 = 2 yk -2.

   After this we will determine the symmetric points in the other
    7 octants.

   At Move each calculated pixel position (x,y) on to the circle
    path centered on (xc , yc) and plot the coordinate values:

                x=x+xc               y=y+yc

   Repeat step 3 through 5 until x>=y


                                                                      11
Example:
Given a circle radius = 10, determine the circle octant in
the first quadrant from x=0 to x=y.

Solution:
                p0 = 5 – r
                     4
                   = 5 – 10
                      4
                   = -8.75
                  ≈ –9
Initial (x0, y0) = (0,10)
Decision parameters are: 2x0 = 0, 2y0 = 20
   k            Pk            x       y      2xk+1   2yk+1
   0             -9           1       10      2        20
   1         -9+2+1=-6        2       10      4        20
   2         -6+4+1=-1        3       10      6        20
   3         -1+6+1=6         4       9       8        18
   4        6+8+1-18=-3       5       9       10       18
   5         -3+10+1=8        6       8       12       16
   6       8+12+1-16=5        7       7       14       14
   Fill-Area algorithms are used to fill the
    interior of a polygonal shape.
   Many algorithms perform fill operations
    by first identifying the interior points,
    given the polygon boundary.
The basic filling algorithm is commonly used in
interactive graphics packages, where the user
specifies an interior point of the region to be filled.


                               4-connected pixels
[1] Set the user specified point.
[2] Store the four neighboring pixels in a stack.
[3] Remove a pixel from the stack.
[4] If the pixel is not set,
    Set the pixel
    Push its four neighboring pixels into the stack
[5] Go to step 3
[6] Repeat till the stack is empty.
void fill(int x, int y) {
  if(getPixel(x,y)==0){
     setPixel(x,y);
     fill(x+1,y);
     fill(x-1,y);
     fill(x,y+1);
     fill(x,y-1);
  }
}
   Boundary Fill Algorithm
    ◦ For filling a region with a single boundary color.
    ◦ Condition for setting pixels:
       Color is not the same as border color
       Color is not the same as fill color
   Flood Fill Algorithm
    ◦ For filling a region with multiple boundary colors.
    ◦ Here we don’t have to deal with boundary color
    ◦ Condition for setting pixels:
       Coloring of the pixels of the polygon is done with
        the fill color until we keep getting the old interior
        color.
void boundaryFill(int x, int y,
          int fillColor, int borderColor)
{
  getPixel(x, y, color);
  if ((color != borderColor)
            && (color != fillColor)) {
      setPixel(x,y);
      boundaryFill(x+1,y,fillColor,borderColor);
      boundaryFill(x-1,y,fillColor,borderColor);
      boundaryFill(x,y+1,fillColor,borderColor);
      boundaryFill(x,y-1,fillColor,borderColor);
  }
}
1.   The 4-connected
     method.




2.   The 8-connected
     method.
CS 380
   Polygon is a closed figure with many vertices and edges (line
    segments), and at each vertex exactly two edges meet and no edge
    crosses the other.
Types of Polygon:
   Regular polygons
           No. of egdes equal to no. of angles.
   Convex polygons
           Line generated by taking two points in the polygon must lie
            within the polygon.


   Concave polygons
          Line generated by taking two points in the polygon may lie
           outside the polygon.
     This test is required to identify whether a point is inside
      or outside the polygon. This test is mostly used for
      identify the points in hollow polgons.


Two types of methods are there for
this test:
I.      Even-Odd Method,
II.     Winding Number Method.

                                                                    1/2
                                                                      -
                                                                     27
1.   Draw a line from any position P to a distant point outside
     the coordinate extents of the object and counting the
     number of edge crossings along the scan line.

2.   If the number of polygon edges crossed by this line is odd
     then
                P is an interior point.
     Else
                P is an exterior point
29
Nonzero Winding Number Rule :
    Another method of finding whether a point is inside or outside
     of the polygon. In this every point has a winding number, and
     the interior points of a two-dimensional object are defined to
     be those that have a nonzero value for the winding number.

1.   Initializing the winding number to 0.
2.   Imagine a line drawn from any position P to a distant point
     beyond the coordinate extents of the object.
3.    Count the number of edges that cross the line in each
      direction. We add 1 to the winding number every time we
      intersect a polygon edge that crosses the line from right to
      left, and we subtract 1 every time we intersect an edge that
      crosses from left to right.
4. If the winding number is nonzero, then
           P is defined to be an interior point
    Else
           P is taken to be an exterior point.
10   14 18    24
Interior pixels along a scan line passing through a polygon area
• For each scan line crossing a polygon ,the area filling algorithm locates the
intersection points of the scan line with the polygon edges.
• These intersection points are then sorted from left to right , and the
corresponding frame buffer positions between each intersection pair are set to
specified fill color
(a)                   (b)
Adjusting endpoint values for a polygon, as we process edges in order
around the polygon perimeter. The edge currently being processed is
indicated as a solid like. In (a), the y coordinate of the upper endpoint of
the current edge id decreased by 1. In (b), the y coordinate of the upper
end point of the next edge is decreased by 1
34

Más contenido relacionado

La actualidad más candente

Polygon Fill
Polygon FillPolygon Fill
Polygon Fill
wahab13
 
Intro to scan conversion
Intro to scan conversionIntro to scan conversion
Intro to scan conversion
Mohd Arif
 
3 d geometric transformations
3 d geometric transformations3 d geometric transformations
3 d geometric transformations
Mohd Arif
 

La actualidad más candente (20)

Polygon Fill
Polygon FillPolygon Fill
Polygon Fill
 
Overview of the graphics system
Overview of the graphics systemOverview of the graphics system
Overview of the graphics system
 
Intro to scan conversion
Intro to scan conversionIntro to scan conversion
Intro to scan conversion
 
4. THREE DIMENSIONAL DISPLAY METHODS
4.	THREE DIMENSIONAL DISPLAY METHODS4.	THREE DIMENSIONAL DISPLAY METHODS
4. THREE DIMENSIONAL DISPLAY METHODS
 
Cohen sutherland line clipping
Cohen sutherland line clippingCohen sutherland line clipping
Cohen sutherland line clipping
 
BRESENHAM’S LINE DRAWING ALGORITHM
BRESENHAM’S  LINE DRAWING ALGORITHMBRESENHAM’S  LINE DRAWING ALGORITHM
BRESENHAM’S LINE DRAWING ALGORITHM
 
Liang barsky Line Clipping Algorithm
Liang barsky Line Clipping AlgorithmLiang barsky Line Clipping Algorithm
Liang barsky Line Clipping Algorithm
 
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
 
DDA algorithm
DDA algorithmDDA algorithm
DDA algorithm
 
Output primitives computer graphics c version
Output primitives   computer graphics c versionOutput primitives   computer graphics c version
Output primitives computer graphics c version
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithms
 
Cohen and Sutherland Algorithm for 7-8 marks
Cohen and Sutherland Algorithm for 7-8 marksCohen and Sutherland Algorithm for 7-8 marks
Cohen and Sutherland Algorithm for 7-8 marks
 
Clipping in Computer Graphics
Clipping in Computer GraphicsClipping in Computer Graphics
Clipping in Computer Graphics
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removal
 
Quadric surfaces
Quadric surfacesQuadric surfaces
Quadric surfaces
 
3 d geometric transformations
3 d geometric transformations3 d geometric transformations
3 d geometric transformations
 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphics
 
Liang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygons
Liang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygonsLiang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygons
Liang- Barsky Algorithm, Polygon clipping & pipeline clipping of polygons
 
Clipping computer graphics
Clipping  computer graphicsClipping  computer graphics
Clipping computer graphics
 
Frame buffer
Frame bufferFrame buffer
Frame buffer
 

Destacado (13)

Lecture filling algorithms
Lecture  filling algorithmsLecture  filling algorithms
Lecture filling algorithms
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformations
 
2 d transformations by amit kumar (maimt)
2 d transformations by amit kumar (maimt)2 d transformations by amit kumar (maimt)
2 d transformations by amit kumar (maimt)
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
 
Character generation
Character generationCharacter generation
Character generation
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Euler and hamilton paths
Euler and hamilton pathsEuler and hamilton paths
Euler and hamilton paths
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Hamiltonian path
Hamiltonian pathHamiltonian path
Hamiltonian path
 
Polygon filling
Polygon fillingPolygon filling
Polygon filling
 
backtracking algorithms of ada
backtracking algorithms of adabacktracking algorithms of ada
backtracking algorithms of ada
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
Area filling algo
Area filling algoArea filling algo
Area filling algo
 

Similar a Computer graphics

Lec05 circle ellipse
Lec05 circle ellipseLec05 circle ellipse
Lec05 circle ellipse
Maaz Rizwan
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
Mohammad Sadiq
 
mid point algorithm.pdf
mid point algorithm.pdfmid point algorithm.pdf
mid point algorithm.pdf
MehulMunshi3
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing Algorithm
Neha Kaurav
 
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
saranyan75
 
Computer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitivesComputer Graphics and Multimedia Output primitives
Computer Graphics and Multimedia Output primitives
saranyan75
 

Similar a Computer graphics (20)

Lec05 circle ellipse
Lec05 circle ellipseLec05 circle ellipse
Lec05 circle ellipse
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 
mid point algorithm.pdf
mid point algorithm.pdfmid point algorithm.pdf
mid point algorithm.pdf
 
2.circle
2.circle2.circle
2.circle
 
Computer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptComputer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.ppt
 
10994479.ppt
10994479.ppt10994479.ppt
10994479.ppt
 
Computer Graphics - lines, Circles and ellipse
Computer Graphics - lines, Circles and ellipseComputer Graphics - lines, Circles and ellipse
Computer Graphics - lines, Circles and ellipse
 
Computer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and EllipseComputer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and Ellipse
 
Unit 3
Unit 3Unit 3
Unit 3
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
 
Bressenham’s Midpoint Circle Drawing Algorithm
Bressenham’s Midpoint Circle Drawing AlgorithmBressenham’s Midpoint Circle Drawing Algorithm
Bressenham’s Midpoint Circle Drawing Algorithm
 
CG-Lecture3.pptx
CG-Lecture3.pptxCG-Lecture3.pptx
CG-Lecture3.pptx
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptx
 
Lect4 ellipse
Lect4 ellipseLect4 ellipse
Lect4 ellipse
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output Primitives
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing Algorithm
 
An Algorithm to Find the Largest Circle inside a Polygon
An Algorithm to Find the Largest Circle inside a PolygonAn Algorithm to Find the Largest Circle inside a Polygon
An Algorithm to Find the Largest Circle inside a Polygon
 
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
 

Último

Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Último (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 

Computer graphics

  • 1. TOPICS:  Mid-point Circle Algorithm,  Filling Algorithms &  Polygons.  1/2 -1
  • 2.
  • 3. To determine the closest pixel position to the specified circle path at each step.  For given radius r and screen center position (xc, yc), calculate pixel positions around a circle path centered at the coordinate origin (0,0).  Then, move each calculated position (x, y) to its proper screen position by adding xc to x and yc to y . 3
  • 4. 8 segments of octants for a circle:
  • 5. Circle function: fcircle (x,y) = x2 + y2 –r2 { > 0, (x,y) outside the circle fcircle (x,y) = < 0, (x,y) inside the circle = 0, (x,y) is on the circle boundary
  • 6. midpoint midpoint yk yk yk-1 yk-1 xk Xk+1 Xk+2 Xk+1 Xk+2 Xk Pk < 0 Pk >= 0 yk+1 = yk yk+1 = yk - 1 Next pixel = (xk+1, yk) Next pixel = (xk+1, yk-1)
  • 7. We know xk+1 = xk+1, Pk = fcircle(xk+1, yk- ½) Pk = (xk +1)2 + (yk - ½)2 - r2 -------- (1) Pk+1 = fcircle(xk+1+1, yk+1- ½) Pk+1 = [(xk +1)+1]2 + (yk+1 - ½)2 - r2 -------- (2) 6
  • 8. By subtracting eq.1 from eq.2, we get Pk+1 –Pk = 2(xk+1) + (y2k+1 – y2k) - (yk+1 – yk) + 1 Pk+1 = Pk + 2(xk+1) + (y2k+1 – y2k) - (yk+1 – yk) + 1 If Pk < 0, Pk+1 = Pk + 2xk+1+1 If Pk >= 0, Pk+1 = Pk + 2xk+1+1 – 2yk+1
  • 9. For the initial point, (x0 , y0 ) = (0, r) p0 = fcircle (1, r-½ ) = 1 + (r-½ )2 – r2 = 5–r 4 ≈ 1–r
  • 10. Taking input radius ‘r’ and circle center (xc , yc), we obtain the first point on the circumference of a circle centered on the origin as: (x0 , y0) = (0,r)  Next we will calculate the initial value of the decision parameter as p0 = 5/4-r  At each x position, starting at k=0 , perform the following test: if p<0 the next point along the circle centered on (0,0) is (xk+1, yk) and pk+1= pk+ 2 xk+1 +1 10
  • 11. Otherwise, the next point along the circle is (xk+1, yk -1) and pk+1 = pk +2 xk+1 +1+ 2 yk+1 where, 2 xk+1 =2 xk+2 and 2 yk+1 = 2 yk -2.  After this we will determine the symmetric points in the other 7 octants.  At Move each calculated pixel position (x,y) on to the circle path centered on (xc , yc) and plot the coordinate values: x=x+xc y=y+yc  Repeat step 3 through 5 until x>=y 11
  • 12. Example: Given a circle radius = 10, determine the circle octant in the first quadrant from x=0 to x=y. Solution: p0 = 5 – r 4 = 5 – 10 4 = -8.75 ≈ –9
  • 13. Initial (x0, y0) = (0,10) Decision parameters are: 2x0 = 0, 2y0 = 20 k Pk x y 2xk+1 2yk+1 0 -9 1 10 2 20 1 -9+2+1=-6 2 10 4 20 2 -6+4+1=-1 3 10 6 20 3 -1+6+1=6 4 9 8 18 4 6+8+1-18=-3 5 9 10 18 5 -3+10+1=8 6 8 12 16 6 8+12+1-16=5 7 7 14 14
  • 14.
  • 15. Fill-Area algorithms are used to fill the interior of a polygonal shape.  Many algorithms perform fill operations by first identifying the interior points, given the polygon boundary.
  • 16. The basic filling algorithm is commonly used in interactive graphics packages, where the user specifies an interior point of the region to be filled. 4-connected pixels
  • 17. [1] Set the user specified point. [2] Store the four neighboring pixels in a stack. [3] Remove a pixel from the stack. [4] If the pixel is not set, Set the pixel Push its four neighboring pixels into the stack [5] Go to step 3 [6] Repeat till the stack is empty.
  • 18. void fill(int x, int y) { if(getPixel(x,y)==0){ setPixel(x,y); fill(x+1,y); fill(x-1,y); fill(x,y+1); fill(x,y-1); } }
  • 19. Boundary Fill Algorithm ◦ For filling a region with a single boundary color. ◦ Condition for setting pixels:  Color is not the same as border color  Color is not the same as fill color  Flood Fill Algorithm ◦ For filling a region with multiple boundary colors. ◦ Here we don’t have to deal with boundary color ◦ Condition for setting pixels:  Coloring of the pixels of the polygon is done with the fill color until we keep getting the old interior color.
  • 20. void boundaryFill(int x, int y, int fillColor, int borderColor) { getPixel(x, y, color); if ((color != borderColor) && (color != fillColor)) { setPixel(x,y); boundaryFill(x+1,y,fillColor,borderColor); boundaryFill(x-1,y,fillColor,borderColor); boundaryFill(x,y+1,fillColor,borderColor); boundaryFill(x,y-1,fillColor,borderColor); } }
  • 21. 1. The 4-connected method. 2. The 8-connected method.
  • 22.
  • 24.
  • 25.
  • 26. Polygon is a closed figure with many vertices and edges (line segments), and at each vertex exactly two edges meet and no edge crosses the other. Types of Polygon:  Regular polygons  No. of egdes equal to no. of angles.  Convex polygons  Line generated by taking two points in the polygon must lie within the polygon.  Concave polygons  Line generated by taking two points in the polygon may lie outside the polygon.
  • 27. This test is required to identify whether a point is inside or outside the polygon. This test is mostly used for identify the points in hollow polgons. Two types of methods are there for this test: I. Even-Odd Method, II. Winding Number Method. 1/2 - 27
  • 28. 1. Draw a line from any position P to a distant point outside the coordinate extents of the object and counting the number of edge crossings along the scan line. 2. If the number of polygon edges crossed by this line is odd then P is an interior point. Else P is an exterior point
  • 29. 29
  • 30. Nonzero Winding Number Rule :  Another method of finding whether a point is inside or outside of the polygon. In this every point has a winding number, and the interior points of a two-dimensional object are defined to be those that have a nonzero value for the winding number. 1. Initializing the winding number to 0. 2. Imagine a line drawn from any position P to a distant point beyond the coordinate extents of the object. 3. Count the number of edges that cross the line in each direction. We add 1 to the winding number every time we intersect a polygon edge that crosses the line from right to left, and we subtract 1 every time we intersect an edge that crosses from left to right.
  • 31. 4. If the winding number is nonzero, then P is defined to be an interior point Else P is taken to be an exterior point.
  • 32. 10 14 18 24 Interior pixels along a scan line passing through a polygon area • For each scan line crossing a polygon ,the area filling algorithm locates the intersection points of the scan line with the polygon edges. • These intersection points are then sorted from left to right , and the corresponding frame buffer positions between each intersection pair are set to specified fill color
  • 33. (a) (b) Adjusting endpoint values for a polygon, as we process edges in order around the polygon perimeter. The edge currently being processed is indicated as a solid like. In (a), the y coordinate of the upper endpoint of the current edge id decreased by 1. In (b), the y coordinate of the upper end point of the next edge is decreased by 1
  • 34. 34