简体   繁体   中英

ℝ³ -> ℕ mapping for a finite number of values

I am looking for an algorithm that is capable of mapping a finite but large number of 3 dimensional positions (about 10^11) to indices (so a mapping ℝ³ -> ℕ)

I know that it's possible and fairly simple to make an ℕ -> ℝ³ mapping, and that's essentially what i want to do, but ℕ -> ℝ³ would be an impractical way of figuring out which indices of ℕ are near a certain position,

Ideally i would also like to ensure that my finite subset of ℕ contains no duplicates.

Some background on how this would be implemented to give a better idea on the constraints and problems with some naive solutions to this problem:

I'm trying to think of a way to map stars in a galaxy to a unique ID that i can then use as a "seed" for a random number generator, an ℕ -> ℝ³ mapping would require me to iterate over all of ℕ to find the values of ℝ³ that are near a given location, which is obviously not a practical approach

I've already found some information about the cantor pairing function and dovetailing, but those cause problems because those mainly apply to ℕⁿ and not ℝⁿ.

It's not guaranteed that my ℝ³ values follow a grid, if they did i could map ℝ³-> ℕ³ by figuring out which "box" the value is in in, and then use cantor's pairing function to figure out which ℕ belongs to that box, but in my situations the box might contain multiple values, or none.

Thanks in advance for any help

You could use a kd tree to spatially partition your set of points. To map onto a natural number, treat the path through the tree to each point as string of binary digits where 0 is the left branch and 1 is the right branch. This might not get you exactly what you're looking for, since some points which are spatially close to each other, may lie on different branches, and are therefore numerically distant from each other. However if two points are close to each other numerically, they will be close to each other spatially.

Alternatively, you could also use an octree , in which case you get three bits at a time for each level you descend into the tree. You can completely partition the space so each region contains at most one point of interest.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM