Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Evaluate the shortest distance between two points in a box with periodic boundary conditions
ResourceFunction["PeriodicBoxDistance"][u,v,L] gives the shortest distance between vectors u and v in a cubic box of side-length L centered on the origin with periodic boundary conditions. |
Compute a 1D periodic box distance in the "box" represented by the interval [-1,1]:
In[1]:= |
Out[1]= |
PeriodicBoxDistance reverts to Euclidean distance when points are close by within the box:
In[2]:= |
Out[2]= |
Parallel points on the boundaries of the box have zero separation:
In[3]:= |
Out[3]= |
PeriodicBoxDistance also works in higher dimensions:
In[4]:= |
Out[4]= |
Compare PeriodicBoxDistance from the origin with Euclidean distance in two dimensions:
In[5]:= |
Out[5]= |
This work is licensed under a Creative Commons Attribution 4.0 International License