Function distance #
Calculates: The eucledian distance between two points in N-dimensional spaces. Distance between point and a line in 2 and 3 dimensional spaces. Pairwise distance between a set of 2D or 3D points NOTE: When substituting coefficients of a line(a, b and c), use ax + by + c = 0 instead of ax + by = c For parametric equation of a 3D line, x0, y0, z0, a, b, c are from: (x−x0, y−y0, z−z0) = t(a, b, c)
Syntax #
math.distance([x1,y1], [x2,y2])
math.distance({pointOneX, pointOneY}, {pointTwoX, pointTwoY})
math.distance([x1,y1,z1], [x2,y2,z2])
math.distance({pointOneX, pointOneY, pointOneZ}, {pointTwoX, pointTwoY, pointTwoZ})
math.distance([x1,y1,z1,a1], [x2,y2,z2,a2])
math.distance([[x1,y1], [x2,y2], [x3,y3]])
math.distance([[x1,y1,z1], [x2,y2,z2], [x3,y3,z3]])
math.distance([pointX,pointY], [a,b,c])
math.distance([pointX,pointY], [lineOnePtX,lineOnePtY], [lineTwoPtX,lineTwoPtY])
math.distance({pointX, pointY}, {lineOnePtX, lineOnePtY}, {lineTwoPtX, lineTwoPtY})
math.distance([pointX,pointY,pointZ], [x0, y0, z0, a, b, c])
math.distance({pointX, pointY, pointZ}, {x0, y0, z0, a, b, c})
Parameters #
Parameter | Type | Description |
---|---|---|
x |
Array | Matrix | Object | Co-ordinates of first point |
y |
Array | Matrix | Object | Co-ordinates of second point |
Returns #
Type | Description |
---|---|
Number | BigNumber | Returns the distance from two/three points |
Throws #
Type | Description —- | ———–
Examples #
math.distance([0,0], [4,4]) // Returns 5.656854249492381
math.distance(
{pointOneX: 0, pointOneY: 0},
{pointTwoX: 10, pointTwoY: 10}) // Returns 14.142135623730951
math.distance([1, 0, 1], [4, -2, 2]) // Returns 3.7416573867739413
math.distance(
{pointOneX: 4, pointOneY: 5, pointOneZ: 8},
{pointTwoX: 2, pointTwoY: 7, pointTwoZ: 9}) // Returns 3
math.distance([1, 0, 1, 0], [0, -1, 0, -1]) // Returns 2
math.distance([[1, 2], [1, 2], [1, 3]]) // Returns [0, 1, 1]
math.distance([[1,2,4], [1,2,6], [8,1,3]]) // Returns [2, 7.14142842854285, 7.681145747868608]
math.distance([10, 10], [8, 1, 3]) // Returns 11.535230316796387
math.distance([0, 0], [3, 0], [0, 4]) // Returns 2.4
math.distance(
{pointX: 0, pointY: 0},
{lineOnePtX: 3, lineOnePtY: 0},
{lineTwoPtX: 0, lineTwoPtY: 4}) // Returns 2.4
math.distance([2, 3, 1], [1, 1, 2, 5, 0, 1]) // Returns 2.3204774044612857
math.distance(
{pointX: 2, pointY: 3, pointZ: 1},
{x0: 1, y0: 1, z0: 2, a: 5, b: 0, c: 1}) // Returns 2.3204774044612857