mcot.maths.spherical

Defines functions to work with spherical coordinates.

Functions

cart2spherical(x, y, z)

Converts to spherical coordinates.

clean_euler(phi, theta, psi)

Finds a set of angles matching the same orientation with.

euler2mat(phi, theta, psi)

Computes a rotation matrix based on the Euler angles.

mat2euler(rot_mat)

Converts a rotation matrix to spherical coordinates.

single_rotmat(theta, axis)

Rotate around the axis with theta radians.

spherical2cart(r, phi, theta)

Converts from spherical coordinates.

cart2spherical

mcot.maths.spherical.cart2spherical(x, y, z)[source]

Converts to spherical coordinates.

Parameters
  • x – x-component of the vector

  • y – y-component of the vector

  • z – z-component of the vector

Returns

tuple with (r, phi, theta)-coordinates

clean_euler

mcot.maths.spherical.clean_euler(phi, theta, psi)[source]

Finds a set of angles matching the same orientation with.

  • phi between -pi and pi

  • theta between 0 and pi

  • psi between -pi and pi

Parameters
  • phi – orientation of the z-axis projection on the x-y plane

  • theta – polar angle (0 for keeping the z-axis in the z-direction, pi/2 for projecting the z-axis onto the x-y plane)

  • psi – rotation of the major dispersion axis around the main fibre orientation

Returns

tuple with new (phi, theta, psi)

euler2mat

mcot.maths.spherical.euler2mat(phi, theta, psi)[source]

Computes a rotation matrix based on the Euler angles.

The z-axis is mapped to: euler2mat(phi, theta, _).dot([0, 0, 1] = (cos(phi) * sin(theta), sin(phi) * sin(theta), cos(theta)) psi determines the x- and y-axes orientations in the plane perpendicular to this

Bingham matrix is assumed to initially point in the z-direction

Parameters
  • phi – orientation of the z-axis projection on the x-y plane

  • theta – polar angle (0 for keeping the z-axis in the z-direction, pi/2 for projecting the z-axis onto the x-y plane)

  • psi – rotation of the major dispersion axis around the main fibre orientation

Returns

(…, 3, 3) array with rotation matrix

mat2euler

mcot.maths.spherical.mat2euler(rot_mat)[source]

Converts a rotation matrix to spherical coordinates.

see spherical.euler2mat for the relation between the rotation matrix and the euler angles

Parameters

rot_mat – (…, 3, 3) array

Returns

euler angles (phi, theta, psi))

single_rotmat

mcot.maths.spherical.single_rotmat(theta, axis)[source]

Rotate around the axis with theta radians.

Parameters
  • theta – Angle of the rotations

  • axis – index of the axis (0, 1, or 2 for x, y, or z)

Returns

(3, 3) array with the rotation matrix

spherical2cart

mcot.maths.spherical.spherical2cart(r, phi, theta)[source]

Converts from spherical coordinates.

Parameters
  • r – radius

  • phi – angle within the x-y plane (longitude)

  • theta – angle relative to z-axis (latitude)

Returns

tuple with (x, y, z) coordinates