Take the 2-minute tour ×
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.

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

Given:

  • $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|improve this question

2 Answers 2

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|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|improve this answer

Your Answer

 
discard

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.