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

后端 未结 5 1418
别那么骄傲
别那么骄傲 2021-02-06 12:32

We have a point (x,y) and a set of some other points (xi,yi). How can we determine which of (xi,yi) are within a circle with c

相关标签:
5条回答
  • 2021-02-06 13:14

    Simple way.

    Compute the distance from the point to the center of the circle. If less than radius , then its within the circle.

    0 讨论(0)
  • 2021-02-06 13:17

    I had the same problem to solve inside a plsql procedure. The solution above are completely right and I did the same. But it compromised the performance of my plsql program drastically. Instead of that circle calculation, I used a square. Because it can be done without doing such calculation and in the sql statement itself. It improved the query performance by more than 10x

    0 讨论(0)
  • 2021-02-06 13:27
    (xi-x)**2 + (yi-y)**2 < r**2
    
    0 讨论(0)
  • 2021-02-06 13:27

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

    0 讨论(0)
  • 2021-02-06 13:33

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

    0 讨论(0)
提交回复
热议问题