SlideShare a Scribd company logo
1 of 27
WHERE TO DRAW A LINE??


 Line drawing is accomplished by calculating
  intermediate positions along the line path between
  specified end points.
 Precise definition of line drawing

        Given two points P and Q in the plane, both with
      integer coordinates, determine which pixels on a
      raster screen should be on in order to make a
      picture of a unit-width line segment starting from P
      and ending at Q.
6                 (3,
5                 3)
4
3
2
1
0
    0 1 2 3 4 5   6
Line drawing (contd.)
 The thinnest line is of one-pixel wide. We will
concentrate on drawing a line of 1 pixel resolution.
The Cartesian slope-intercept equation for a straight

line is
              y= m. ∆x + b
m is the slope of the line and b is the y intercept.
Given the endpoints of a line segment.
           m = (y2-y1) / (x2-x1)
            b= y1-m.x1
Line Drawing (cont)
 Also for any given interval ∆x along a line, we can
 compute the corresponding y interval ∆y from
                 ∆y= m. x
Similarly we can obtain the x interval ∆x corresponding

 to a specified ∆y as
                 ∆x= ∆y / m
These equations form the basis for determining

 deflection voltages in analog devices.
Line Drawing (cont)

   On Raster systems, lines are plotted with pixels, and
    step sizes in the horizontal and vertical directions are
    constrained by pixel separations. Hence we ought to
    “sample” a line at discrete positions and determine
    the nearest pixel to the line at each sampled position.
Bresenham’s Line Algorithm
An accurate, efficient raster line drawing algorithm
developed by Bresenham, scan converts lines using
only incremental integer calculations that can be
adapted to display circles and other curves.

Keeping in mind the symmetry property of lines, lets
derive a more efficient way of drawing a line.
    Starting from the left end point (x0,y0) of a given line , we step to each
    successive column (x position) and plot the pixel whose scan-line y
    value closest to the line path
    Assuming we have determined that the pixel at (xk,yk) is to be
    displayed, we next need to decide which pixel to plot in column
    xk+1.
Bresenham Line Algorithm
             (cont)
Choices are(xk +1, yk) and (xk+1, yK+1)
     d1 = y – yk = m(xk + 1) + b – yk
     d2 = (yk + 1) – y = yk + 1- m(xk + 1) – b
The difference between these 2 separations is
      d1-d2 = 2m(xk + 1) – 2 yK + 2b – 1

 A decision parameter pk for the kth step in the line algorithm
can be obtained by rearranging above equation so that it
involves only integer calculations
Bresenham’s Line Algorithm
Define
          Pk = Δx ( d1-d2) = 2Δyxk-2 Δxyk + c

The sign of Pk is the same as the sign of d1-d2, since Δx > 0.
    Parameter c is a constant and has the value 2Δy + Δx(2b-1)
    (independent of pixel position)

If pixel at yk is closer to line-path than pixel at yk +1
  (i.e, if d1 < d2) then pk is negative. We plot lower pixel in such a
case. Otherwise , upper pixel will be plotted.
Bresenham’s algorithm (cont)
At step k + 1, the decision parameter can be evaluated as,
           pk+1 = 2Δyxk+1- 2Δxyk+1+ c
Taking the difference of pk+ 1 and pk we get the following.
            pk+1 – pk = 2Δy(xk+1- xk)-2Δx(yk+1 – yk)

But, xk+1 = xk +1, so that
            pk+1 = pk + 2Δy - 2 Δx(yk+1 – yk)

Where the term yk+1-yk is either 0 or 1, depending on the sign of
parameter pk
Bresenham’s Line Algorithm
The first parameter p0 is directly computed

    p0 = 2 Δyx0 - 2 Δxy0 + c = 2 Δyx0 + 2 Δxy0 +2 Δy + Δx (2b-1)

Since (x0,y0) satisfies the line equation , we also have
       y0 = Δy/ Δx * x0 + b

Combining the above 2 equations , we will have
    p0 = 2Δy – Δx
   The constants 2Δy and 2Δy-2Δx are calculated once for each
time to be scan converted
Bresenham’s Line Algorithm
   So, the arithmetic involves only integer addition and subtraction of 2 constants
STEP 1 Input the two end points and store the left end point
           in (x0,y0)


STEP 2 Load (x0,y0) into the frame buffer (plot the first point)


STEP 3 Calculate the constants Δx, Δy, 2Δy and 2Δy-2Δx and
           obtain the starting value of the decision parameter as
                        p0 = 2Δy- Δx
Bresenham’s Line Algorithm
STEP 4 At each xk along the line, starting at k=0,
perform the following test:
If pk < 0 , the next point is (xk+1, yk) and
      pk+1 = pk + 2Δy

Otherwise
Point to plot is (xk+1, yk+1)
           pk+1 = pk + 2Δy - 2Δx

Repeat step 4 (above step) Δx times
Loading the frame buffer


•Calculate frame-buffer addresses by incremental
methods
•For a bilevel system(1 bit per pixel), address for
pixel(x,y)
       Addr(x,y) = addr(0,0)+y(xmax +1)+x
       Addr(x+1,y) = addr(x,y)+1
       Addr(x+1,y+1) = addr(x,y)+ x max +2
Where do we draw a circle???
   Properties of a circle:
A circle is defined as a set of points that are all the given distance (x ,y ).
                                                                          c c
This distance relationship is expressed by the pythagorean theorem in
Cartesian coordinates as
           (x – xc)2 + (y – yc) 2 = r2
We could use this equation to calculate the points on the circle

circumference by stepping along x-axis in unit steps from xc-r to xc+r and
calculate the corresponding y values at each position as
            y = yc +(- ) (r2 – (xc –x )2)1/2
This is not the best method:

   Considerable amount of computation
   Spacing between plotted pixels is not uniform
Polar co-ordinates for a circle
We could use polar coordinates r and θ,
     x = xc + r cosθ    y = yc + r sinθ
 A fixed angular step size can be used to plot equally spaced points
 along the circumference
A step size of 1/r can be used to set pixel positions to approximately

 1 unit apart for a continuous boundary
But, note that circle sections in adjacent octants within one quadrant

 are symmetric with respect to the 45 deg line dividing the two octants
Thus we can generate all pixel positions around a circle by calculating

 just the points within the sector from x=0 to x=y
This method is still computationally expensive
Bresenham to Midpoint
   Bresenham requires explicit equation
       Not always convenient (many equations are
        implicit)
       Based on implicit equations: Midpoint
        Algorithm (circle, ellipse, etc.)
       Implicit equations have the form F(x,y)=0.
Midpoint Circle Algorithm
We will first calculate pixel positions for a circle centered around the
origin (0,0). Then, each calculated position (x,y) is moved to its proper
screen position by adding xc to x and yc to y

Note that along the circle section from x=0 to x=y in the first octant,
the slope of the curve varies from 0 to -1

Circle function around the origin is given by
                  fcircle(x,y) = x2 + y2 – r2

Any point (x,y) on the boundary of the circle satisfies the equation
and circle function is zero
Midpoint Circle Algorithm
 For a point in the interior of the circle, the circle function is negative and
  for a point outside the circle, the function is positive
 Thus,

     f (x,y) < 0 if (x,y) is inside the circle boundary
       circle
       fcircle(x,y) = 0 if (x,y) is on the circle boundary
       fcircle(x,y) > 0 if (x,y) is outside the circle boundary
Midpoint Circle Algorithm
Assuming we have just plotted the pixel at (xk,yk) , we next need to
determine whether the pixel at position (xk + 1, yk-1) is closer to the circle
Our decision parameter is the circle function evaluated at the midpoint
between these two pixels

        pk = fcircle (xk +1, yk-1/2) = (xk +1)2 + (yk -1/2)2 – r2


   If pk < 0 , this midpoint is inside the circle and the pixel on the scan line yk
is closer to the circle boundary. Otherwise, the
   mid position is outside or on the circle boundary, and we select the pixel
on the scan line yk-1
Midpoint Circle Algorithm
Successive decision parameters are obtained using incremental
calculations
          Pk+1 = fcircle(xk+1+1, yk+1-1/2)
                  = [(xk+1)+1]2 + (yk+1 -1/2)2 –r2


OR
          Pk+1 = Pk+2(xK+1) + (yK+12 – yk2) – (yK+1- yk)+1
Where yk+1 is either yk or yk-1, depending on the sign of pk
Increments for obtaining Pk+1:
    2xk+1+1 if pk is negative
    2xk+1+1-2yk+1 otherwise
Midpoint circle algorithm
Note that following can also be done incrementally:
   2xk+1 = 2xk +2
     2 yk+1 = 2yk – 2
At the start position (0,r) , these two terms have the values 2 and 2r-2
respectively
Initial decision parameter is obtained by evaluating the circle function at

the start position (x0,y0) = (0,r)
         p0 = fcircle(1, r-1/2) = 1+ (r-1/2)2-r2
OR
        P0 = 5/4 -r
If radius r is specified as an integer, we can round p0 to
         p0 = 1-r
The actual algorithm
 1: Input radius r and circle center (xc,yc) and obtain the first point
 on the circumference of the circle centered on the origin as
          (x0,y0) = (0,r)

 2: Calculate the initial value of the decision parameter as
         P0 = 5/4 - r
  3: At each xk position starting at k = 0 , perform the following
test:
  If pk < 0 , the next point along the circle centered on (0,0) is
(xk+1, yk) and
        pk+1 = pk + 2xk+1 + 1
The algorithm
Otherwise the next point along the circle is (xk+1, yk-1) and
          pk+1 = pk + 2xk+1 +1 -2yk+1
Where 2xk+1 = 2xk+2 and 2yk+1 = 2yk-2

4: Determine symmetry points in the other seven octants

5: Move each calculated pixel position (x,y) onto the
circular path centered on (x,yc) and plot the coordinate
values
          x = x+ xc , y= y+ yc

 6: Repeat steps 3 through 5 until x >= y

More Related Content

What's hot

Bezier curve & B spline curve
Bezier curve  & B spline curveBezier curve  & B spline curve
Bezier curve & B spline curveArvind Kumar
 
Booths Multiplication Algorithm
Booths Multiplication AlgorithmBooths Multiplication Algorithm
Booths Multiplication Algorithmknightnick
 
boolean algebra and logic simplification
boolean algebra and logic simplificationboolean algebra and logic simplification
boolean algebra and logic simplificationUnsa Shakir
 
2D viewing & clipping
2D viewing & clipping2D viewing & clipping
2D viewing & clippingMdAlAmin187
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsDrishti Bhalla
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformationsMohammad Sadiq
 
Unit iv Shop floor control and FMS
Unit iv Shop floor control and FMSUnit iv Shop floor control and FMS
Unit iv Shop floor control and FMSmanimaran m
 
Notes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphicsNotes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphicsNANDINI SHARMA
 
scan conversion of point , line and circle
scan conversion of point , line and circlescan conversion of point , line and circle
scan conversion of point , line and circleDivy Kumar Gupta
 
Computer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and EllipseComputer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and Ellipse2013901097
 
Booths algorithm for Multiplication
Booths algorithm for MultiplicationBooths algorithm for Multiplication
Booths algorithm for MultiplicationVikas Yadav
 
Computer Graphic - Clipping
Computer Graphic - ClippingComputer Graphic - Clipping
Computer Graphic - Clipping2013901097
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer GraphicsKamal Acharya
 
Overview of Graphics System
Overview of Graphics SystemOverview of Graphics System
Overview of Graphics SystemPrathimaBaliga
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.Mohd Arif
 

What's hot (20)

Bresenham algorithm
Bresenham algorithmBresenham algorithm
Bresenham algorithm
 
Bezier curve & B spline curve
Bezier curve  & B spline curveBezier curve  & B spline curve
Bezier curve & B spline curve
 
Booths Multiplication Algorithm
Booths Multiplication AlgorithmBooths Multiplication Algorithm
Booths Multiplication Algorithm
 
boolean algebra and logic simplification
boolean algebra and logic simplificationboolean algebra and logic simplification
boolean algebra and logic simplification
 
2D viewing & clipping
2D viewing & clipping2D viewing & clipping
2D viewing & clipping
 
Bresenham circle
Bresenham circleBresenham circle
Bresenham circle
 
Mid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer GraphicsMid point line Algorithm - Computer Graphics
Mid point line Algorithm - Computer Graphics
 
Two dimensional geometric transformations
Two dimensional geometric transformationsTwo dimensional geometric transformations
Two dimensional geometric transformations
 
Unit iv Shop floor control and FMS
Unit iv Shop floor control and FMSUnit iv Shop floor control and FMS
Unit iv Shop floor control and FMS
 
DC servo motor
DC servo motorDC servo motor
DC servo motor
 
BRESENHAM’S LINE DRAWING ALGORITHM
BRESENHAM’S  LINE DRAWING ALGORITHMBRESENHAM’S  LINE DRAWING ALGORITHM
BRESENHAM’S LINE DRAWING ALGORITHM
 
Notes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphicsNotes 2D-Transformation Unit 2 Computer graphics
Notes 2D-Transformation Unit 2 Computer graphics
 
scan conversion of point , line and circle
scan conversion of point , line and circlescan conversion of point , line and circle
scan conversion of point , line and circle
 
Computer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and EllipseComputer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and Ellipse
 
Booths algorithm for Multiplication
Booths algorithm for MultiplicationBooths algorithm for Multiplication
Booths algorithm for Multiplication
 
Computer Graphic - Clipping
Computer Graphic - ClippingComputer Graphic - Clipping
Computer Graphic - Clipping
 
PLC
PLCPLC
PLC
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
Overview of Graphics System
Overview of Graphics SystemOverview of Graphics System
Overview of Graphics System
 
Ellipses drawing algo.
Ellipses drawing algo.Ellipses drawing algo.
Ellipses drawing algo.
 

Similar to Lines and curves algorithms

Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output PrimitivesPrathimaBaliga
 
Computer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptComputer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptAliZaib71
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2SanthiNivas
 
Unit 2
Unit 2Unit 2
Unit 2ypnrao
 
mid point algorithm.pdf
mid point algorithm.pdfmid point algorithm.pdf
mid point algorithm.pdfMehulMunshi3
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxNaveenaKarthik3
 
Lab lecture 2 bresenham
Lab lecture 2 bresenhamLab lecture 2 bresenham
Lab lecture 2 bresenhamsimpleok
 
Bressenham’s Midpoint Circle Drawing Algorithm
Bressenham’s Midpoint Circle Drawing AlgorithmBressenham’s Midpoint Circle Drawing Algorithm
Bressenham’s Midpoint Circle Drawing AlgorithmMrinmoy Dalal
 
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 algorithmsAmol Gaikwad
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxKokebe2
 
Lec05 circle ellipse
Lec05 circle ellipseLec05 circle ellipse
Lec05 circle ellipseMaaz Rizwan
 
Computer graphics notes 2 tutorials duniya
Computer graphics notes 2   tutorials duniyaComputer graphics notes 2   tutorials duniya
Computer graphics notes 2 tutorials duniyaTutorialsDuniya.com
 
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
 

Similar to Lines and curves algorithms (20)

Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output Primitives
 
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 Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
 
Dda algo notes
Dda algo notesDda algo notes
Dda algo notes
 
Unit 2
Unit 2Unit 2
Unit 2
 
2.circle
2.circle2.circle
2.circle
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
mid point algorithm.pdf
mid point algorithm.pdfmid point algorithm.pdf
mid point algorithm.pdf
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptx
 
Lab lecture 2 bresenham
Lab lecture 2 bresenhamLab lecture 2 bresenham
Lab lecture 2 bresenham
 
Bressenham’s Midpoint Circle Drawing Algorithm
Bressenham’s Midpoint Circle Drawing AlgorithmBressenham’s Midpoint Circle Drawing Algorithm
Bressenham’s Midpoint Circle Drawing Algorithm
 
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
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptx
 
Computer Graphics - lines, Circles and ellipse
Computer Graphics - lines, Circles and ellipseComputer Graphics - lines, Circles and ellipse
Computer Graphics - lines, Circles and ellipse
 
Lec05 circle ellipse
Lec05 circle ellipseLec05 circle ellipse
Lec05 circle ellipse
 
Computer graphics notes 2 tutorials duniya
Computer graphics notes 2   tutorials duniyaComputer graphics notes 2   tutorials duniya
Computer graphics notes 2 tutorials duniya
 
Computer graphics 2
Computer graphics 2Computer graphics 2
Computer graphics 2
 
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
 

Lines and curves algorithms

  • 1. WHERE TO DRAW A LINE??  Line drawing is accomplished by calculating intermediate positions along the line path between specified end points.  Precise definition of line drawing Given two points P and Q in the plane, both with integer coordinates, determine which pixels on a raster screen should be on in order to make a picture of a unit-width line segment starting from P and ending at Q.
  • 2. 6 (3, 5 3) 4 3 2 1 0 0 1 2 3 4 5 6
  • 3. Line drawing (contd.)  The thinnest line is of one-pixel wide. We will concentrate on drawing a line of 1 pixel resolution. The Cartesian slope-intercept equation for a straight line is y= m. ∆x + b m is the slope of the line and b is the y intercept. Given the endpoints of a line segment. m = (y2-y1) / (x2-x1) b= y1-m.x1
  • 4. Line Drawing (cont)  Also for any given interval ∆x along a line, we can compute the corresponding y interval ∆y from ∆y= m. x Similarly we can obtain the x interval ∆x corresponding to a specified ∆y as ∆x= ∆y / m These equations form the basis for determining deflection voltages in analog devices.
  • 5. Line Drawing (cont)  On Raster systems, lines are plotted with pixels, and step sizes in the horizontal and vertical directions are constrained by pixel separations. Hence we ought to “sample” a line at discrete positions and determine the nearest pixel to the line at each sampled position.
  • 6. Bresenham’s Line Algorithm An accurate, efficient raster line drawing algorithm developed by Bresenham, scan converts lines using only incremental integer calculations that can be adapted to display circles and other curves. Keeping in mind the symmetry property of lines, lets derive a more efficient way of drawing a line. Starting from the left end point (x0,y0) of a given line , we step to each successive column (x position) and plot the pixel whose scan-line y value closest to the line path Assuming we have determined that the pixel at (xk,yk) is to be displayed, we next need to decide which pixel to plot in column xk+1.
  • 7.
  • 8. Bresenham Line Algorithm (cont) Choices are(xk +1, yk) and (xk+1, yK+1) d1 = y – yk = m(xk + 1) + b – yk d2 = (yk + 1) – y = yk + 1- m(xk + 1) – b The difference between these 2 separations is d1-d2 = 2m(xk + 1) – 2 yK + 2b – 1  A decision parameter pk for the kth step in the line algorithm can be obtained by rearranging above equation so that it involves only integer calculations
  • 9. Bresenham’s Line Algorithm Define Pk = Δx ( d1-d2) = 2Δyxk-2 Δxyk + c The sign of Pk is the same as the sign of d1-d2, since Δx > 0. Parameter c is a constant and has the value 2Δy + Δx(2b-1) (independent of pixel position) If pixel at yk is closer to line-path than pixel at yk +1 (i.e, if d1 < d2) then pk is negative. We plot lower pixel in such a case. Otherwise , upper pixel will be plotted.
  • 10. Bresenham’s algorithm (cont) At step k + 1, the decision parameter can be evaluated as, pk+1 = 2Δyxk+1- 2Δxyk+1+ c Taking the difference of pk+ 1 and pk we get the following. pk+1 – pk = 2Δy(xk+1- xk)-2Δx(yk+1 – yk) But, xk+1 = xk +1, so that pk+1 = pk + 2Δy - 2 Δx(yk+1 – yk) Where the term yk+1-yk is either 0 or 1, depending on the sign of parameter pk
  • 11. Bresenham’s Line Algorithm The first parameter p0 is directly computed p0 = 2 Δyx0 - 2 Δxy0 + c = 2 Δyx0 + 2 Δxy0 +2 Δy + Δx (2b-1) Since (x0,y0) satisfies the line equation , we also have y0 = Δy/ Δx * x0 + b Combining the above 2 equations , we will have p0 = 2Δy – Δx The constants 2Δy and 2Δy-2Δx are calculated once for each time to be scan converted
  • 12. Bresenham’s Line Algorithm  So, the arithmetic involves only integer addition and subtraction of 2 constants STEP 1 Input the two end points and store the left end point in (x0,y0) STEP 2 Load (x0,y0) into the frame buffer (plot the first point) STEP 3 Calculate the constants Δx, Δy, 2Δy and 2Δy-2Δx and obtain the starting value of the decision parameter as p0 = 2Δy- Δx
  • 13. Bresenham’s Line Algorithm STEP 4 At each xk along the line, starting at k=0, perform the following test: If pk < 0 , the next point is (xk+1, yk) and pk+1 = pk + 2Δy Otherwise Point to plot is (xk+1, yk+1) pk+1 = pk + 2Δy - 2Δx Repeat step 4 (above step) Δx times
  • 14. Loading the frame buffer •Calculate frame-buffer addresses by incremental methods •For a bilevel system(1 bit per pixel), address for pixel(x,y) Addr(x,y) = addr(0,0)+y(xmax +1)+x Addr(x+1,y) = addr(x,y)+1 Addr(x+1,y+1) = addr(x,y)+ x max +2
  • 15. Where do we draw a circle??? Properties of a circle: A circle is defined as a set of points that are all the given distance (x ,y ). c c This distance relationship is expressed by the pythagorean theorem in Cartesian coordinates as (x – xc)2 + (y – yc) 2 = r2 We could use this equation to calculate the points on the circle circumference by stepping along x-axis in unit steps from xc-r to xc+r and calculate the corresponding y values at each position as y = yc +(- ) (r2 – (xc –x )2)1/2 This is not the best method: Considerable amount of computation Spacing between plotted pixels is not uniform
  • 16. Polar co-ordinates for a circle We could use polar coordinates r and θ, x = xc + r cosθ y = yc + r sinθ  A fixed angular step size can be used to plot equally spaced points along the circumference A step size of 1/r can be used to set pixel positions to approximately 1 unit apart for a continuous boundary But, note that circle sections in adjacent octants within one quadrant are symmetric with respect to the 45 deg line dividing the two octants Thus we can generate all pixel positions around a circle by calculating just the points within the sector from x=0 to x=y This method is still computationally expensive
  • 17.
  • 18.
  • 19. Bresenham to Midpoint  Bresenham requires explicit equation  Not always convenient (many equations are implicit)  Based on implicit equations: Midpoint Algorithm (circle, ellipse, etc.)  Implicit equations have the form F(x,y)=0.
  • 20. Midpoint Circle Algorithm We will first calculate pixel positions for a circle centered around the origin (0,0). Then, each calculated position (x,y) is moved to its proper screen position by adding xc to x and yc to y Note that along the circle section from x=0 to x=y in the first octant, the slope of the curve varies from 0 to -1 Circle function around the origin is given by fcircle(x,y) = x2 + y2 – r2 Any point (x,y) on the boundary of the circle satisfies the equation and circle function is zero
  • 21.
  • 22. Midpoint Circle Algorithm  For a point in the interior of the circle, the circle function is negative and for a point outside the circle, the function is positive  Thus,  f (x,y) < 0 if (x,y) is inside the circle boundary circle  fcircle(x,y) = 0 if (x,y) is on the circle boundary  fcircle(x,y) > 0 if (x,y) is outside the circle boundary
  • 23. Midpoint Circle Algorithm Assuming we have just plotted the pixel at (xk,yk) , we next need to determine whether the pixel at position (xk + 1, yk-1) is closer to the circle Our decision parameter is the circle function evaluated at the midpoint between these two pixels pk = fcircle (xk +1, yk-1/2) = (xk +1)2 + (yk -1/2)2 – r2 If pk < 0 , this midpoint is inside the circle and the pixel on the scan line yk is closer to the circle boundary. Otherwise, the mid position is outside or on the circle boundary, and we select the pixel on the scan line yk-1
  • 24. Midpoint Circle Algorithm Successive decision parameters are obtained using incremental calculations Pk+1 = fcircle(xk+1+1, yk+1-1/2) = [(xk+1)+1]2 + (yk+1 -1/2)2 –r2 OR Pk+1 = Pk+2(xK+1) + (yK+12 – yk2) – (yK+1- yk)+1 Where yk+1 is either yk or yk-1, depending on the sign of pk Increments for obtaining Pk+1: 2xk+1+1 if pk is negative 2xk+1+1-2yk+1 otherwise
  • 25. Midpoint circle algorithm Note that following can also be done incrementally: 2xk+1 = 2xk +2 2 yk+1 = 2yk – 2 At the start position (0,r) , these two terms have the values 2 and 2r-2 respectively Initial decision parameter is obtained by evaluating the circle function at the start position (x0,y0) = (0,r) p0 = fcircle(1, r-1/2) = 1+ (r-1/2)2-r2 OR P0 = 5/4 -r If radius r is specified as an integer, we can round p0 to p0 = 1-r
  • 26. The actual algorithm 1: Input radius r and circle center (xc,yc) and obtain the first point on the circumference of the circle centered on the origin as (x0,y0) = (0,r) 2: Calculate the initial value of the decision parameter as P0 = 5/4 - r 3: At each xk position starting at k = 0 , perform the following test: If pk < 0 , the next point along the circle centered on (0,0) is (xk+1, yk) and pk+1 = pk + 2xk+1 + 1
  • 27. The algorithm Otherwise the next point along the circle is (xk+1, yk-1) and pk+1 = pk + 2xk+1 +1 -2yk+1 Where 2xk+1 = 2xk+2 and 2yk+1 = 2yk-2 4: Determine symmetry points in the other seven octants 5: Move each calculated pixel position (x,y) onto the circular path centered on (x,yc) and plot the coordinate values x = x+ xc , y= y+ yc 6: Repeat steps 3 through 5 until x >= y