dtmm.rotation

Rotation matrices and conversion functions.

Rotation matrices

rotation_vector2() : 2D rotation vector. rotation_matrix2() : 2D rotation matrix. rotation_matrix_z() : 3D rotation matrix around z. rotation_matrix_x() : 3D rotation matrix around x. rotation_matrix_y() : 3D rotation matrix around y. rotation_matrix() : general 3D rotation matrix from Euler angles.

Conversion functions

rotate_diagonal_tensor() for 3D diagonal tensor rotation. rotate_tensor() for 3D tensor rotation. rotate_vector() for 3D vector rotation. rotation_angles() fConverts rotation matrix to Euler angles

Module Contents

dtmm.rotation.rotation_vector2(angle, out=None)

Converts the provided angle into a rotation vector (cos, sin).

Parameters
  • angle (array) – Array containing the angle of rotation at different points in space

  • out (array) – Rotation, represented as a 2D vector at every point in space

dtmm.rotation.rotation_matrix2(angle, out=None)

Returns 2D rotation matrix.

Numpy broadcasting rules apply.

dtmm.rotation.rotation_matrix_z(angle, out=None)

Calculates a rotation matrix for rotations around the z axis.

Numpy broadcasting rules apply.

dtmm.rotation.rotation_matrix_y(angle, out=None)

Calculates a rotation matrix for rotations around the y axis.

Numpy broadcasting rules apply.

dtmm.rotation.rotation_matrix_x(angle, out=None)

Calculates a rotation matrix for rotations around the x axis.

Numpy broadcasting rules apply.

dtmm.rotation.rotation_matrix(angles, out)

rotation_matrix(angles, out)

Calculates a general rotation matrix for rotations z-y-z psi, theta, phi. If out is specified.. it should be 3x3 float matrix.

Parameters

angles (array_like) – A length 3 vector of the three angles

Examples

>>> a = rotation_matrix([0.12,0.245,0.78])

The same can be obtained by:

>>> Ry = rotation_matrix_z(0.12)
>>> Rt = rotation_matrix_y(0.245)
>>> Rf = rotation_matrix_z(0.78)
>>> b = np.dot(Rf,np.dot(Rt,Ry))
>>> np.allclose(a,b)
True
dtmm.rotation.rotation_angles(matrix, out)

Computes Euler rotation angles from rotation matrix.

Numpy broadcasting rules apply.

Parameters
  • matrix ((.., 3,3) array) – Rotation matrix

  • out (ndarray, optional) – Output array

Returns

angles – Euler angles : psi (z rotation), theta (x rotation), phi (z rotation).

Return type

(..,3) ndarray

dtmm.rotation.rotate_diagonal_tensor(R, diagonal, out=None)

Rotates a diagonal tensor, based on the rotation matrix provided

>>> R = rotation_matrix((0.12,0.245,0.78))
>>> diag = np.array([1.3,1.4,1.5], dtype = CDTYPE)
>>> tensor = rotate_diagonal_tensor(R, diag)
>>> matrix = dtmm.data.tensor2matrix(tensor)

The same can be obtained by:

>>> Ry = rotation_matrix_z(0.12)
>>> Rt = rotation_matrix_y(0.245)
>>> Rf = rotation_matrix_z(0.78)
>>> R = np.dot(Rf,np.dot(Rt,Ry))
>>> diag = np.diag([1.3,1.4,1.5]) + 0j
>>> matrix2 = np.dot(R,np.dot(diag, R.transpose()))
>>> np.allclose(matrix2,matrix)
True
dtmm.rotation.rotate_tensor(R, tensor, out)

Calculates out = R.tensor.RT of a tensor”

>>> R = rotation_matrix((0.12,0.245,0.78))
>>> tensor = np.array([1.3,1.4,1.5,0.1,0.2,0.3], dtype = CDTYPE)
>>> tensor = rotate_tensor(R, tensor)
>>> matrix = tensor2matrix(tensor)
dtmm.rotation.rotate_vector(rotation_matrix, vector, out)

Rotates vector <vector> using rotation matrix <rotation_matrix> rotate_vector(R, vector)

Calculates out = R.vector of a vector.

Parameters
  • rotation_matrix (array) – 3x3 rotation matrix

  • vector (array) – Input 3-vector to rotate

  • out (array, optional) – Output rotated 3-vector

Returns

vector – Rotated vector.

Return type

ndarray