4 ms·
I'd love to see that. Could you link me to an implementation or explain this in more detail please?
by quibono 10mo ago
I'd love to see that. Could you link me to an implementation or explain this in more detail please?
- johnisgood 10mo agoI would like to know about this more, too. Is there a code anywhere, ideally with comments? But I am fine without comments, too, I would just like to see the code and possibly with an example usage.
- quibono 10mo agoOkay, I was intrigued and I did some digging. Morton / Z-order is all about interleaving the individual bits of the x and y coordinates. You end up grouping by quadrants. Python one liner: points.sort(key=lambda p: sum(((p[0]>>i&1)<<(2*i))|((p[1]>>i&1)<<(2*i+1)) for i in range(16)))
- _jackdk_ 10mo agoHere's a 3D version used in the creation of sparse voxel octrees: https://forceflow.be/2013/10/07/morton-encodingdecoding-through-bit-interleaving-implementations/ https://forceflow.be/2013/10/07/morton-encodingdecoding-thro... Here's an example from AWS, where lat/long pairs are put into a Z-index, which is used as a DynamoDB sort key, letting you efficiently query for items near a point. https://aws.amazon.com/blogs/database/z-order-indexing-for-multifaceted-queries-in-amazon-dynamodb-part-1/ https://aws.amazon.com/blogs/database/z-order-indexing-for-m...