distance.md (3271B)
1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> 2 3 # Function distance 4 5 Calculates: 6 The eucledian distance between two points in N-dimensional spaces. 7 Distance between point and a line in 2 and 3 dimensional spaces. 8 Pairwise distance between a set of 2D or 3D points 9 NOTE: 10 When substituting coefficients of a line(a, b and c), use ax + by + c = 0 instead of ax + by = c 11 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) 12 13 14 ## Syntax 15 16 ```js 17 math.distance([x1, y1], [x2, y2]) 18 math.distance({pointOneX: 4, pointOneY: 5}, {pointTwoX: 2, pointTwoY: 7}) 19 math.distance([x1, y1, z1], [x2, y2, z2]) 20 math.distance({pointOneX: 4, pointOneY: 5, pointOneZ: 8}, {pointTwoX: 2, pointTwoY: 7, pointTwoZ: 9}) 21 math.distance([x1, y1, ... , N1], [x2, y2, ... , N2]) 22 math.distance([[A], [B], [C]...]) 23 math.distance([x1, y1], [LinePtX1, LinePtY1], [LinePtX2, LinePtY2]) 24 math.distance({pointX: 1, pointY: 4}, {lineOnePtX: 6, lineOnePtY: 3}, {lineTwoPtX: 2, lineTwoPtY: 8}) 25 math.distance([x1, y1, z1], [LinePtX1, LinePtY1, LinePtZ1], [LinePtX2, LinePtY2, LinePtZ2]) 26 math.distance({pointX: 1, pointY: 4, pointZ: 7}, {lineOnePtX: 6, lineOnePtY: 3, lineOnePtZ: 4}, {lineTwoPtX: 2, lineTwoPtY: 8, lineTwoPtZ: 5}) 27 math.distance([x1, y1], [xCoeffLine, yCoeffLine, constant]) 28 math.distance({pointX: 10, pointY: 10}, {xCoeffLine: 8, yCoeffLine: 1, constant: 3}) 29 math.distance([x1, y1, z1], [x0, y0, z0, a-tCoeff, b-tCoeff, c-tCoeff]) point and parametric equation of 3D line 30 math.distance([x, y, z], [x0, y0, z0, a, b, c]) 31 math.distance({pointX: 2, pointY: 5, pointZ: 9}, {x0: 4, y0: 6, z0: 3, a: 4, b: 2, c: 0}) 32 ``` 33 34 ### Parameters 35 36 Parameter | Type | Description 37 --------- | ---- | ----------- 38 `x` | Array | Matrix | Object | Co-ordinates of first point 39 `y` | Array | Matrix | Object | Co-ordinates of second point 40 41 ### Returns 42 43 Type | Description 44 ---- | ----------- 45 Number | BigNumber | Returns the distance from two/three points 46 47 48 ### Throws 49 50 Type | Description 51 ---- | ----------- 52 53 54 ## Examples 55 56 ```js 57 math.distance([0,0], [4,4]) // Returns 5.6569 58 math.distance( 59 {pointOneX: 0, pointOneY: 0}, 60 {pointTwoX: 10, pointTwoY: 10}) // Returns 14.142135623730951 61 math.distance([1, 0, 1], [4, -2, 2]) // Returns 3.74166 62 math.distance( 63 {pointOneX: 4, pointOneY: 5, pointOneZ: 8}, 64 {pointTwoX: 2, pointTwoY: 7, pointTwoZ: 9}) // Returns 3 65 math.distance([1, 0, 1, 0], [0, -1, 0, -1]) // Returns 2 66 math.distance([[1, 2], [1, 2], [1, 3]]) // Returns [0, 1, 1] 67 math.distance([[1,2,4], [1,2,6], [8,1,3]]) // Returns [2, 7.14142842854285, 7.681145747868608] 68 math.distance([10, 10], [8, 1, 3]) // Returns 11.535230316796387 69 math.distance([10, 10], [2, 3], [-8, 0]) // Returns 8.759953130362847 70 math.distance( 71 {pointX: 1, pointY: 4}, 72 {lineOnePtX: 6, lineOnePtY: 3}, 73 {lineTwoPtX: 2, lineTwoPtY: 8}) // Returns 2.720549372624744 74 math.distance([2, 3, 1], [1, 1, 2, 5, 0, 1]) // Returns 2.3204774044612857 75 math.distance( 76 {pointX: 2, pointY: 3, pointZ: 1}, 77 {x0: 1, y0: 1, z0: 2, a: 5, b: 0, c: 1} // Returns 2.3204774044612857 78 ``` 79 80