Code Monkey home page Code Monkey logo

morton.jl's Introduction

Morton

Build Status codecov.io

This package provides functions to convert between Morton number (a.k.a. Z-order), Cartesian coordinates, and quadtree and octree coordinates.

Say for example you have a 4x4 matrix. The sixteen cells could be addressed in each of the following three ways.

Morton order:

1 2 5 6
3 4 7 8
9 10 13 14
11 12 15 16

Cartesian coordinates:

1,1 2,1 3,1 4,1
1,2 2,2 3,2 4,2
1,3 2,3 3,3 4,3
1,4 2,4 3,4 4,4

Quadtree coordinates:

1,1 1,2 2,1 2,2
1,3 1,4 2,3 2,4
3,1 3,2 4,1 4,2
3,3 3,4 4,3 4,4

To convert from Morton to Cartesian, use the morton2cartesian function:

julia> Pkg.add("Morton")
julia> using Morton

julia> morton2cartesian(13)
2-element Array{Int64,1}:
3
3

Similarly, one can convert from Morton to quadtree, or Cartesian to quadtree:

julia> morton2tree(13)
2-element Array{Int64,1}:
4
1

julia> cartesian2tree([3,3])
2-element Array{Int64,1}:
4
1

Of course each of the functions can be reversed:

julia> cartesian2morton([3,3])
13

julia> tree2morton([4,1])
13

julia> tree2cartesian([4,1])
2-element Array{Int64,1}:
3
3

Corresponding functions also exist for three dimensional matrices (i.e. octrees). Simply replace the 2 with a 3: morton3cartesian, morton3tree, etc.

There are also un-exported N-dimensional functions to convert between tree and Morton, and tree and Cartesian (e.g. Morton._treeNmorton). Please let me know if you have a clever way to convert directly between Morton and Cartesian in arbitrary dimensions!

Related packages

RegionTrees

Author

Ben Arthur, [email protected]
Scientific Computing
Janelia Research Campus
Howard Hughes Medical Institute

morton.jl's People

Contributors

bjarthur avatar juliatagbot avatar cshenton avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.