Public Group

# Drawing a 2d Circle Explanation

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

## 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 on other sites
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.

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633756
• Total Posts
3013710
×