# distance() Function & Examples

Use the distance() geometry function in Calcul.io. Review its syntax, edit working examples, understand the result, and explore related math functions.

## distance

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

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

Try it yourself:

```calculio
distance([0,0], [4,4])
distance([[0,0], [4,4]])
```

---

## 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()](https://calcul.io/function/hypot/index.md) is a convenient related operation. Build coordinate differences with [subtract()](https://calcul.io/function/subtract/index.md), and use [abs()](https://calcul.io/function/abs/index.md) 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()](https://calcul.io/function/to/index.md) when measurements use different scales.

[All functions](https://calcul.io/functions/index.md)
