distance

distance([x1, y1], [x2, y2])

distance([[x1, y1], [x2, y2]])

Try it yourself:


distance(): Measuring Separation Between Points

distance() calculates the separation between compatible points or vectors. In ordinary Euclidean coordinates, it generalizes the Pythagorean theorem: the distance between (x₁, y₁) and (x₂, y₂) is the square root of the summed squared coordinate differences.

Useful geometry

Distance is useful for nearest-neighbour checks, collision ranges, movement, and error measurement. For a two-component difference, hypot() is a convenient related operation. Build coordinate differences with subtract(), and use abs() when you need per-axis displacement rather than straight-line distance.

Input caveats

Points need matching dimensions and compatible units. A two-dimensional point cannot be directly compared with a three-dimensional point without an explicit convention. For matrices, distinguish geometric distance from element-wise differences. Normalize units first with to() when measurements use different scales.

Try Distance in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions