snippetMinor
How to check if a list of XY coordinate meet the safety distance to each others?
Viewed 0 times
theeachothersdistancecoordinatemeetsafetyhowlistcheck
Problem
My background is not CS so sorry for using improper term. But basically I want to check if a point on XY plane is "too close" to any other points, and do so with every points. In another words, if I draw a circle with radius R at every points, would any circle cross other circles on the plane.
I want to code this in Python, if that matters.
I want to code this in Python, if that matters.
Solution
The problem you are solving has many well-known efficient algorithms.
The problem is to find closest pair of points in the plane.
If the closest pair have distance less than the safety distance, you already have a pair.
If not, no other pair can have a less distance, and hence all pairs are safe.
One efficient way to solve this problem is using divide and conquer. The algorithm is practical and easy to implement. It has run-time $O(n \log n)$ (check the notes at the end).
It might be an over-kill, but as efficient from the theoretical point of view, to build Delaunay-Triangulation over the set of points and compare each point to its neighbors in the triangulation, which is also achievable in $O(n \log n)$.
There are many libraries that offer a ready-to-use Delaunay-Triangulation (you can check CGAL-Boost library for C++), which makes it an easier way to implement that the previous method.
ps. Another very well-known approach, used in many different problems is line-sweep. There is also a line-sweep $O(n \log n)$ algorithm for Closest pair of points problem. (please check the link).
The problem is to find closest pair of points in the plane.
If the closest pair have distance less than the safety distance, you already have a pair.
If not, no other pair can have a less distance, and hence all pairs are safe.
One efficient way to solve this problem is using divide and conquer. The algorithm is practical and easy to implement. It has run-time $O(n \log n)$ (check the notes at the end).
It might be an over-kill, but as efficient from the theoretical point of view, to build Delaunay-Triangulation over the set of points and compare each point to its neighbors in the triangulation, which is also achievable in $O(n \log n)$.
There are many libraries that offer a ready-to-use Delaunay-Triangulation (you can check CGAL-Boost library for C++), which makes it an easier way to implement that the previous method.
ps. Another very well-known approach, used in many different problems is line-sweep. There is also a line-sweep $O(n \log n)$ algorithm for Closest pair of points problem. (please check the link).
Context
StackExchange Computer Science Q#108928, answer score: 3
Revisions (0)
No revisions yet.