public static VertexPositionColor[] GetCircleVertices(int radius, int angleInDegrees, out int primitiveCount, AlignmentPlaneType orientationType) { primitiveCount = 360 / angleInDegrees; VertexPositionColor[] vertices = new VertexPositionColor[primitiveCount + 1]; Vector3 position = Vector3.Zero; float angleInRadians = MathHelper.ToRadians(angleInDegrees); for (int i = 0; i <= primitiveCount; i++) { if (orientationType == AlignmentPlaneType.XY) { position.X = (float)(radius * Math.Cos(i * angleInRadians)); position.Y = (float)(radius * Math.Sin(i * angleInRadians)); } else if (orientationType == AlignmentPlaneType.XZ) { position.X = (float)(radius * Math.Cos(i * angleInRadians)); position.Z = (float)(radius * Math.Sin(i * angleInRadians)); } else { position.Y = (float)(radius * Math.Cos(i * angleInRadians)); position.Z = (float)(radius * Math.Sin(i * angleInRadians)); } vertices[i] = new VertexPositionColor(position, Color.White); } return(vertices); }
//returns the vertices for a circle with a user-defined radius, sweep angle, and orientation public static VertexPositionColor[] GetVerticesPositionColorCircle(int radius, int sweepAngleInDegrees, AlignmentPlaneType orientationType) { //sweep angle should also be >= 1 and a multiple of 360 //if angle is not a multiple of 360 the circle will not close - remember we are drawing with a LineStrip if ((sweepAngleInDegrees < 1) || (360 % sweepAngleInDegrees != 0)) { return(null); } //number of segments forming the circle (e.g. for sweepAngleInDegrees == 90 we have 4 segments) int segmentCount = 360 / sweepAngleInDegrees; //segment angle float rads = MathHelper.ToRadians(sweepAngleInDegrees); //we need one more vertex to close the circle (e.g. 4 + 1 vertices to draw four lines) VertexPositionColor[] vertices = new VertexPositionColor[segmentCount + 1]; float a, b; for (int i = 0; i < vertices.Length; i++) { //round the values so we dont end up with the two oordinate values very close to but not equals to 0 a = (float)(radius * Math.Round(Math.Cos(rads * i), ROUND_PRECISION_FLOAT)); b = (float)(radius * Math.Round(Math.Sin(rads * i), ROUND_PRECISION_FLOAT)); if (orientationType == AlignmentPlaneType.XY) { vertices[i] = new VertexPositionColor(new Vector3(a, b, 0), Color.White); } else if (orientationType == AlignmentPlaneType.XZ) { vertices[i] = new VertexPositionColor(new Vector3(a, 0, b), Color.White); } else { vertices[i] = new VertexPositionColor(new Vector3(0, a, b), Color.White); } } return(vertices); }