Fastest way to draw circles

what’s the fastest way to draw circles of varying radii to the screen?
do it myself? if so, what drawing method should i use?–

At 16:02 11.03.2002 -0800, you wrote:

what’s the fastest way to draw circles of varying radii to the screen?
do it myself? if so, what drawing method should i use?

Hm, there are various ways … whithout hardware, with hardware, the
oldschool-way and so on…
the oldschool-way is with a variation of the Bresenham’s
algorithm. Newschool is, you decide how many segments your circle will
have, make a table of sines and a table of cosines of #segments length, and
then your read costab, multiply with radius -> that’s x_coordinate, read
sintab, multiply with radius -> y_coord. now you draw staight lines
between two of those pairs of coordinates, then loop thru your segments in
this manner. easy, isn’t it? Just simple math.
St0fF.

If you have to write the code to draw it yourself, search for something like
"Bresenham circle algorithm" in any search engine. Otherwise, you can simply
use the SDL_gfx library found here: http://www.ferzkopp.net/Software/SDL_gfx-
2.0/
It draws many graphics primitives with some other extra options too if you’re
interested.

Mahmoud>what’s the fastest way to draw circles of varying radii to the screen?

do it myself? if so, what drawing method should i use?


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

what’s the fastest way to draw circles of varying radii to the screen?
do it myself? if so, what drawing method should i use?

Bresenham’s circle algorithm is generally the best fastest way. I really
don’t know much about the algorithm, though I do know a lot about
Bresenham’s line algorithm. A web search should point to the algorithm
somewhere.

You can do it yourself, or grab an SDL add one library that does it for you.
Up to you.

-Jason

----- Original Message -----
From: chris@luethy.net (Christopher Thielen)
To:
Sent: Monday, March 11, 2002 7:02 PM
Subject: [SDL] fastest way to draw circles

This is an idea:

int cir(SDL_Rect *twoPoints,SDL_Surface *dst,Uint32 couleur)
{
SDL_Rect barres;
double iCercle;
double plus=(double)(2/(double)(twoPoints->w));

for (iCercle=0; iCercle < 2*3.1416;iCercle=iCercle+plus)
{

putpixel(dst,abs(twoPoints->x)+twoPoints->w/2+(cos(iCercle)*twoPoints->w/2),

abs(twoPoints->y)+twoPoints->h/2+(sin(iCercle)*twoPoints->h/2),couleur);
}
}

“Jason Hoffoss” a ?crit dans le message news:
mailman.1015895104.15271.sdl at libsdl.org…> ----- Original Message -----

From: “Christopher Thielen”
To:
Sent: Monday, March 11, 2002 7:02 PM
Subject: [SDL] fastest way to draw circles

what’s the fastest way to draw circles of varying radii to the screen?
do it myself? if so, what drawing method should i use?

Bresenham’s circle algorithm is generally the best fastest way. I really
don’t know much about the algorithm, though I do know a lot about
Bresenham’s line algorithm. A web search should point to the algorithm
somewhere.

You can do it yourself, or grab an SDL add one library that does it for
you.
Up to you.

-Jason

That’s not going to be very fast, though. I would personally never use a
putpixel() call for drawing anything that requires more than just 1 pixel,
btw.

The way Bresenham’s algorithm works I believe is that it takes advantage of
the fact that a circle is just a 45 degree arc reflected 7 times to make the
whole thing. This cuts the heavy math down to only 1/8 the time. Probably
other tricks it uses as well I’m sure. Seriously, you should check out the
algorithm rather than try and reinvent the wheel. Learn from the master, as
they say. If you still think you can do better after that, then give it a
shot, but I think you should at least familiarize yourself with what’s
already invented first.

-Jason> ----- Original Message -----

From: bille2@free.fr (Bille2)
Newsgroups: loki.open-source.sdl
To:
Sent: Tuesday, March 12, 2002 3:25 PM
Subject: Re: [SDL] fastest way to draw circles

This is an idea:

int cir(SDL_Rect *twoPoints,SDL_Surface *dst,Uint32 couleur)
{
SDL_Rect barres;
double iCercle;
double plus=(double)(2/(double)(twoPoints->w));

for (iCercle=0; iCercle < 2*3.1416;iCercle=iCercle+plus)
{

putpixel(dst,abs(twoPoints->x)+twoPoints->w/2+(cos(iCercle)*twoPoints->w/2),

abs(twoPoints->y)+twoPoints->h/2+(sin(iCercle)*twoPoints->h/2),couleur);
}
}

“Jason Hoffoss” a ?crit dans le message news:
mailman.1015895104.15271.sdl at libsdl.org

----- Original Message -----
From: “Christopher Thielen”
To:
Sent: Monday, March 11, 2002 7:02 PM
Subject: [SDL] fastest way to draw circles

what’s the fastest way to draw circles of varying radii to the screen?
do it myself? if so, what drawing method should i use?

Bresenham’s circle algorithm is generally the best fastest way. I
really

don’t know much about the algorithm, though I do know a lot about
Bresenham’s line algorithm. A web search should point to the algorithm
somewhere.

You can do it yourself, or grab an SDL add one library that does it for
you.
Up to you.

-Jason


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

try this :

void circle( int xc, int yc, int Rc, SDL_Surface *PIX, unsigned char col)
// draw circle with Brehensam (only integer)
{
int X1=xc; int PX,PY;
int Y1=yc;
int X,Y,delta, ep;
Y=Rc;
delta=Y-1;
X=1;
while( Y>=0 )
{
ep=delta+delta;

PX=X1+X;
PY=Y1+Y;

putpixel(PIX,PX,PY,col);

PX=X1-X;
putpixel(PIX,PX,PY,col);

PY=Y1-Y;
putpixel(PIX,PX,PY,col);

PX=X1+X;
putpixel(PIX,PX,PY,col);

if (ep<0)
{
ep+=X;
if (ep<0)
delta+=–Y;
else
delta+=(–Y)-(++X);
}
else
{
ep-=Y;
if (ep>=0)
delta-=++X;
else
delta+=(–Y)-(++X);
}
}
}

Yeah!
That’s what it should look like … no need for sintabs or even
floating-point calculation … as somebody said, learn from the master!
St0ff.

At 23:58 12.03.2002 +0100, you wrote:>try this :

void circle( int xc, int yc, int Rc, SDL_Surface *PIX, unsigned char col)
// draw circle with Brehensam (only integer)
{
int X1=xc; int PX,PY;
int Y1=yc;
int X,Y,delta, ep;
Y=Rc;
delta=Y-1;
X=1;
while( Y>=0 )
{
ep=delta+delta;

PX=X1+X;
PY=Y1+Y;

putpixel(PIX,PX,PY,col);

PX=X1-X;
putpixel(PIX,PX,PY,col);

PY=Y1-Y;
putpixel(PIX,PX,PY,col);

PX=X1+X;
putpixel(PIX,PX,PY,col);

if (ep<0)
{
ep+=X;
if (ep<0)
delta+=–Y;
else
delta+=(–Y)-(++X);
}
else
{
ep-=Y;
if (ep>=0)
delta-=++X;
else
delta+=(–Y)-(++X);
}
}
}


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

// Draw circle with midpoint algorythm (integer math only) uses octet
mirroring
void circle( int xc, int yc, int R, SDL_Surface *PIX, unsigned char col)
{
int x=0,xx=0;
int y=R,yy=R+R;
int p=1-R;

// Draw the X=0 and Y=0 points
putpixel(PIX, xc, yc-y, col);
putpixel(PIX, xc, yc+y, col);
putpixel(PIX, xc-y, yc, col);
putpixel(PIX, xc+y, yc, col);

while(x<y) {
xx+=2; // 2x
++x;
if(p>=0) {
yy-=2; // 2
y
–y;
p -= yy;
}
p += xx+1;

 putpixel(PIX,xc-x,yc-y,col);
 putpixel(PIX,xc+x,yc-y,col);
 putpixel(PIX,xc-x,yc+y,col);
 putpixel(PIX,xc+x,yc+y,col);
 putpixel(PIX,xc-y,yc-x,col);
 putpixel(PIX,xc+y,yc-x,col);
 putpixel(PIX,xc-y,yc+x,col);
 putpixel(PIX,xc+y,yc+x,col);

}
if(x=y) { // Draw the exact 45 degree points if necessary
putpixel(PIX,xc-x,yc-y,col);
putpixel(PIX,xc+x,yc-y,col);
putpixel(PIX,xc-x,yc+y,col);
putpixel(PIX,xc+x,yc+y,col);
}
}