UNPKG

1.16 kBMarkdownView Raw
1<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
2
3# Function cross
4
5Calculate the cross product for two vectors in three dimensional space.
6The cross product of `A = [a1, a2, a3]` and `B = [b1, b2, b3]` is defined
7as:
8
9 cross(A, B) = [
10 a2 * b3 - a3 * b2,
11 a3 * b1 - a1 * b3,
12 a1 * b2 - a2 * b1
13 ]
14
15If one of the input vectors has a dimension greater than 1, the output
16vector will be a 1x3 (2-dimensional) matrix.
17
18
19## Syntax
20
21```js
22math.cross(x, y)
23```
24
25### Parameters
26
27Parameter | Type | Description
28--------- | ---- | -----------
29`x` | Array &#124; Matrix | First vector
30`y` | Array &#124; Matrix | Second vector
31
32### Returns
33
34Type | Description
35---- | -----------
36Array &#124; Matrix | Returns the cross product of `x` and `y`
37
38
39## Examples
40
41```js
42math.cross([1, 1, 0], [0, 1, 1]) // Returns [1, -1, 1]
43math.cross([3, -3, 1], [4, 9, 2]) // Returns [-15, -2, 39]
44math.cross([2, 3, 4], [5, 6, 7]) // Returns [-3, 6, -3]
45math.cross([[1, 2, 3]], [[4], [5], [6]]) // Returns [[-3, 6, -3]]
46```
47
48
49## See also
50
51[dot](dot.md),
52[multiply](multiply.md)