Function Repository Resource:

# MortonCurve

Generate a Morton (z-order) curve

Contributed by: Jan Mangaldan
 ResourceFunction["MortonCurve"][n] gives the line segments representing the nth-step Morton (z-order) curve. ResourceFunction["MortonCurve"][n,d] gives the nth-step Morton curve in d dimensions.

## Details and Options

ResourceFunction["MortonCurve"] is also known as the Morton space-filling curve, z-order curve or the Lebesgue curve.
With the default option setting , ResourceFunction["MortonCurve"][n] returns a Line primitive corresponding to a path that starts at {0,0}, then joins all integer points in the 2n-1 by 2n-1 square and ends at {2n-1,0}.
Setting DataRange{{xmin,xmax},{ymin,ymax},} yields a Morton curve that occupies the specified coordinate ranges.

## Examples

### Basic Examples (2)

A 2D z-order curve:

 In[1]:=
 Out[1]=

Lengths of the approximations to the Morton curve:

 In[2]:=
 Out[2]=

Visualize the Morton curve in 2D with splines:

 In[3]:=
 Out[3]=

### Scope (4)

A 2D Morton curve:

 In[4]:=
 Out[4]=

A 3D Morton curve:

 In[5]:=
 Out[5]=

An n-dimensional Morton curve:

 In[6]:=
 Out[6]=

Show the Morton curve for different numbers of steps:

 In[7]:=
 Out[7]=

### Options (2)

#### DataRange (2)

DataRange allows you to specify the range of mesh coordinates to generate:

 In[8]:=
 Out[8]=

Specify a different range:

 In[9]:=
 Out[9]=

### Applications (2)

Visualize the Morton curve in 3D:

 In[10]:=
 Out[10]=

With tubes:

 In[11]:=
 Out[11]=

### Properties and Relations (2)

MortonCurve consists of lines:

 In[12]:=
 Out[12]=

DataRangerange is equivalent to using RescalingTransform[{…},range]:

 In[13]:=
 Out[13]=

Use RescalingTransform directly:

 In[14]:=
 Out[14]=

### Possible Issues (2)

By default, the coordinates of the Morton curve are not in the unit square:

 In[15]:=
 Out[15]=

Use DataRange to generate the Morton curve in the unit square:

 In[16]:=
 Out[16]=

MortonCurve can be too large to generate:

 In[17]:=
 Out[17]=

### Neat Examples (1)

Traverse a Morton curve dynamically:

 In[18]:=
 Out[18]=

## Version History

• 1.0.1 – 03 May 2021