Find if points are inside a circle with a given center and radius

We have a point (x, y) and many other points (xi, yi) . How to determine which of (xi, yi) are inside a circle with center (x, y) and radius r (given number)?

+4
source share
5 answers
(xi-x)**2 + (yi-y)**2 < r**2 
+14
source

The easy way.

Calculate the distance from the point to the center of the circle. If there is less radius, then it is inside the circle.

+5
source

If (xi - x) ^ 2 + (yi - y) ^ 2 is less than d ^ 2, then inside. If it is equal to d ^ 2, then it is on the circle. If it is greater than d ^ 2, it is outside.

+3
source

If sqrt ((xi-x) ^ 2 + (yi-y) ^ 2) <= d

+2
source

I had the same problem to solve inside the plsql procedure. The solution above is completely correct, and I did the same. But it dramatically worsened the performance of my plsql program. Instead of calculating the circle, I used a square. Because it can be done without performing such a calculation in the sql expression itself. This improved query performance by over 10x

0
source

All Articles