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?
Drawing a circle w/o sin, cos, and sqrt?
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)
Quote:Original post by skow
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); }
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..
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 );
}
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 );
}
Quote:Original post by WanMasterQuote:Original post by skow
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); }
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.
Quote:Original post by SnailyQuote:Original post by WanMasterQuote:Original post by skow
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); }
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.
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)..
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement