Drawing a 2d Circle Explanation

Started by
0 comments, last by alvaro 13 years, 4 months ago
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
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.

This topic is closed to new replies.

Advertisement