Finding a point on a circle?

Hey guys,

I am trying to create a code that will draw a line for every nth degree around the center point of a circle (like a clock). Does anyone know how to go about doing this?

Thanks!

edit retag close merge delete

Sort by ยป oldest newest most voted

Hi @brycemh! You can calculate a Point on a Circle as follows:

public static PointF PointOnCircle(float radius, float angleInDegrees, Point origin)
{
// Convert from degrees to radians via multiplication by PI/180
float x = (float)(radius * Math.Cos(angleInDegrees * Math.PI / 180F)) + origin.X;
float y = (float)(radius * Math.Sin(angleInDegrees * Math.PI / 180F)) + origin.Y;

return new PointF(x, y);
}


more

@BalajiRenganathan I tried using the answer you gave, but it didn't work, it gave me a few error messages after I changed some of the values.

( 2014-07-11 06:11:57 -0600 )edit

@BalajiRenganathan I figured it out, but I have a question; how will I use this point to create a loop that will draw a line from the center to the edge of a circle? example: I have the radius (150), the point on the circle (242.7,176.3) , and the degree (36), how can I draw a line for every 36th degree?

( 2014-07-11 06:45:27 -0600 )edit