12 lines
599 B
Plaintext
12 lines
599 B
Plaintext
// PairDistance: the distance between two points in a cubic periodic box of
|
|
// side Box, each coordinate difference taken by the minimum image
|
|
// convention. HYPOT adds the squares without overflowing on the way.
|
|
USE md.MinimumImage
|
|
FUNCTION PairDistance(A : LIST OF FLOAT, B : LIST OF FLOAT, Box : FLOAT) RETURNS FLOAT
|
|
REQUIRE LENGTH(A) == 3 AND LENGTH(B) == 3 AND Box > 0.0
|
|
DECLARE Dx : FLOAT <- MinimumImage(A[0] - B[0], Box)
|
|
DECLARE Dy : FLOAT <- MinimumImage(A[1] - B[1], Box)
|
|
DECLARE Dz : FLOAT <- MinimumImage(A[2] - B[2], Box)
|
|
RETURN HYPOT(HYPOT(Dx, Dy), Dz)
|
|
ENDFUNCTION
|