函数 distance #

计算: N 维空间中两点之间的欧几里得距离。二维和三维空间中点到直线的距离。二维或三维点集之间的成对距离。注意:在代入直线系数 (a, b, c) 时,请使用 ax + by + c = 0 而非 ax + by = c。对于三维直线的参数方程,x0, y0, z0, a, b, c 来自:(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 数组 | 矩阵 | 对象 第一个点的坐标
y 数组 | 矩阵 | 对象 第二个点的坐标

Returns #

Type Description
数字 | 大数 返回两点/三点之间的距离

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
Fork me on GitHub