• Advertisement
Sign in to follow this  

Drawing a 2d Circle Explanation

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

vertices = new VertexPositionColor[100];
for (int i = 0; i < 99; i++)
{
float angle = (float)(i / 100.0 * Math.PI * 2);
vertices.Position = new Vector3(200 + (float)Math.Cos(angle) * 100, 200 + (float)Math.Sin(angle) * 100, 0);
vertices.Color = Color.Black;
}
vertices[99] = vertices[0];


Can someone explain this code? I understand what it's doing as far as the for loop, but I'm trying to learn trig. Can someone explain it step by step? The output of this is a 2d circle. ;o

Share this post


Link to post
Share on other sites
Advertisement
The code is pretty straight forward. This is the most basic thing you can do with sine and cosine. The functions sin() and cos() take angles in radians; perhaps that's what was confusing you. Other than that, you should learn about trigonometry from a book, or you should have paid attention in high school.

The assignment vertices[99] = vertices[0]; seems like a bad idea. If you need the last point to be the same as the first, you need 101 points, or you need to divide the circle in 99 equal parts. As it is, there is a gap between 98 and 99.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement