Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Having a circle with the centre $(x_c, y_c)$ with the radius $r$ how to know whether a point $(x_p, y_p)$ is inside the circle?

share|cite|improve this question
Do you know the formula for the distance between two points, given their coordinates? – Brian M. Scott Sep 18 '12 at 22:32
Well, it would definitely help. – Ivan Sep 18 '12 at 22:34
Inside the radius? You mean inside the circle? – Pedro Tamaroff Sep 18 '12 at 22:35
Exactly, @PeterTamaroff. – Ivan Sep 18 '12 at 22:38
up vote 17 down vote accepted

The distance between $\langle x_c,y_c\rangle$ and $\langle x_p,y_p\rangle$ is given by the Pythagorean theorem as $$d=\sqrt{(x_p-x_c)^2+(y_p-y_c)^2}\;.$$ The point $\langle x_p,y_p\rangle$ is inside the circle if $d<r$, on the circle if $d=r$, and outside the circle if $d>r$. You can save yourself a little work by comparing $d^2$ with $r^2$ instead: the point is inside the circle if $d^2<r^2$, on the circle if $d^2=r^2$, and outside the circle if $d^2>r^2$. Thus, you want to compare the number $(x_p-x_c)^2+(y_p-y_c)^2$ with $r^2$.

share|cite|improve this answer

The point is inside the circle if the distance from it to the center is at most $r$. Symbolically, this is $$\sqrt{|x_p-x_c|^2+|y_p-y_c|^2}< r.$$

share|cite|improve this answer
I would not say that it’s inside the circle when the distance is $r$. – Brian M. Scott Sep 18 '12 at 22:51
It depends on whether you include the boundary. If you don't, replace $\leq$ with $<$. – Alex Becker Sep 18 '12 at 22:54
I’d say that you’re confusing the (closed) disk with the circle. A point at distance $r$ for the centre is inside the disk but not inside the circle; rather, it’s on the circle. (It’s a fairly minor point, but there are enough occasions for terminological confusion that I like to avoid it when it’s easy to do so.) – Brian M. Scott Sep 18 '12 at 22:57
@BrianM.Scott That's a fair point. – Alex Becker Sep 18 '12 at 22:59

Alex and Brian have answered your question already. In case you're trying to implement this algorithm in some programming language, here's my Haskell implementation:

distance :: Floating a => (a, a) -> (a, a) -> a
distance (x1,y1) (x2,y2) = sqrt((x1-x2)**2 + (y1-y2)**2)

isInsideCircle :: (Ord a, Floating a) => a -> (a, a) -> (a, a) -> Bool
isInsideCircle r (xc,yc) (x,y) | (distance (xc,yc) (x,y) < r) = True
                               | (distance (xc,yc) (x,y) >= r) = False

Suppose you have a circle whose radius is $r = 1$ and whose center is the origin $(0,0)$. You would like to know if $(\frac{1}{2},0)$, $(1,0)$, and $(1,1)$ are inside the circle. The following interactive GHCi session answers the question:

*Main> isInsideCircle 1 (0,0) (0.5,0)
*Main> isInsideCircle 1 (0,0) (1,0)
*Main> isInsideCircle 1 (0,0) (1,1)
share|cite|improve this answer

If you have the equation of the circle, simply plug in the x and y from your point (x,y). After working out the problem, check to see whether your added values are greater than, less than, or equal to the r^2 value. If it is greater, then the point lies outside of the circle. If it is less than, the point is inside the circle. If it is equal, the point is on the circle.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.