0

I'm looking to have a reverse lookup of a 2D table i.e. Table: F(x,y), given F, find x and y

My current method uses a nested for loop to search the table for all x's and y's to find F within some error. The complication here is that the queried "F" may not be a perfect match for the "F" in my lookup table. I also have NaNs in my table. I'm hoping to have this program find the nearest "F" to the queried "F".

The table is currently a 2D array, but I'm thinking a map may be more appropriate here. I know how to create a multidimensional map from this: https://www.geeksforgeeks.org/implementing-multidimensional-map-in-c/

I also found some great answers (@Rob's specifically) on how to have a reverse map lookup for a 1D map using Boost here: Reverse map lookup

I'm having some trouble combining the two methods, as well as having a findNearest feature.

ashune
  • 11
  • You'll want a 2d space partitioning data structure, like a quad tree, probably. – Yakk - Adam Nevraumont May 16 '21 at 20:44
  • Does the table change? If not, just create a vector of all (F, x, y) triples and sort them. findNearest() then amounts to performing a binary search in this vector, and picking whichever element on either side is closer to the target. – j_random_hacker May 17 '21 at 00:50
  • can you share your LUT ? so we can actually see what you have ... ideally also with a 3D plot preview ... also check this out [Reverse complex 2D lookup table](https://stackoverflow.com/a/29227551/2521214) – Spektre May 17 '21 at 06:54

1 Answers1

0

Sounds like you would like to use the indexing suite of Boost Geometry.

Not only does it have nearest-k queries, but it affords you all kinds of coordinate systems (including geodesic systems).

See Spatial Indexes

sehe
  • 374,641
  • 47
  • 450
  • 633