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