Accelerating the pace of engineering and science

# numeric::rotationMatrix

Orthogonal matrix of the rotation about an axis

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

numeric::rotationMatrix(angle, axis, <Symbolic>, <ReturnType = t>)

## Description

numeric::rotationMatrix(angle, axis) returns an orthogonal matrix corresponding to the rotation about the given axis by the given angle.

The rotation by the angle alpha about the axis given by the vector [x, y, z] of Euclidean length 1 is given by the rotation matrix

with c = cos(alpha), s = sin(alpha), and t = 1 - c = .

The rotation is implemented following the "right hand rule": Stretch the thumb of your right hand and bend the fingers. When the thumb points into the direction of the rotation axis, your finger tips indicate the direction of the rotation.

Use negative angles to rotate in the opposite direction.

The axis parameter of the routine does not need to be normalized to the Euclidean length 1. However, it must not be of zero length.

If no return type is specified via the option ReturnType = t, the domain type of the result depends on the type of the input matrix axis:

• If the axis is of domain type array, then the rotation matrix is returned as an array.

• If the axis is of domain type hfarray, then the result is returned as an hfarray.

• If the axis is of domain type Dom::DenseMatrix(), then the rotation matrix is returned as a matrix of type Dom::DenseMatrix() over the ring of MuPAD® expressions.

• If axis is of any different matrix type, the result is a matrix of type Dom::Matrix() over the ring of MuPAD expressions. This includes input matrices axis of type Dom::Matrix(...), Dom::SquareMatrix(...), Dom::MatrixGroup(...) etc.

• If axis is a list with 3 elements, the rotation matrix is also returned as an Dom::Matrix() over the ring of MuPAD expressions.

Without the option Symbolic, all arguments are automatically converted to floating-point arguments (if possible). Use the option Symbolic if no such conversion is desired.

## Environment Interactions

The function is sensitive to the environment variable DIGITS, which determines the numerical working precision.

## Examples

### Example 1

The rotation around the z axis by 45 degrees is given by the following matrix:

numeric::rotationMatrix(PI/4, [0, 0, 1])

Symbolic arguments are accepted:

numeric::rotationMatrix(a, [1, 2, 3])

With the option Symbolic, no automatic conversion to floating-point numbers occurs:

numeric::rotationMatrix(a, [1, 2, 3], Symbolic)

### Example 2

The return type coincides with the type of the input parameter representing the axis:

numeric::rotationMatrix(0.3, matrix([1,2,3]))

domtype(%)

numeric::rotationMatrix(0.3, hfarray(1..3, [1,2,3]))

domtype(%)

The option ReturnType allows to specify the type of the result:

numeric::rotationMatrix(0.3, hfarray(1..3, [1,2,3]),
ReturnType = matrix)

domtype(%)

### Example 3

The direction of the rotation is given by the "right hand rule": Stretch the thumb of your right hand and bend the fingers. When the thumb points into the direction of the rotation axis, your finger tips indicate the direction of the rotation:

axis := matrix([0, 0, 1]):
vector := matrix([1, 0, 0]):
Q := numeric::rotationMatrix(PI/4, axis):
plot(plot::Arrow3d(axis, Color = RGB::Blue),
plot::Arrow3d(vector, Color = RGB::Red),
plot::Arrow3d(Q*vector, Color = RGB::Red),
plot::Text3d("axis", [0.01, 0.01, 0.5]),
plot::Text3d("vector", [1.05, 0, 0]),
plot::Text3d("rotated vector", [0.75, 0.75, 0]),
Scaling = Constrained, Axes = None):

Use negative angles to rotate in the opposite direction:

axis := matrix([0, 0, 1]):
vector := matrix([1, 0, 0]):
Q := numeric::rotationMatrix(-PI/4, axis):
plot(plot::Arrow3d(axis, Color = RGB::Blue),
plot::Arrow3d(vector, Color = RGB::Red),
plot::Arrow3d(Q*vector, Color = RGB::Red),
plot::Text3d("axis", [0.01, 0.01, 0.5]),
plot::Text3d("vector", [1.05, 0, 0]),
plot::Text3d("rotated vector", [0.75, -0.75, 0]),
Scaling = Constrained, Axes = None):

delete axis, vector, Q:

## Parameters

 angle axis A vector represented by a list with 3 entries or by a 3 ×1 matrix of domain type DOM_ARRAY, DOM_HFARRAY, or of category Cat::Matrix

## Options

 Symbolic Prevents the conversion of the input data to floating-point numbers. Exact arithmetic is used. ReturnType Option, specified as ReturnType = t Return the result as a matrix of domain type t. The following return types are available: DOM_ARRAY, DOM_HFARRAY, matrix, or densematrix.

## Return Values

Depending on the type of the input matrix axis, the 3×3 rotation matrix is returned as a matrix of domain type DOM_ARRAY, DOM_HFARRAY, Dom::Matrix(), or Dom::DenseMatrix().