SlideShare une entreprise Scribd logo
1  sur  9
Télécharger pour lire hors ligne
A Fast Bresenham Type Algorithm
       For Drawing Ellipses




                  by


             John Kennedy
        Mathematics Department
         Santa Monica College
            1900 Pico Blvd.
        Santa Monica, CA 90405

       rkennedy@ix.netcom.com
Except for this comment explaining that it is blank for
some deliberate reason, this page is intentionally blank!
Fast Ellipse Drawing
      There is a well-known algorithm for plotting straight lines on a display device or a plotter where
the grid over which the line is drawn consists of discrete points or pixels. In working with a lattice of
points it is useful to avoid floating point arithmetic. One of the first published algorithms was by Jack
Bresenham who worked for I.B.M. ("*'&Ñ. The main idea in the algorithm is to analyze and manipulate
the linear equation so that only integer arithmetic is used in all the calculations. Integer arithmetic has
the advantages of speed and precision; working with floating point values requires more time and
memory and such values would need to be rounded to integers anyway. In this paper we consider the
more difficult problem of approximating the plot of an ellipse on a grid of discrete pixels, using only
integer arithmetic.

    Before reading this paper it is suggested you read the paper by the same author on drawing circles.
The key ideas in the previous paper give all the details for circles, and there is much similarity between
drawing ellipses and circles. This paper will discuss the basic differences between circles and ellipses
but it assumes complete familiarity with the circle algorithm.
               #      #
    Assume B#  C# œ " represents the real variable equation of an ellipse which is to be plotted
               +     ,
using a grid of discrete pixels where each pixel has integer coordinates. There is no loss of generality
here since once the points are determined they may be translated to any elliptical center that is not the
origin (!ß !).

    We will compare errors associated with the B and C coordinates of the points that we are plotting.
Although we plot points of the form T (B3 ß C3 ), these points usually do not exactly satisfy the ellipses'
defining equation. In order to avoid dividing we re-write the above equation in the form

                                          ,# † B#  +# † C# œ ,# † +#

   For a given point T (B3 ß C3 ), the quantity

                                          ,# † B#  +# † C3  ,# † +#
                                                3
                                                          #


is a measure telling where T lies in relation to the true ellipse. If this quantity is negative it means T
lies inside the true ellipse, and if this quantity is positive it means T is outside the true ellipse. When
this quantity is ! (which may be rare but does happen) T is exactly on the ellipse. The expression

                                         l ,# † B#  +# † C3  ,# † +# l
                                                 3
                                                           #


is a more practical measure of the error. The absolute value will be needed when comparing two such
errors. We define a function which we call the I663:=/I<<9< which is an error measure for each
plotted point.

                           I663:=/I<<9<(B3 ß C3 ) œ l ,# † B#  +# † C3  ,# † +# l
                                                            3
                                                                      #




                                           Fast Ellipse Drawing     1
The ellipse plotting algorithm differs from the circle algorithm in that the ellipses' symmetry allows
only % simultaneous points to be plotted at a time. We still need only calculate points in the first
quadrant, but we need to complete a full *!° , not just %&° . In fact, the criterion for where to make the
break is determined by the slope of the tangent line to the ellipse.

    In the first quadrant the ellipse tangent line slope is always negative. Starting on the B-axis and
wrapping in a counterclockwise direction the slope is large and negative which means the C -coordinates
increase faster than the B-coordinates. But once the tangent line slope passes through the value " then
the B-coordinates start changing faster than the C -coordinates.

    Thus we will calculate two sets of points in the first quadrant. The first set starts on the positive B-
axis and wraps in a counterclockwise direction until the tangent line slope reaches ". The second set
will start on the positive C-axis and wrap in a clockwise direction until the tangent line slope again
reaches the value ". See the figure at the end of this paper.

   For the first set of points we will always increment C and we will test when to decrement B. This
process is very similar to that for circles. For the second set of points we will always increment B and
decide when to decrement C .

   Our test decision as to when to decrease B for the first set of points is based on the comparison of the
two values,

                    I663:=/I<<9<(B3  "ß C3  ")            and      I663:=/I<<9<(B3 ß C3  ")

   Then we choose either B3  " or B3 as our new B-coordinate depending on which of the two
I663:=/I<<9< values is the smallest.

   In any event, we need to know how the function I663:=/I<<9<(B3 ß C3 ) changes for each possible
change in its arguments. We do not need to calculate I663:=/I<<9< anew for each next point, if we just
keep track of how the value changes as the arguments change.

   For the first set of points,

              I663:=/I<<9<(B3  "ß C3  ") œ l ,# † ( B3  " )#  +# † ( C3  " )#  ,# † +# l

                       œ l ,# † B#  ,# † #B3  ,#  +# † C3  +# † #C3  +#  ,# † +# l
                                 3
                                                           #


                     œ l ,# † B#  +# † C3  ,# † +#  ,# † ( "  #B3 )  +# † ( #C3  " ) l
                               3
                                         #


   while
                     I663:=/I<<9<(B3 ß C3  ") œ l ,# † B3  +# † ( C3  " )#  ,# † +# l
                                                         #


                                  œ l ,# † B#  +# † C3  +# † #C3  +#  ,# † +# l
                                            3
                                                      #


                                  œ l ,# † B#  +# † C3  ,# † +#  +# † ( #C3  " ) l
                                            3
                                                      #




                                              Fast Ellipse Drawing      2
The analysis of the following ellipse inequality is almost identical to that for the circle inequality
except we multiply the appropriate change factor by either +# or ,# . The end result is that

                      I663:=/I<<9<(B3  "ß C3  ")  I663:=/I<<9<(B3 ß C3  ")

                                                if and only if

                 # † c ,# † B#  +# † C3  ,# † +#  +# † ( #C3  " ) d  ,# † ( "  #B3 )  !
                             3
                                       #


    When this last inequality holds then we should decrement B when we plot the next point
T (B3" ß C3" ).

   Having performed the above analysis we can begin to see the usefulness of defining three new
quantities.
                                G2+81/ œ ,# † ( "  #B3 )

                                       ] G2+81/ œ +# † ( #C3  " )

                               I663:=/I<<9< œ ,# † B#  +# † C3  ,# † +#
                                                    3
                                                              #




    These three quantities may also be calculated recursively (i.e., iteratively). Since when B3 and C3
change, they change by „ ", the quantities G2+81/ and ] G2+81/ always change by exactly
„ # † ,# and „ # † +# respectively. The initial G2+81/ value is +# † ( "  #+ ). The initial ] G2+81/
value is +# . The initial I663:=/I<<9< value is !. The program variable I663:=/I<<9< neither needs
nor uses an absolute value.

   We can analyze the tangent line slope by implicitly differentiating the equation

                                        ,# † B#  +# † C# œ ,# † +#

                                       # † , # † B  # † +# † C † C w œ !

   Solving for C w yields
                                                     # † ,# † B
                                             Cw œ
                                                     # † +# † C


   Although one might normally expect to reduce the above fraction by dividing by #, it turns out to be
more efficient to not reduce this fraction.

     Now we can determine where to break the two sets of calculated points in the first quadrant. The
first set corresponds to where C w  ". So we consider the inequality

                                             # † ,# † B
                                                          "
                                             # † +# † C


                                          Fast Ellipse Drawing      3
and we decide to continue to plot points while

                                      # † ,# † B  # † +# † C  !.

    Rather than perform the multiplications in this inequality each time through the while-loop test, we
again take advantage of the fact that whenever B and C change, they change by exactly " unit. So we
define two new values called W>9::381 and W>9::381] . Although we compute these values
recursively (iteratively), these values are really represented by the following equations.

                      W>9::381 œ # † ,# † B3 and W>9::381] œ # † +# † C3

    When plotting the first set of points the initial values are given by W>9::381 œ # † ,# † + and
W>9::381] œ !. For the first set of points B decreases by " at each stage so W>9::381 has a
corresponding decrease of # † ,# . For the first set of points W>9::381] increases by # † +# .

    When plotting the second set of points the initial values are given by W>9::381 œ ! and
W>9::381] œ # † +# † ,. For the second set of points B increases by " at each stage so W>9::381 has a
corresponding increase of # † ,# . For the second set of points W>9::381] decreases by # † +# each time
C decreases by ".

    Now we can give the ellipse plotting algorithm. Below, G , G] , and V+.3?= and ] V+.3?=
refer to the ellipse's center point coordinates and its horizontal and vertical radial values. So
V+.3?= œ + and ] V+.3?= œ ,. The constants X A9FW;?+</ and X A9EW;?+</ are the pre-
computed values # † ,# and # † +# .


procedure PlotEllipse(CX, CY, XRadius, YRadius : longint);
begin
   var X, Y                    : longint;
        XChange, YChange       : longint;
        EllipseError           : longint;
        TwoASquare, TwoBSquare : longint;
        StoppingX, StoppingY   : longint;

    TwoASquare := 2*XRadius*XRadius;
    TwoBSquare := 2*YRadius*YRadius;
    X : œ XRadius;
    Y := 0;
    XChange : œ YRadius*YRadius*(1  2*XRadius);
    YChange : œ XRadius*XRadius;
    EllipseError := 0;
    StoppingX := TwoBSquare*XRadius;
    StoppingY := 0;

    { algorithm continues on the next page }




                                        Fast Ellipse Drawing   4
while ( StoppingX   StoppingY ) do      {1st set of points,
yw >  1}
        begin
           Plot4EllipsePoints(X,Y);          {subroutine appears later}
           inc(Y);
           inc(StoppingY, TwoASquare);
           inc(EllipseError, YChange);
           inc(YChange,TwoASquare);
           if ((2*EllipseError + XChange) > 0 ) then
              begin
                 dec(X);
                 dec(StoppingX, TwoBSquare);
                 inc(EllipseError, XChange);
                 inc(XChange,TwoBSquare)
              end
        end;

   { 1st point set is done; start the 2nd set of points }

   X : œ 0;
   Y := YRadius;
   XChange : œ YRadius*YRadius;
   YChange : œ XRadius*XRadius*(1  2*YRadius);
   EllipseError := 0;
   StoppingX := 0;
   StoppingY := TwoASquare*YRadius;
   while ( StoppingX Ÿ StoppingY ) do {2nd set of points, yw <  1}
      begin
         Plot4EllipsePoints(X,Y);       {subroutine appears later}
         inc(X);
         inc(StoppingX, TwoBSquare);
         inc(EllipseError, XChange);
         inc(XChange,TwoBSquare);
         if ((2*EllipseError + YChange) > 0 ) then
            begin
               dec(Y);
               dec(StoppingY, TwoASquare);
               inc(EllipseError, YChange);
               inc(YChange,TwoASquare)
            end
      end
end; {procedure PlotEllipse}




                           Fast Ellipse Drawing   5
The subroutine called T 69>%I663:=/T 938>= takes advantage of the symmetry in the ellipse. We
only calculate the points in the first quadrant, but for each such point we actually plot % other points at
the same time as indicated in the figure below. The T 69>%I663:=/T 938>= subroutine would normally be
defined inside the above T 69>I663:=/ procedure. Also note that G and G] refer to the ellipse's
center point.

procedure Plot4EllipsePoints(X,Y : longint);
begin
   PutPixel(CX+X, CY+Y);          {point in quadrant                                                1}
   PutPixel(CX-X, CY+Y);          {point in quadrant                                                2}
   PutPixel(CX-X, CY-Y);          {point in quadrant                                                3}
   PutPixel(CX+X, CY-Y)           {point in quadrant                                                4}
end; {procedure Plot4EllipsePoints}

    As shown in the figure below, when this subroutine plots the first set of points, the four points would
be like those numbered ", %, &, and ) in the figure. When plotting the second set of points, the four
points would be like those numbered #, $, ', and ( in the figure.

                                                          Y+
                                                        2nd plotting direction     The tangent line slope
                                                        is clockwise               at this point = -1
                              (-x2 , y2 )                                 (x , y )
                                                                       2 2 2

                                        3               2nd set of                                            1st plotting
                                                        points                                         (x , y ) direction
                                                                                                         1 1
      (-x , y )                                                                                      1          is
           1   1
                                                                                                               counter-
                   4                                                               1st set of                 clockwise
     X-                                                                            points

                                                                                                                 X+
                   5                                                                            8
    (-x , -y )                                                                                       (x , -y )
       1       1                                                                                         1   1

                                        6                         7

                               (-x 2 , -y2 )                         (x , -y )
                                                                       2       2
                                                         Y-


Figure 1. This figure indicates the two sets of points in the first quadrant that get plotted.
          The plotting algorithm uses two sets with 4-point symmetry.




                                               Fast Ellipse Drawing        6
REFERENCES:

    ". Jack Bresenham, Algorithm for Computer Control of a Digital Plotter, IBM Systems
           Journal, Volume %, Number ", "*'&, pp. #&-$!.

    #. Jack Bresenham, A Linear Algorithm for Incremental Display of Circular Arcs,
           Communications of the ACM, Volume #!, Number #, February "*((, pp. "!!-"!'.

    $. Jerry R. Van Aken, An Efficient Ellipse-Drawing Algorithm, I.E.E.E. Computer Graphics
            & Applications, September "*)%, pp.#%-$&.

    %. Michael Abrash, The Good, the Bad, and the Run-sliced, Dr. Dobbs Journal, Number "*%,
          November "**#, pp."("-"('.




                                  Fast Ellipse Drawing   7

Contenu connexe

Similaire à Fast Bresenham Type Algorithm For Drawing Ellipses

Lesson 1 1 properties of real numbers
Lesson 1 1 properties of real numbersLesson 1 1 properties of real numbers
Lesson 1 1 properties of real numbersTerry Gastauer
 
Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...
Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...
Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...James Smith
 
Lines and angles /GEOMETRY
Lines and angles /GEOMETRYLines and angles /GEOMETRY
Lines and angles /GEOMETRYindianeducation
 
M210 Songyue.pages__MACOSX._M210 Songyue.pagesM210-S16-.docx
M210 Songyue.pages__MACOSX._M210 Songyue.pagesM210-S16-.docxM210 Songyue.pages__MACOSX._M210 Songyue.pagesM210-S16-.docx
M210 Songyue.pages__MACOSX._M210 Songyue.pagesM210-S16-.docxsmile790243
 
Trigonometry for class xi
Trigonometry for class xiTrigonometry for class xi
Trigonometry for class xiindu psthakur
 
Unidad ii matemática ANA VIRGUEZ
Unidad ii matemática ANA VIRGUEZ Unidad ii matemática ANA VIRGUEZ
Unidad ii matemática ANA VIRGUEZ anavirguez3
 
Integrated 2 Section 2-1
Integrated 2 Section 2-1Integrated 2 Section 2-1
Integrated 2 Section 2-1Jimbo Lamb
 
ROOT-LOCUS METHOD, Determine the root loci on the real axis /the asymptotes o...
ROOT-LOCUS METHOD, Determine the root loci on the real axis /the asymptotes o...ROOT-LOCUS METHOD, Determine the root loci on the real axis /the asymptotes o...
ROOT-LOCUS METHOD, Determine the root loci on the real axis /the asymptotes o...Waqas Afzal
 
Graph Theory 117 © David Lippman Creative Commons BY-
  Graph Theory   117 © David Lippman  Creative Commons BY-  Graph Theory   117 © David Lippman  Creative Commons BY-
Graph Theory 117 © David Lippman Creative Commons BY-maple8qvlisbey
 
Linear Inequality slayerix
Linear Inequality slayerixLinear Inequality slayerix
Linear Inequality slayerixAshams kurian
 

Similaire à Fast Bresenham Type Algorithm For Drawing Ellipses (20)

Karnaugh maps
Karnaugh mapsKarnaugh maps
Karnaugh maps
 
Lesson 1 1 properties of real numbers
Lesson 1 1 properties of real numbersLesson 1 1 properties of real numbers
Lesson 1 1 properties of real numbers
 
Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...
Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...
Projection of a Vector upon a Plane from an Arbitrary Angle, via Geometric (C...
 
Lines and angles /GEOMETRY
Lines and angles /GEOMETRYLines and angles /GEOMETRY
Lines and angles /GEOMETRY
 
MATHS SYMBOLS - TRIANGLES - FIRST PROPERTIES
MATHS SYMBOLS - TRIANGLES - FIRST PROPERTIESMATHS SYMBOLS - TRIANGLES - FIRST PROPERTIES
MATHS SYMBOLS - TRIANGLES - FIRST PROPERTIES
 
M210 Songyue.pages__MACOSX._M210 Songyue.pagesM210-S16-.docx
M210 Songyue.pages__MACOSX._M210 Songyue.pagesM210-S16-.docxM210 Songyue.pages__MACOSX._M210 Songyue.pagesM210-S16-.docx
M210 Songyue.pages__MACOSX._M210 Songyue.pagesM210-S16-.docx
 
Math1 1
Math1 1Math1 1
Math1 1
 
Trigonometry for class xi
Trigonometry for class xiTrigonometry for class xi
Trigonometry for class xi
 
College algebra -REAL Numbers
College algebra -REAL NumbersCollege algebra -REAL Numbers
College algebra -REAL Numbers
 
Solution kepler chap 1
Solution kepler chap 1Solution kepler chap 1
Solution kepler chap 1
 
Afa 2019
Afa 2019Afa 2019
Afa 2019
 
Unidad ii matemática ANA VIRGUEZ
Unidad ii matemática ANA VIRGUEZ Unidad ii matemática ANA VIRGUEZ
Unidad ii matemática ANA VIRGUEZ
 
Control chap7
Control chap7Control chap7
Control chap7
 
Integrated 2 Section 2-1
Integrated 2 Section 2-1Integrated 2 Section 2-1
Integrated 2 Section 2-1
 
ROOT-LOCUS METHOD, Determine the root loci on the real axis /the asymptotes o...
ROOT-LOCUS METHOD, Determine the root loci on the real axis /the asymptotes o...ROOT-LOCUS METHOD, Determine the root loci on the real axis /the asymptotes o...
ROOT-LOCUS METHOD, Determine the root loci on the real axis /the asymptotes o...
 
Buksis 7.1 new
Buksis 7.1 newBuksis 7.1 new
Buksis 7.1 new
 
Graph Theory 117 © David Lippman Creative Commons BY-
  Graph Theory   117 © David Lippman  Creative Commons BY-  Graph Theory   117 © David Lippman  Creative Commons BY-
Graph Theory 117 © David Lippman Creative Commons BY-
 
Linear Inequality slayerix
Linear Inequality slayerixLinear Inequality slayerix
Linear Inequality slayerix
 
Linear Inequality
Linear InequalityLinear Inequality
Linear Inequality
 
Parsetrees
ParsetreesParsetrees
Parsetrees
 

Dernier

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
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 SDThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
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 ConsultingTechSoup
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 

Dernier (20)

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
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
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
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
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
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"
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
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
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

Fast Bresenham Type Algorithm For Drawing Ellipses

  • 1. A Fast Bresenham Type Algorithm For Drawing Ellipses by John Kennedy Mathematics Department Santa Monica College 1900 Pico Blvd. Santa Monica, CA 90405 rkennedy@ix.netcom.com
  • 2. Except for this comment explaining that it is blank for some deliberate reason, this page is intentionally blank!
  • 3. Fast Ellipse Drawing There is a well-known algorithm for plotting straight lines on a display device or a plotter where the grid over which the line is drawn consists of discrete points or pixels. In working with a lattice of points it is useful to avoid floating point arithmetic. One of the first published algorithms was by Jack Bresenham who worked for I.B.M. ("*'&Ñ. The main idea in the algorithm is to analyze and manipulate the linear equation so that only integer arithmetic is used in all the calculations. Integer arithmetic has the advantages of speed and precision; working with floating point values requires more time and memory and such values would need to be rounded to integers anyway. In this paper we consider the more difficult problem of approximating the plot of an ellipse on a grid of discrete pixels, using only integer arithmetic. Before reading this paper it is suggested you read the paper by the same author on drawing circles. The key ideas in the previous paper give all the details for circles, and there is much similarity between drawing ellipses and circles. This paper will discuss the basic differences between circles and ellipses but it assumes complete familiarity with the circle algorithm. # # Assume B#  C# œ " represents the real variable equation of an ellipse which is to be plotted + , using a grid of discrete pixels where each pixel has integer coordinates. There is no loss of generality here since once the points are determined they may be translated to any elliptical center that is not the origin (!ß !). We will compare errors associated with the B and C coordinates of the points that we are plotting. Although we plot points of the form T (B3 ß C3 ), these points usually do not exactly satisfy the ellipses' defining equation. In order to avoid dividing we re-write the above equation in the form ,# † B#  +# † C# œ ,# † +# For a given point T (B3 ß C3 ), the quantity ,# † B#  +# † C3  ,# † +# 3 # is a measure telling where T lies in relation to the true ellipse. If this quantity is negative it means T lies inside the true ellipse, and if this quantity is positive it means T is outside the true ellipse. When this quantity is ! (which may be rare but does happen) T is exactly on the ellipse. The expression l ,# † B#  +# † C3  ,# † +# l 3 # is a more practical measure of the error. The absolute value will be needed when comparing two such errors. We define a function which we call the I663:=/I<<9< which is an error measure for each plotted point. I663:=/I<<9<(B3 ß C3 ) œ l ,# † B#  +# † C3  ,# † +# l 3 # Fast Ellipse Drawing 1
  • 4. The ellipse plotting algorithm differs from the circle algorithm in that the ellipses' symmetry allows only % simultaneous points to be plotted at a time. We still need only calculate points in the first quadrant, but we need to complete a full *!° , not just %&° . In fact, the criterion for where to make the break is determined by the slope of the tangent line to the ellipse. In the first quadrant the ellipse tangent line slope is always negative. Starting on the B-axis and wrapping in a counterclockwise direction the slope is large and negative which means the C -coordinates increase faster than the B-coordinates. But once the tangent line slope passes through the value " then the B-coordinates start changing faster than the C -coordinates. Thus we will calculate two sets of points in the first quadrant. The first set starts on the positive B- axis and wraps in a counterclockwise direction until the tangent line slope reaches ". The second set will start on the positive C-axis and wrap in a clockwise direction until the tangent line slope again reaches the value ". See the figure at the end of this paper. For the first set of points we will always increment C and we will test when to decrement B. This process is very similar to that for circles. For the second set of points we will always increment B and decide when to decrement C . Our test decision as to when to decrease B for the first set of points is based on the comparison of the two values, I663:=/I<<9<(B3  "ß C3  ") and I663:=/I<<9<(B3 ß C3  ") Then we choose either B3  " or B3 as our new B-coordinate depending on which of the two I663:=/I<<9< values is the smallest. In any event, we need to know how the function I663:=/I<<9<(B3 ß C3 ) changes for each possible change in its arguments. We do not need to calculate I663:=/I<<9< anew for each next point, if we just keep track of how the value changes as the arguments change. For the first set of points, I663:=/I<<9<(B3  "ß C3  ") œ l ,# † ( B3  " )#  +# † ( C3  " )#  ,# † +# l œ l ,# † B#  ,# † #B3  ,#  +# † C3  +# † #C3  +#  ,# † +# l 3 # œ l ,# † B#  +# † C3  ,# † +#  ,# † ( "  #B3 )  +# † ( #C3  " ) l 3 # while I663:=/I<<9<(B3 ß C3  ") œ l ,# † B3  +# † ( C3  " )#  ,# † +# l # œ l ,# † B#  +# † C3  +# † #C3  +#  ,# † +# l 3 # œ l ,# † B#  +# † C3  ,# † +#  +# † ( #C3  " ) l 3 # Fast Ellipse Drawing 2
  • 5. The analysis of the following ellipse inequality is almost identical to that for the circle inequality except we multiply the appropriate change factor by either +# or ,# . The end result is that I663:=/I<<9<(B3  "ß C3  ")  I663:=/I<<9<(B3 ß C3  ") if and only if # † c ,# † B#  +# † C3  ,# † +#  +# † ( #C3  " ) d  ,# † ( "  #B3 )  ! 3 # When this last inequality holds then we should decrement B when we plot the next point T (B3" ß C3" ). Having performed the above analysis we can begin to see the usefulness of defining three new quantities. G2+81/ œ ,# † ( "  #B3 ) ] G2+81/ œ +# † ( #C3  " ) I663:=/I<<9< œ ,# † B#  +# † C3  ,# † +# 3 # These three quantities may also be calculated recursively (i.e., iteratively). Since when B3 and C3 change, they change by „ ", the quantities G2+81/ and ] G2+81/ always change by exactly „ # † ,# and „ # † +# respectively. The initial G2+81/ value is +# † ( "  #+ ). The initial ] G2+81/ value is +# . The initial I663:=/I<<9< value is !. The program variable I663:=/I<<9< neither needs nor uses an absolute value. We can analyze the tangent line slope by implicitly differentiating the equation ,# † B#  +# † C# œ ,# † +# # † , # † B  # † +# † C † C w œ ! Solving for C w yields # † ,# † B Cw œ # † +# † C Although one might normally expect to reduce the above fraction by dividing by #, it turns out to be more efficient to not reduce this fraction. Now we can determine where to break the two sets of calculated points in the first quadrant. The first set corresponds to where C w  ". So we consider the inequality # † ,# † B  " # † +# † C Fast Ellipse Drawing 3
  • 6. and we decide to continue to plot points while # † ,# † B  # † +# † C  !. Rather than perform the multiplications in this inequality each time through the while-loop test, we again take advantage of the fact that whenever B and C change, they change by exactly " unit. So we define two new values called W>9::381 and W>9::381] . Although we compute these values recursively (iteratively), these values are really represented by the following equations. W>9::381 œ # † ,# † B3 and W>9::381] œ # † +# † C3 When plotting the first set of points the initial values are given by W>9::381 œ # † ,# † + and W>9::381] œ !. For the first set of points B decreases by " at each stage so W>9::381 has a corresponding decrease of # † ,# . For the first set of points W>9::381] increases by # † +# . When plotting the second set of points the initial values are given by W>9::381 œ ! and W>9::381] œ # † +# † ,. For the second set of points B increases by " at each stage so W>9::381 has a corresponding increase of # † ,# . For the second set of points W>9::381] decreases by # † +# each time C decreases by ". Now we can give the ellipse plotting algorithm. Below, G , G] , and V+.3?= and ] V+.3?= refer to the ellipse's center point coordinates and its horizontal and vertical radial values. So V+.3?= œ + and ] V+.3?= œ ,. The constants X A9FW;?+</ and X A9EW;?+</ are the pre- computed values # † ,# and # † +# . procedure PlotEllipse(CX, CY, XRadius, YRadius : longint); begin var X, Y : longint; XChange, YChange : longint; EllipseError : longint; TwoASquare, TwoBSquare : longint; StoppingX, StoppingY : longint; TwoASquare := 2*XRadius*XRadius; TwoBSquare := 2*YRadius*YRadius; X : œ XRadius; Y := 0; XChange : œ YRadius*YRadius*(1  2*XRadius); YChange : œ XRadius*XRadius; EllipseError := 0; StoppingX := TwoBSquare*XRadius; StoppingY := 0; { algorithm continues on the next page } Fast Ellipse Drawing 4
  • 7. while ( StoppingX   StoppingY ) do {1st set of points, yw >  1} begin Plot4EllipsePoints(X,Y); {subroutine appears later} inc(Y); inc(StoppingY, TwoASquare); inc(EllipseError, YChange); inc(YChange,TwoASquare); if ((2*EllipseError + XChange) > 0 ) then begin dec(X); dec(StoppingX, TwoBSquare); inc(EllipseError, XChange); inc(XChange,TwoBSquare) end end; { 1st point set is done; start the 2nd set of points } X : œ 0; Y := YRadius; XChange : œ YRadius*YRadius; YChange : œ XRadius*XRadius*(1  2*YRadius); EllipseError := 0; StoppingX := 0; StoppingY := TwoASquare*YRadius; while ( StoppingX Ÿ StoppingY ) do {2nd set of points, yw <  1} begin Plot4EllipsePoints(X,Y); {subroutine appears later} inc(X); inc(StoppingX, TwoBSquare); inc(EllipseError, XChange); inc(XChange,TwoBSquare); if ((2*EllipseError + YChange) > 0 ) then begin dec(Y); dec(StoppingY, TwoASquare); inc(EllipseError, YChange); inc(YChange,TwoASquare) end end end; {procedure PlotEllipse} Fast Ellipse Drawing 5
  • 8. The subroutine called T 69>%I663:=/T 938>= takes advantage of the symmetry in the ellipse. We only calculate the points in the first quadrant, but for each such point we actually plot % other points at the same time as indicated in the figure below. The T 69>%I663:=/T 938>= subroutine would normally be defined inside the above T 69>I663:=/ procedure. Also note that G and G] refer to the ellipse's center point. procedure Plot4EllipsePoints(X,Y : longint); begin PutPixel(CX+X, CY+Y); {point in quadrant 1} PutPixel(CX-X, CY+Y); {point in quadrant 2} PutPixel(CX-X, CY-Y); {point in quadrant 3} PutPixel(CX+X, CY-Y) {point in quadrant 4} end; {procedure Plot4EllipsePoints} As shown in the figure below, when this subroutine plots the first set of points, the four points would be like those numbered ", %, &, and ) in the figure. When plotting the second set of points, the four points would be like those numbered #, $, ', and ( in the figure. Y+ 2nd plotting direction The tangent line slope is clockwise at this point = -1 (-x2 , y2 ) (x , y ) 2 2 2 3 2nd set of 1st plotting points (x , y ) direction 1 1 (-x , y ) 1 is 1 1 counter- 4 1st set of clockwise X- points X+ 5 8 (-x , -y ) (x , -y ) 1 1 1 1 6 7 (-x 2 , -y2 ) (x , -y ) 2 2 Y- Figure 1. This figure indicates the two sets of points in the first quadrant that get plotted. The plotting algorithm uses two sets with 4-point symmetry. Fast Ellipse Drawing 6
  • 9. REFERENCES: ". Jack Bresenham, Algorithm for Computer Control of a Digital Plotter, IBM Systems Journal, Volume %, Number ", "*'&, pp. #&-$!. #. Jack Bresenham, A Linear Algorithm for Incremental Display of Circular Arcs, Communications of the ACM, Volume #!, Number #, February "*((, pp. "!!-"!'. $. Jerry R. Van Aken, An Efficient Ellipse-Drawing Algorithm, I.E.E.E. Computer Graphics & Applications, September "*)%, pp.#%-$&. %. Michael Abrash, The Good, the Bad, and the Run-sliced, Dr. Dobbs Journal, Number "*%, November "**#, pp."("-"('. Fast Ellipse Drawing 7