31

Using C#:

How do I get the (x, y) coordinates on the edge of a circle for any given degree, if I have the center coordinates and the radius?

There is probably SIN, TAN, COSIN and other grade ten math involved... :)

Daniel Vassallo
  • 337,827
  • 72
  • 505
  • 443
Ian Vink
  • 66,960
  • 104
  • 341
  • 555
  • That's the kind of question to ask on http://mathoverflow.net/ – Lucero Jan 19 '10 at 12:42
  • 8
    @Lucero: No, I doubt this one would count as a "research level math question" – Niki Jan 19 '10 at 12:44
  • @nikie, true, but on the other hand it's even less a programming question. It's simple geometry. – Lucero Jan 19 '10 at 14:34
  • -1, not programming related. Voted to close. – user7116 Jan 19 '10 at 18:48
  • 3
    Either way, he would be absolutely flamed to death on Math Overflow if he posted that. They're much more strict about keeping it "by mathematicians, for mathematicians" than we are over here. – Adrian Petrescu Jan 19 '10 at 18:49
  • 1
    Possible duplicate of [Calculating point on a circle's circumference from angle in C#?](http://stackoverflow.com/questions/674225/calculating-point-on-a-circles-circumference-from-angle-in-c) – Peter O. Nov 21 '16 at 07:12
  • 4
    I'm voting to close this question as off-topic because it is a geometry question, not a programming question. – tripleee Aug 17 '18 at 09:56
  • http://en.wikipedia.org/wiki/Trigonometry is your friend, the calculations are quite simple. Check the Math Namespace for Sin() & Cos() –  Jan 19 '10 at 12:30
  • All of these comments are why the StackOverflow websites have a reputation as being unfriendly and hostile to newcomers. Not every programming beginner is good at maths (or even educated in maths!) – Lou Jun 17 '23 at 18:25

3 Answers3

87

Here's the mathematical solution which can be applied in any language:

x = x0 + r * cos(theta)
y = y0 + r * sin(theta)

x0 and y0 are the coordinates of the centre, r is the radius, and theta is in radians. The angle is measured anticlockwise from the x-axis.

This is the code for C# specifically if your angle is in degrees:

double x = x0 + r * Math.Cos(theta * Math.PI / 180);
double y = y0 + r * Math.Sin(theta * Math.PI / 180);
Alan W. Smith
  • 24,647
  • 4
  • 70
  • 96
David M
  • 71,481
  • 13
  • 158
  • 186
9

using Pythagoras Theorem (where x1,y1 is the edge point):

x1 = x + rcos(theta)
y1 = y + r
sin(theta)

in C#, this would look like:

x1 = x + radius * Math.Cos(angle * (Math.PI / 180));
y1 = y + radius * Math.Sin(angle * (Math.PI / 180));

where all variables are doubles and angle is in degrees

Alastair Pitts
  • 19,423
  • 9
  • 68
  • 97
4

For a circle with origin (j, k), radius r, and angle t in radians:

   x(t) = r * cos(t) + j       
   y(t) = r * sin(t) + k
Daniel Vassallo
  • 337,827
  • 72
  • 505
  • 443