How do I get x,y values on a circle perimeter ?

I need to get a point (x,y) on a circle perimeter (based on a radiant value).

As an example, suppose that the circle have a diameter of 100 pixels *, I want to be able to have a x,y value anywhere in the circle perimeter.

The idea is to draw figures using Object2D, then set the DrawObject TheObject,x,y using that circle * perimeter value as the point of origin.

  • This is a virtual circle since it will never be drawn.

I took time yesterday afternoon, evening and some hours earlier today to think at that, but I do not had a single idea on how I can do that.

Can you help me ?

Basically, you use SIN and COS functions, like…

x = radius * cos (angle) y = radius * sin (angle)

to get a point relative to 0,0

You can Google circle cos sin or similar to get more detailed information.

How about this method?

Sub GetCircleXY(diameter As Double, angle As Double, ByRef x As Double, ByRef y As Double)
  Dim radius As Double
  radius = diameter / 2
  X = radius * cos(angle)
  y = radius * sin(angle)
End Sub

You can then use it like this:

  Dim x As Double
  Dim Y as Double
  GetCircleXY(DiameterInPixels, AngleInRadians, x, y)
  msgbox "X:" +Str(x) + ", Y:" + Str(y)

O, I see we replied at the same time.


Thank you for your answers, I will go back to that project this afternoon.

and if your angle is representing degrees you’ll need to scale the value to radians to work with sin/cos.

const deg2rad = 0.01745329251994 // scaling value = (PI radians) / (180 degrees)

//angleInDegrees, angleInRadians As double

angleInRadians = angleInDegrees * deg2rad

Thanks Will.

In fact, I started to use % to draw what I have to draw.

BTW: I have a (stupid ?) question: why the start angle is at 1.57 rad instead of 0 ?

To draw an ArcShape starting at 12:00 (top most x,y), I have to use -1.57 rad, not 0.

Also, the ArcShape example is… against intuitive:

Dim a As New ArcShape a.ArcAngle = 1.57 a.StartAngle = -1.57 a.FillColor = RGB(255, 0, 127) g.DrawObject(a, 100, 100)

If you look at it too fast, you do not realize what is StartAngle (since it comes second).

Also, to comply with the reality, it may be better to create an ArcShape that starts with a StartAngle of 0.

Remember that my years geometry are very far behind me.

Thats because with angles 0 is at 3 o’ clock and positive values move counter-clockwise. In this picture point A is at 0 angle and B is at some positive angle.

That’s the mathematical standard where coordinates are plotted with positive Y upwards. But the coordinates in Xojos Graphics class are Y downwards (top pixel is Y=0 and Y increases going towards the bottom). So that picture is flipped over the X axis. Basically, with an ArcShape at least, an angle of 0 will put the point at 3 o’ clock on the circle, and increasing values move clockwise.

For the example, a StartAngle of -1.57 means it starts 90 degrees counter-clockwise (because it’s negative) from 3 o’clock. Then an ArcAngle of 1.57 means it’ll trace out an arc of 90 degrees going clockwise. Do the values make sense now?

You could also use a StartAngle of 0 and ArcAngle of -1.57 to draw the same arc shape.


thank you for taking time to explain. I saved this Conversation page for later re-reading (and try to understand).

After talking with someone (here at a local McDonald’s), I realized that I will not be able to explain myself to someone the Pie Chart drawing process even if I can use it. I think that is why I ask questions / I feel insecure on the subject.

  1. I understand how I have to code to get the result I want, thanks for many hours of hard work.
    I mainly use: Wikipedia / Radian and a Xojo project to check the results.

  2. What I do not understand is why when I give a StartAngle value to 0 and a ArcAngle of 1.57 (half of ?) I get a pie chart that start at 3:00 and ends at 6:00 (in a clock metaphor).

  3. Why using different units (radian, degree) to draw circles and pie chart ?
    Pie Chart with an image that demonstrates (looking at the USA Part) why I feel sad to not understand why: ArcShape StartAngle = 0, ArcAngle = 1.6 ? (more or less; I mean 1.6 * ?) will not produce the same yellow area.

I have a mental blocking when I do not understand something. When I was young, I scrapped the whole thing. With time, I started to be able to use things even if I do not understand the whole process, but it is hard, very hard, the next time I have to go a similar way.