Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

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

I am coding a video game, but I am not so good at the math. I am hoping for some help here:


  • $X, Y$ that is the center of the Circle
  • $R$ that is the radius of the Circle
  • $X_1, Y_1$ that may or may not be in the circle.

The idea is that I have a tower that will shoot at a bad guy when it comes in range. The bad guy has an $X_1, Y_1$ coordinate that will continually update.

I need an equation I can run to see if the bad guy is in range.

share|cite|improve this question
up vote 11 down vote accepted

$(X-X_1)^2+(Y-Y_1)^2\leq R^2$ is true if and only if the bad guy is in range, since the distance between $(X,Y)$ and $(X_1,Y_1)$ is $\sqrt{(X-X_1)^2+(Y-Y_1)^2}$.

share|cite|improve this answer

The circle is defined by all points $(x_1, y_1)$ satisfying $(x_1-x)^{2} + (y_1-y)^{2} \le R^{2}$. That is your logical condition to test if someone is in 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.