1 |
|
2 |
|
3 | # Function cross
|
4 |
|
5 | Calculate the cross product for two vectors in three dimensional space.
|
6 | The cross product of `A = [a1, a2, a3]` and `B = [b1, b2, b3]` is defined
|
7 | as:
|
8 |
|
9 | cross(A, B) = [
|
10 | a2 * b3 - a3 * b2,
|
11 | a3 * b1 - a1 * b3,
|
12 | a1 * b2 - a2 * b1
|
13 | ]
|
14 |
|
15 | If one of the input vectors has a dimension greater than 1, the output
|
16 | vector will be a 1x3 (2-dimensional) matrix.
|
17 |
|
18 |
|
19 | ## Syntax
|
20 |
|
21 | ```js
|
22 | math.cross(x, y)
|
23 | ```
|
24 |
|
25 | ### Parameters
|
26 |
|
27 | Parameter | Type | Description
|
28 | --------- | ---- | -----------
|
29 | `x` | Array | Matrix | First vector
|
30 | `y` | Array | Matrix | Second vector
|
31 |
|
32 | ### Returns
|
33 |
|
34 | Type | Description
|
35 | ---- | -----------
|
36 | Array | Matrix | Returns the cross product of `x` and `y`
|
37 |
|
38 |
|
39 | ## Examples
|
40 |
|
41 | ```js
|
42 | math.cross([1, 1, 0], [0, 1, 1]) // Returns [1, -1, 1]
|
43 | math.cross([3, -3, 1], [4, 9, 2]) // Returns [-15, -2, 39]
|
44 | math.cross([2, 3, 4], [5, 6, 7]) // Returns [-3, 6, -3]
|
45 | math.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)
|