Calculate distance between two points. If both points have a z property, the distance is 3D distance is calculated. If only one point has a z, it is ignored.

// Distance between two points
const ptA = { x: 0.5, y:0.8 };
const ptB = { x: 1, y: 0.4 };
distance(ptA, ptB);
// Or, provide x,y as parameters
distance(ptA, 0.4, 0.9);

// Distance from ptA to x: 0.5, y:0.8, z: 0.1
const ptC = { x: 0.5, y:0.5, z: 0.3 };
// With x,y,z as parameters:
distance(ptC, 0.5, 0.8, 0.1);

First point

Second point, or x coord

y coord, if x coord is given

Optional z coord, if x and y are given.

  • Parameters

    Returns number

  • Parameters

    • a: Point
    • x: number
    • y: number

    Returns number