Skip to content

pymath.length

Daniel Flassig edited this page Jul 17, 2026 · 1 revision

Returns the Euclidean length of a vector, or the distance between two points.

len = pymath.length(v)
dist = pymath.length(v, w)
Parameter Type Description
v vector A vector (or point) of any dimension.
w vector (optional) A second point of the same dimension; when given, the distance `

Return value

Type Description
len The 2-norm of v, or of w - v when w is given.

Notes:

  • Both vectors must have the same dimension.
  • The computation is overflow-safe: it stays accurate even for very large or small components.
  • For loose number arguments instead of a vector table, see the global PYTHAGORAS(x, y, ...) in Math functions.

Example:

local len = pymath.length({3, 4})
-- len == 5.0

local dist = pymath.length({1, 1, 0}, {4, 5, 0})
-- dist == 5.0

local diag = pymath.length({1, 1, 1})
-- diag == 1.7320508...          -- sqrt(3)

Version Support:

Minimum PYTHA Version: V27

See also:

pymath, pymath.normalize, pymath.dot, Math functions

Clone this wiki locally