2

px and py are the x and y coordinates of a point on a circle's circumference.

Given:

the center of the circle as: cx, cy
the radius of the circle as: r
px

How to calculate the value of py? Thanks!

ohho
  • 49,193
  • 73
  • 246
  • 377

2 Answers2

3

Given px there are at most two possible values for py.

Look at the pythagorean theorem: (px-cx)^2+(py-cy)^2=r^2.

Let d=r^2-(px-cx)^2

If d>0 then you have two solutions. This gives py=sqrt(d)+cy, where the square root is positive or negative.

If d=0 then you have one solution py=cy, the left or right of the circle, depending on px

If d<0 you have no real points.

caf
  • 225,337
  • 36
  • 308
  • 455
John Smith
  • 11,997
  • 16
  • 62
  • 109
  • 2
    Actually, for a given `px`, there are either one, two, or zero solutions. Two if `r^2 - (px - cx)^2 > 0`, one if `r^2 - (px - cx)^2 == 0` (or `r == abs(px - cx)`), and zero otherwise (in which case the square root is imaginary). – Mike DeSimone Jan 05 '11 at 04:24
  • @Mike you're right. Didn't consider non-complex numbers (my money is imaginary anyway :-) – John Smith Jan 05 '11 at 04:30
0

Although this is not programming... you know this equation right?

(x - h)^2 + (y - k)^2 = r^2

You have h and k from cx and cy

You have r

you have x from px

then is easy to solve it!

nacho4d
  • 41,605
  • 42
  • 154
  • 237