4

I'm looking for efficient data structures for storing 3d points (x,y,z). The effect of storing in at the points in a data structure should generate a more memory efficient structure and a faster search for a specific set of coordinates. The 3d points is mapping to a specific ID so it should be able to keep track of each set of coordinates I'm looking for any implementation which is available.

x, y, z gives the cartesian coordinates of each node.

id x y z

1 14.566132 34.873772 7.857000

2 16.022520 33.760513 7.047000

3 17.542000 32.604973 6.885001

4 19.163984 32.022469 5.913000

5 20.448090 30.822802 4.860000

6 21.897903 28.881084 3.402000

7 18.461960 30.289471 8.586000

8 19.420759 28.730757 9.558000

The number of coordinates will be huge maybe around 1 000 000.

Thanks in advance!

Yoko
  • 59
  • 1
  • 3
  • What options have you considered so far? – Oliver Charlesworth Mar 05 '16 at 20:27
  • Have considered octree https://en.wikipedia.org/wiki/Octree and https://en.wikipedia.org/wiki/R-tree but docent find any good implementation for storing 3d coordinates – Yoko Mar 05 '16 at 21:51
  • 2
    You should specify what is important to you. Code readability (simple array of structure), auto-vectorization (structure of arrays), or maybe good insertion/search times (octree?). For example in N-body computations an octree is the best approach for being O(nlog n). – Hopobcn Mar 05 '16 at 23:47
  • 1
    1 million float triples is far from huge. – o9000 Mar 06 '16 at 00:28
  • 1
    It's unlikely that a more memory-efficient structure than a sequential list will give faster search times. Typically, there's a tradeoff. If you want faster search then you probably need to use more memory. If you want to use less memory, then you'll have to suffer slower search times. – Jim Mischel Mar 07 '16 at 17:44

3 Answers3

2

a more memory efficient structure

More memory efficient than what? A list? You'd need compression for that.

a faster search for a specific set of coordinates

If you want to find the k closest points from a set of coordinates, a ball tree is a good option.

If you want to search a volume, a quad tree (or octree) works better.

o9000
  • 1,626
  • 13
  • 15
  • Yeah more memory efficient than storing everything in a list struct coordinate { double x; double y; double z; }; int main(){ std::vector list; coordinate a = coordinates(2.123123,2.1231,3.112); list .push_pack(a); } – Yoko Mar 06 '16 at 10:35
2

I'm hearing that the coords you're looking up will be exact matches for those in the structure already. Depending perhaps on your spatial distribution, you could create a hash function that takes the coord and attempts to produce something fairly unique, then just use a standard hash map. Most modern languages provide some kind of hash map implementation, so all you'd need to do is provide those appropriate hash values for your coords.

If you need to look up coords near the test coord, then a balltree or octree or something, but it doesn't sound like that's what you need.

Aiken Drum
  • 573
  • 1
  • 3
  • 24
  • With hashing they need to be equal bit by bit. If the lookup values are the result of floating point operations, that might not be true due to loss of precision. If that is the case, the hash function would have to take into account the maximum error and discard the least significant bits before actually hashing. But I think the OP is a bit confused about what he needs. – o9000 Mar 06 '16 at 12:05
  • I know, that's why I qualified my answer as being for exact matches only. In the case of wanting matches within a certain epsilon, dropping bits off of the bottom would only unify some of the neighbors (about an eighth in the case of 3D coords). It's harder to visualize with a float, but consider the bitwise difference between close-as-can-be integer neighbors 255 and 256. I wouldn't recommend that. An epsilon-based search needs a different data structure. – Aiken Drum Mar 06 '16 at 20:45
0

You can use a struct:

struct coordinate
{
   double x;
   double y;
   double z;
} points[1000000];
johnnyRose
  • 7,310
  • 17
  • 40
  • 61
Rajeev Singh
  • 3,292
  • 2
  • 19
  • 30
  • One small refinement: given that he apparently only has 7 significant digits, he might want to use `float` instead of `double`. It's not an uncommon choice for 3D applications... – H. Guijt Mar 05 '16 at 20:38
  • its up-to you how much precise value you want to store! – Rajeev Singh Mar 05 '16 at 20:41
  • That's only a structure I'm looking for a data structure for storing 3d coordinates. In this structure I will have to brute force a search for specific set of coordinates and that's not what I'm looking for. – Yoko Mar 05 '16 at 21:52