cross.md (1214B)
1 <!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. --> 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 ### Throws 40 41 Type | Description 42 ---- | ----------- 43 44 45 ## Examples 46 47 ```js 48 math.cross([1, 1, 0], [0, 1, 1]) // Returns [1, -1, 1] 49 math.cross([3, -3, 1], [4, 9, 2]) // Returns [-15, -2, 39] 50 math.cross([2, 3, 4], [5, 6, 7]) // Returns [-3, 6, -3] 51 math.cross([[1, 2, 3]], [[4], [5], [6]]) // Returns [[-3, 6, -3]] 52 ``` 53 54 55 ## See also 56 57 [dot](dot.md), 58 [multiply](multiply.md)