Ask Your Question
-1

Finding a point on a circle?

asked 2014-07-09 08:15:43 -0600

brycemh gravatar image

updated 2017-08-01 18:35:27 -0600

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 flag offensive close merge delete

Comments

1 answer

Sort by ยป oldest newest most voted
4

answered 2014-07-09 08:36:23 -0600

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

public static PointF PointOnCircle(float radius, float angleInDegrees, Point origin)
{
    //radius -> Radius of Circle & Origin -> Circle Centre.
    // 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);
}

image description

edit flag offensive delete link more

Comments

@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.

brycemh gravatar imagebrycemh ( 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?

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

Question Tools

Stats

Asked: 2014-07-09 08:15:43 -0600

Seen: 867 times

Last updated: Sep 22 '14