2018-06-16 15:39:07 +02:00

57 lines
1.5 KiB
Markdown

---
layout: default
---
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
<h1 id="function-cross">Function cross <a href="#function-cross" title="Permalink">#</a></h1>
Calculate the cross product for two vectors in three dimensional space.
The cross product of `A = [a1, a2, a3]` and `B = [b1, b2, b3]` is defined
as:
cross(A, B) = [
a2 * b3 - a3 * b2,
a3 * b1 - a1 * b3,
a1 * b2 - a2 * b1
]
If one of the input vectors has a dimension greater than 1, the output
vector will be a 1x3 (2-dimensional) matrix.
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
```js
math.cross(x, y)
```
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
Parameter | Type | Description
--------- | ---- | -----------
`x` | Array &#124; Matrix | First vector
`y` | Array &#124; Matrix | Second vector
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
Type | Description
---- | -----------
Array &#124; Matrix | Returns the cross product of `x` and `y`
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
```js
math.cross([1, 1, 0], [0, 1, 1]) // Returns [1, -1, 1]
math.cross([3, -3, 1], [4, 9, 2]) // Returns [-15, -2, 39]
math.cross([2, 3, 4], [5, 6, 7]) // Returns [-3, 6, -3]
math.cross([[1, 2, 3]], [[4], [5], [6]]) // Returns [[-3, 6, -3]]
```
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
[dot](dot.html),
[multiply](multiply.html)