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
  • 50,879
  • 75
  • 256
  • 383

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
  • 233,326
  • 40
  • 323
  • 462
John Smith
  • 12,491
  • 18
  • 65
  • 111
  • 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
  • 43,720
  • 45
  • 157
  • 240