Finding Circumference points of Circle and Drawing Circle on windows Form.

Posted by SurajRane under C# category on | Views : 6548
We can draw circle on windows form using various functions provided by System.Drawing namespace. But using those methods will not give you points on circumference of circle which you may need sometime. Here I come up with solution to this problem.

We can find points on circumference using following mathematical formulas.
X = x0 + r Cos 0
Y = y0 + r Sin 0
Point on circumference = (X, Y) and
Center = (x0, y0)
An angle = 0
Here is the code for finding points and drawing the circle

private void Form1_Paint(object sender, PaintEventArgs e)
//Graphics object
Graphics graphics = e.Graphics;

//array of points
PointF[] CircumferencePoints = new PointF[360];

//path type points to show direction
byte[] pathType = new byte[360];

//loop and collect points starting from angle 0 to 360
double THETA = 0.0;

for (int i = 0; i < 360; i++)

CircumferencePoints[i].X = (float)(200 + 100 * (Math.Cos(THETA * Math.PI / 180)));
CircumferencePoints[i].Y = (float)(200 + 100 * (Math.Sin(THETA * Math.PI / 180)));

//keep angle increasing by 1
THETA += 1.0;

//give path type
pathType[i] = (byte)PathPointType.Line;

//This smoothing is neccessary for High quality curve
graphics.SmoothingMode = SmoothingMode.HighQuality;

System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath(CircumferencePoints, pathType);

//Draw circle using Draw path method
graphics.DrawPath(new Pen(Brushes.Black, 3), path);

//Fill the circle with color
graphics.FillClosedCurve(Brushes.Orange, CircumferencePoints);

Comments or Responses

Login to post response