delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/02/10:03:28

From: Jeff Weeks <pweeks AT execulink DOT com>
Newsgroups: rec.games.programmer,comp.os.msdos.djgpp
Subject: Re: bresenham's circle
Date: Fri, 01 Aug 1997 13:32:52 -0400
Organization: Code X Software
Lines: 77
Message-ID: <33E21DC4.72FF58C1@execulink.com>
References: <33DF4527 DOT 671 AT mindspring DOT com> <kn5WwGAfZ$3zEwbB AT jenkinsdavid DOT demon DOT co DOT uk> <33E06240 DOT 3FE7 AT mindspring DOT com> <vMFk6FATSU4zEwx$@jenkinsdavid.demon.co.uk> <33e27d37 DOT 4438718 AT news DOT concentric DOT net>
NNTP-Posting-Host: ppp4.mercury.execulink.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Avery Lee wrote:
> 
> David Jenkins <me AT jenkinsdavid DOT demon DOT co DOT uk> wrote:
> 
> >In article <33E06240 DOT 3FE7 AT mindspring DOT com>, Derek Greene
> ><topcoder AT mindspring DOT com> writes
> >>David Jenkins wrote:
> >>> Is this Bresenhams circle routine??
> >>> Or is it the one where you calculate an eigth of a circle and draw the
> >>> full circle from these calcs, never seen that one in action though.
> >>
> >>according to my info, bresenham's is the one where you calculate the
> >>eighth
> >
> >Is it faster than the routine I posted??
> >I did read about it somewhere, I figured that recalculating the eigth to
> >the other 7 eigths would take offset the benefits.
> 
> No.  The other 7 octants are simply reflections, so you can generate them
> by reversing signs or by swapping x and y.  There is no division in the
> algorithm, which is very time consuming even on a Pentium.  The drawback to
> Bresenham's circle algorithm is that it can only generate circles, so to
> get a circle on an output device without a 1:1 aspect ratio, you need to
> switch to an ellipse algorithm.

Are you sure?  According to snippets, the Bresenham circle algorithm CAN
be used to draw elipses.  Here's the code they show:

/* draws a circle at (xc, yc) with radius r in color c
**
** note: the scaling factor of (SCREEN_WIDTH / SCREEN_HEIGTH) is used
when
** updating d.  This makes round circles.  If you want ellipses, you can
** modify that ratio.
*/

void bresenham_circle(int xc, int yc, int r, char c)
{
      int x = 0, y = r, d = 2 * (1 - r);

      while(y >= 0)
      {
            plotdot(xc + x, yc + y, c);
            plotdot(xc + x, yc - y, c);
            plotdot(xc - x, yc + y, c);
            plotdot(xc - x, yc - y, c);
            if(d + y > 0)
            {
                  y -= 1;
                  d -= (2 * y * SCREEN_WIDTH / SCREEN_HEIGTH) - 1;
            }
            if(x > d)
             {
                  x += 1;
                  d += (2 * x) + 1;
            }
      }
}


Is this not bresenham?  It seems that everybody has their own opinion as
to which code is really bresenhams.  According to this, the code draws
one 4th (not an 8th) and mirrors the rest.

Also, to the origional poster:  This code used to show gaps as well. 
All it needed, however, was to change the "while(y > 0)" to "while(y >=
0)" and that fixed it.

Jeff

--------------------------------------------
            - Code X Software -
       Programming to a Higher Power
  
  email: mailto:pweeks AT execulink DOT com
  web:	 http://www.execulink.com/~pweeks/
--------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019