Questions tagged [z-order-curve]

Use this tag for questions about Morton order and related questions about Z-order curves. Not to be confused with the z-order tag, which is for questions about Z-order rendering, or the morton-number tag, which relates to the Morton Number used in fluid dynamics, or the z-curve tag, which relates to finance.

This tag is for questions about Morton order and related questions about Z order curves.

Not to be confused with , which is for questions about Z-order rendering, or , which relates to the Morton Number used in fluid dynamics, or , which relates to finance.

Note: we should add as a synonym.

33 questions
41
votes
9 answers

How to compute a 3D Morton number (interleave the bits of 3 ints)

I'm looking for a fast way to compute a 3D Morton number. This site has a magic-number based trick for doing it for 2D Morton numbers, but it doesn't seem obvious how to extend it to 3D. So basically I have 3 10-bit numbers that I want to interleave…
damndirtyape
  • 473
  • 1
  • 5
  • 5
25
votes
3 answers

How to de-interleave bits (UnMortonizing?)

What is the most efficient way to de-interleave bits from a 32 bit int? For this particular case, I'm only concerned about the odd bits, although I'm sure it's simple to generalize any solution to both sets. For example, I want to convert…
AShelly
  • 34,686
  • 15
  • 91
  • 152
23
votes
6 answers

How to efficiently de-interleave bits (inverse Morton)

This question: How to de-interleave bits (UnMortonizing?) has a good answer for extracting one of the two halves of a Morton number (just the odd bits), but I need a solution which extracts both parts (the odd bits and the even bits) in as few…
Paul R
  • 208,748
  • 37
  • 389
  • 560
21
votes
7 answers

How can I shuffle bits efficiently?

I need to shuffle a 16 bit unsigned integer in a way that the even indexes land in the lower byte, and the odd indexes land in the upper byte. input: fedcba98 76543210 (contiguously numbered) output: fdb97531 eca86420 (even and odd separated) My…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
10
votes
3 answers

2D morton code encode/decode 64bits

How to encode/decode morton codes(z-order) given [x, y] as 32bit unsigned integers producing 64bit morton code, and vice verse ? I do have xy2d and d2xy but only for coordinates that are 16bits wide producing 32bit morton number. Searched a lot in…
Dawid Szymański
  • 775
  • 6
  • 15
10
votes
2 answers

How to use Morton Order(z order curve) in range search?

How to use Morton Order in range search? From the wiki, In the paragraph "Use with one-dimensional data structures for range searching", it says "the range being queried (x = 2, ..., 3, y = 2, ..., 6) is indicated by the dotted rectangle. Its…
gfan
  • 1,027
  • 1
  • 14
  • 28
8
votes
3 answers

How to use Morton Order in range search?

If I have a dataset, where the keys are points in 3D, represented by 3 signed 64 bit integers. And I want to use a (sorted)key-value store to store them, where keys are just byte array (but I can specify a comparator). I think I can turn all those…
Sebastien Diot
  • 7,183
  • 6
  • 43
  • 85
7
votes
2 answers

Benefits of nearest neighbor search with Morton-order?

While working on the simulation of particle interactions, I stumbled across grid indexing in Morton-order (Z-order)(Wikipedia link) which is regarded to provide an efficient nearest neighbor cell search. The main reason that I've read is the almost…
bbtrb
  • 4,065
  • 2
  • 25
  • 30
6
votes
1 answer

Is Morton code the most efficient for higher dimensions?

For my current input data, which is points in 3D, I'm using Morton code to improve the cache coherence when accessing the point list. I have some other data that is 6D and 7D. Is Morton code still a good technique for such dimensions? Or are there…
6
votes
1 answer

Produce interleaving bit patterns (morton keys) for 32 bit , 64 bit and 128bit

I want to produce a morton key for 32bit and 64bit and 128bit, with optimal code! What’s the solution?
Gabriel
  • 8,990
  • 6
  • 57
  • 101
5
votes
1 answer

2d Morton code 64bits decode function

The first function encodes [x, y] as 64bit wide Morton code where x and y are 32bit wide integers using Interleave bits by Binary Magic Numbers. What would be the reverse function ? void xy2d_morton_64bits(uint64_t x, uint64_t y, uint64_t *d) { …
Dawid Szymański
  • 775
  • 6
  • 15
5
votes
1 answer

Morton index from 2D point with floats

I have a 2D point that looks something like this: class Point { float m_x, m_y; public: int mortonIndex() { // what would go here? } }; I know what to do with integers, but I need to use floats. I also want to avoid…
wavycat
  • 61
  • 6
4
votes
1 answer

Find nearest neighbor with morton code

I have implemented a decode/encode method for transforming 2d points into their respective morton code. What am i looking for is to find the nearest neighbor (under a min_distance) So for example something like…
greedsin
  • 1,252
  • 1
  • 24
  • 49
3
votes
0 answers

Kd Tree vs. Sorted Morton Codes

I'm currently programming an opengl 2d particle system, but I've run into more of a general programing problem that I need help with. Basically, I need a way to find if particles may be colliding, I.e. broad phase collision detection. I've done a…
Barbacamanitu
  • 61
  • 1
  • 4
3
votes
1 answer

2D Morton decode function 64bits

The first function encodes [x, y] as 64bit wide Morton code where x and y are 32bit wide integers using Interleave bits by Binary Magic Numbers. What would be the reverse function? void xy2d_morton_64bits(uint64_t x, uint64_t y, uint64_t *d) { x…
Dawid Szymański
  • 775
  • 6
  • 15
1
2 3