Given a list of 2*N points in a plane, I am trying to find a method which will divide them into N pairs such that each pair has a similar edge length to all other pairs.
Essentially I am trying to form pairs of points which are roughly equidistant.
CodePudding user response:
I can propose only naive solution. Not pretty sure about its time complexity, but it's polynomial, and for sure not worse than O(n^5) :)
Let's make some definitions:
p1andp2— our points. Structure of point contains its index, so for each pair of point we can know is it the same point or else.p1.i— index ofp1.D(p1, p2)— distance betweenp1andp2. In implementation it would be convenient to store squares of distances, in order to useinttype. SoD(p1, p2)=(p1.x - p2.x)^2 (p1.y - p2.y)^2.SameDistanceMapis a map from distance to array of point's pairs, such as:
For each (p1, p2) in SameDistanceMap[dst], D(p1, p2) = dst.
You can do it this way:
- Let's construct
SameDistanceMap. It can be easily done with double nested loop. - Now we know, that if answer exists, then it's a subarray of one of
SameDistanceMapvalue-arrays. - Let's iterate
SameDistanceMapvalue-arrays, and see if any one of them is a real answer. We can consider only arrays of length not less thenn. - Let's consider each of these arrays. The rest of the task could be reformulated to

