mathjs
Version:
Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif
52 lines (34 loc) • 1.64 kB
Markdown
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function rotationMatrix
Create a 2-dimensional counter-clockwise rotation matrix (2x2) for a given angle (expressed in radians).
Create a 2-dimensional counter-clockwise rotation matrix (3x3) by a given angle (expressed in radians) around a given axis (1x3).
## Syntax
```js
math.rotationMatrix(theta)
math.rotationMatrix(theta, format)
math.rotationMatrix(theta, [v])
math.rotationMatrix(theta, [v], format)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`theta` | number | BigNumber | Complex | Unit | Rotation angle
`v` | Array | Matrix | Rotation axis
`format` | string | Result Matrix storage format
### Returns
Type | Description
---- | -----------
Array | Matrix | Rotation matrix
## Examples
```js
math.rotationMatrix(math.pi / 2) // returns [[0, -1], [1, 0]]
math.rotationMatrix(math.bignumber(1)) // returns [[bignumber(cos(1)), bignumber(-sin(1))], [bignumber(sin(1)), bignumber(cos(1))]]
math.rotationMatrix(math.complex(1 + i)) // returns [[cos(1 + i), -sin(1 + i)], [sin(1 + i), cos(1 + i)]]
math.rotationMatrix(math.unit('1rad')) // returns [[cos(1), -sin(1)], [sin(1), cos(1)]]
math.rotationMatrix(math.pi / 2, [0, 1, 0]) // returns [[0, 0, 1], [0, 1, 0], [-1, 0, 0]]
math.rotationMatrix(math.pi / 2, matrix([0, 1, 0])) // returns matrix([[0, 0, 1], [0, 1, 0], [-1, 0, 0]])
```
## See also
[matrix](matrix.md),
[cos](cos.md),
[sin](sin.md)