Math grids unique values

47 Views Asked by At

I suspect this may have to do with color space math, but I'm looking for a way to assign unique values to a grid.

Basically it's for (what I suspect) a more computationally efficient "select the closest person to location (Lat, Lng)". Currently the way I do it is calculating all 50,000 people's distance to a target location using haversine before selecting a best candidate. It doesn't typically take long, but I'd like to select the closest person on each loop of code so this would get rather 'clunky' really quickly.

Lets say I have 5 people. For simplicity sake lets limit the globe to max X and Y values of 5 (so 1 = 36 degrees lat, and 72 degrees lng if you really want):
1. 1, 4
2. 2, 3
3. 1, 1
4. 4, 1
5. 2, 4

Now, I dont have a target location yet, but when you plot these on a grid, you can immediately see that person 1 and 5 are pretty close together, and person 2 is an immediate diagonal to person 1. Now my problem is I need a unique way of "scoring them". When I drop a target (T) onto the grid, lets say (1, 4) we immediately see worker 1 is the best candidate, worker 5 is the next best (being 1 over) and worker 2 is the third best being √3 away on the grid.

But if I multiply X and Y together I get a value of 4 for the target, which is fine, but now person 1 and person 4 are the best candidates, and if person 1 is busy, it'll try to assign person 4!

If I try sums, then people 1, 2 AND 4 come up as the best options.

I'm looking for a way to give the target location a "score" so I can immediately say worker 1, then worker 5 then worker 2 are the best candidates, but for any arbitrary location on the grid. When expanding the grid to 360X and 180Y, using sums and differences between X and Y produces equal values along the diagonals. Using multiplication has a similar issue but even worse, and using one axis as an exponent on the other axis could easily mean that 2^8 (X2, Y8) could pick a worker at X4, Y2!

Then I thought "the color wheel on artistic programs has unique values all over a 2D circle, all unique, and the colors immediately next to any color I choose are very similar, but still unique. There must be a way to do that but for mathematics"!

Sorry if this is a hard concept to grasp, it's very difficult for me to try to explain it simply.

1

There are 1 best solutions below

1
On

You are looking to create a Voroni diagram. Given your people you can divide the earth's surface into regions closest to each person. Then when you get the target location you can just look which region it is in. The image is from the Wikipedia entry. To create it you just draw the lines bisecting the segements between each pair of people. You create convex regions around each person. enter image description here