# Drawing a circle w/o sin, cos, and sqrt?

This topic is 4981 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I would like to make a circle via a line strip, 2 ways I can think of doing it are a little slow for my liking. Method 1)
for(int i=0;i<NUM_LINES;i++)
{
xcoord = RADIUS * cos(i*2*PI/NUM_LINES);
ycoord = RADIUS * sin(i*2*PI/NUM_LINES);
}

Method 2) for(float i = -RADIUS; i < RADIUS; i +=RADIUS/NUM_LINES) { ycoord = i; xcoord1 = sqrt(RADIUS^2 - i^2); xcoord2 = -xcoord1; } Where both xcoord1 and xcoord2 share the same ycoord. I have a feeling I’m forgetting/overlooking something, know of a faster way?

##### Share on other sites
Quote:
 Original post by skowMethod 1)for(int i=0;i

You only have to calculate a quarter of the circle if you use the right number of lines: cos(0) is the same as -cos(2 * PI) and so on..

##### Share on other sites
just make the vertices once

Vector verts[360];

CreateCircle()
{
for ( i = 0; i < 360; i++ )
verts.x = cos(i);
verts.y = sin(i);
}

Then Draw them.

DrawCircle(float size, int numVertsToDraw)
{
step = 360/numVertsToDraw;
for ( int i = 0;
i < numVertsToDraw;
i+= step )
DrawLine( verts * size, vert[i+1] * size );

}

##### Share on other sites
Quote:
Original post by WanMaster
Quote:
 Original post by skowMethod 1)for(int i=0;i

You only have to calculate a quarter of the circle if you use the right number of lines: cos(0) is the same as -cos(2 * PI) and so on..

I believe you can get away with an eighth, too.

##### Share on other sites
Quote:
Original post by Snaily
Quote:
Original post by WanMaster
Quote:
 Original post by skowMethod 1)`for(int i=0;i

You only have to calculate a quarter of the circle if you use the right number of lines: cos(0) is the same as -cos(2 * PI) and so on..

I believe you can get away with an eighth, too.

Yes, you are correct. Didn't think about that.

##### Share on other sites
Use a look-up table for sin/cos (can be way less than 360 if you know the max amount of lines - I use 20 for a 20px (diameter) circle and that looks fine)..

##### Share on other sites
Thanks guys, I'm going with a lookup table.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634063
• Total Posts
3015308
×