Search code examples
geometrypythagorean

How to know if a point is locate at outer circle?


Having a circle with the centre (xc,yc) with the radius r how to know whether a point (xp,yp) is locate at the outer circle which following in the picture below.

enter image description here


Solution

  • If inner circle has radius r and outer circle has radius R, then you can check whether point lies in the ring using comparison of squared distances:

     dd = (xp - xc)^2 + (yp - yc)^2
     if (dd <= R^2) and (dd >= r^2) then 
        point is in the ring