Originally Posted by
Adak
Actually, I was wondering if "tester" was BOTH a function, AND sometimes referred to the program "testing" in the simulation. It is confusing.
This is just the Pythagorean theorem:
RETURN 1 if sqrt(x*x + y*y) <= r, ELSE 0
Where x = A, y = B, and r = C˛ in A˛ + B˛ = C˛
So to tell if it's inside the circle, get the x and y point of the hit, and the x and y values of the center of the circle. Then:
We get a triangle from the hit, to the center of the circle:
X -x == base distance of the triangle
Y - y == height distance of the triangle
Now base˛ + height˛ == hypotenuse˛ (distance as the crow flies), from the hit, to the center of the circle.
If hypotenuse is greater than the radius of the circle, then it's outside the circle. If it's less than or equal to, it's inside the circle.
For instance, if the triangle had base of 3, and height of 4, then the hypotenuse would be 5, since:
3˛ + 4˛ = 5˛
So if the radius of the circle was > 5, the hit would be outside the circle. If it's less than or equal to 5, then it's inside it.