UNPKG

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