Closest distance between two points(disjoint set)
In the Bichromatic Closest Pair Problem, we are given a set R of red points and a set B of blue points in the plane. The problem is to return the pair of points, one red and one blue, whose distance is minimum over all red-blue pairs.
My algorithm is a kind of them.
1: If both R and B store only a constant number of points, sort the points according to <y , com- pute a bichromatic closest pair using a brute- force algorithm, and return.
2: Assume |R| >= |B|, otherwise reverse the roles of R and B.
3: Pick a random element r from R.
4: Find the closest element of b in B to r.
5: Compute the left envelope of disks having radius |rb| centered at each of the points in B.
6: Remove all elements of R that are outside the envelope.
I can’t think any idea which implementing to 4,5,6.
some reference said Graham’s algorithm. I think it cannot be a circle. and I want to know how I implement them.
and How to make envelope some kind of region? T T..
It is easy draw in a paper, but implementing is always hard to me. someone who advise in C++?
We’re still using an L1 metric, right? Let’s assume that the red points have x <= 0 and the blue points have x >= 0.
Every red-blue pair has a shortest path with at most three segments: one horizontal from the red point to the y-axis, one vertical on the y-axis, one horizontal from the y-axis to the blue point. It suffices to compute the intersection of the y-axis and the Voronoi diagram for the red points and then locate the projection of each blue point on the y-axis in the diagram (e.g., with binary search :P; it may be faster, however, to sort the blue points by y-coordinate and merge).
Let’s say that a red point R = (x, y) dominates another red point R’ = (x’, y’) iff x’ <= x (R is at least as close to the y-axis as R’) and |y – y’| <= x – x’.
Lemma 1 If R dominates R’, then every point on the y-axis is at least as close to R as R’.
Proof: let P = (x, y’). Essentially by hypothesis, d(R, P) <= d(R’, P). For every point Q on the y-axis, d(R’, Q) = d(R’, P) + d(P, Q) >= d(R, P) + d(P, Q) >= d(R, Q).
Lemma 2 Let R1 = (x1, y1), R2 = (x2, y2), R3 = (x3, y3). Assume that y1 <= y2 <= y3. If R3 dominates R1, then R2 dominates R1 or R3 dominates R2. Symmetrically, if R1 dominates R3, then R1 dominates R2 or R2 dominates R3.
Proof: we have x1 <= x3. There are three cases.
Case 1: x2 < x1. In this case, x2 <= x3 and |y3 – y2| <= |y3 – y1| <= x3 – x1 <= x3 – x2, so R3 dominates R2.
Case 2: x1 <= x2 <= x3. In this case, |y2 – y1| + |y3 – y2| = |y3 – y1| <= x3 – x1 = (x2 – x1) + (x3 – x2), so |y2 – y1| <= x2 – x1 and R2 dominates R1 or |y3 – y2| <= x3 – x2 and R3 dominates R2.
Case 3: x3 < x2. In this case, x1 <= x2 and |y2 – y1| <= |y3 – y1| <= x3 – x1 <= x2 – x1, so R2 dominates R1.
Lemma 3 Suppose that R dominates R’ and R’ dominates R. Then R = R’.
Lemma 4 Suppose that R = (x, y) is dominated by no other red point. Then (0, y) is closer to R than every other red point.
Together, the lemmas imply that by repeatedly eliminating all R’ with some neighbor R (in sorted order by y-coordinate) that dominates R’, we obtain the Voronoi cells in order.