# Thread: Circles!! help

1. ## Circles!! help

im trying to get a perfect circle going here
im using this code below.
its not exactly a perfect circle though
more like a Octacontagon its circular but with rough edges
any suggestions?

Code:
```void circle(int rx, int ry, int r)
{
int x,y;
double d;//detail
const double pi = 3.14159265; //more or less
for(d=0; d<=2*pi; d+=0.01) //you can play with the value to be added to d
{
x=rx+sin(d)*r;
y=ry+sin(d+(pi/2))*r;
putpixel(x,y);
}
}```

2. Originally Posted by -Bl00d-
im trying to get a perfect circle going here
im using this code below.
its not exactly a perfect circle though
more like a Octacontagon its circular but with rough edges
any suggestions?

Code:
```void circle(int rx, int ry, int r)
{
int x,y;
double d;//detail
const double pi = 3.14159265; //more or less
for(d=0; d<=2*pi; d+=0.01) //you can play with the value to be added to d
{
x=rx+sin(d)*r;
y=ry+sin(d+(pi/2))*r;
putpixel(x,y);
}
}```

If this is for a directX game construct 360 vertices one from each degree of rotation and then allow directX to render the necessary lines.
Example code (i just wrote this up here, so there may be errors0
Code:
```void render(int xLoc, int yLoc, int rad){
//create pLine here, dont feel like looking up params list for D3DXCreateLine()
D3DXVECTOR2 vec[360];
for(int i = 0; i < 360; ++i){
vec[i].x=xLoc+(rad*cos((i)*(PI/180)));
vec[i].y=yLoc+(rad*sin((i)*(PI/180)));
}
pLine->Begin();
pLine->Draw(vec,360,D3DCOLOR_XRGB(10,200,10));
pLine->End();
}```

3. ## The Following User Says Thank You to Saltine For This Useful Post:

-Bl00d- (01-14-2013)

4. ahhh! Saltine your awesome dude!

5. ## The Following 2 Users Say Thank You to -Bl00d- For This Useful Post:

kittens4life (01-14-2013),Saltine (01-14-2013)

6. Originally Posted by -Bl00d-
ahhh! Saltine your awesome dude!
Oh, if you do create pLine every function call don't forget to do pLine->Release(); at the end of the function or it will leak memory like a bitch

7. ## The Following 3 Users Say Thank You to Saltine For This Useful Post:

-Bl00d- (01-14-2013),[MPGH]Flengo (01-14-2013),kittens4life (01-14-2013)

8. I was about to mention Saltine to this thread since I know he loves circles. Guess he already got to it

/Solved
/Closed

9. ## The Following User Says Thank You to Flengo For This Useful Post:

Saltine (01-14-2013)