开发者

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

开发者 https://www.devze.com 2022-12-09 17:44 出处:网络
We have a point (x,y) and a set of some other points (xi,yi). How can we de开发者_如何转开发termine which of (xi,yi) are within a circle with center (x,y) and radius r (a given number)?(xi-x)**2 + (yi

We have a point (x,y) and a set of some other points (xi,yi). How can we de开发者_如何转开发termine which of (xi,yi) are within a circle with center (x,y) and radius r (a given number)?


(xi-x)**2 + (yi-y)**2 < r**2


Simple way.

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


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.


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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号