UNPKG

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