jaxmat.tensors.rotation module#
- from_axis_angle(axis, theta)[source]#
Construct rotation matrix/matrices from an axis-angle representation.
Uses Rodrigues’ rotation formula:
\[R = I + \sin\theta \, [\hat{a}]_\times + (1-\cos\theta) [\hat{a}]_\times^2\]where \(\hat{a}\) is the unit rotation axis.
- Parameters:
axis (array_like, shape (..., 3)) – Rotation axis vectors. They do not need to be normalized. The last dimension must be 3. First except last dimensions are interpreted as batch dimensions.
theta (array_like, shape (...)) – Rotation angle(s) in radians. Must be broadcast-compatible with
axis[..., 0].
- Returns:
R – Rotation matrix/matrices in SO(3).
- Return type:
jax.Array, shape (…, 3, 3)
- from_quaternion(q)[source]#
Construct rotation matrix/matrices from quaternion(s).
The quaternion is assumed to follow the scalar-first convention:
\[q = (w, x, y, z)\]- Parameters:
q (array_like, shape (..., 4)) – Quaternion(s) in scalar-first format
(w, x, y, z). The quaternion(s) need not be normalized.- Returns:
R – Rotation matrix/matrices in SO(3).
- Return type:
jax.Array, shape (…, 3, 3)
- from_euler_bunge(phi1, Phi, phi2)[source]#
Construct rotation matrix/matrices from Bunge Euler angles (ZXZ convention).
The rotation is the active rotation, composed of the active rotations \(R_z, R_x\) about the axes (as returned by
from_axis_angle()):\[R = R_z(\phi_1) R_x(\Phi) R_z(\phi_2)\]It maps the sample axes onto the crystal axes: its columns are the crystal axes in the sample frame, a vector of crystal components \(v_c\) has the sample components \(R v_c\), and a tensor
Tgiven in the crystal axes is expressed in the sample axes byT.rotate(R). It is the transpose of the Bunge orientation matrix \(g = R^T\) (rows are the crystal axes), which converts sample to crystal components.- Parameters:
phi1 (array_like, shape (...)) – First rotation about the z-axis (radians).
Phi (array_like, shape (...)) – Second rotation about the x-axis (radians).
phi2 (array_like, shape (...)) – Third rotation about the z-axis (radians).
- Returns:
R – Rotation matrix/matrices in SO(3).
- Return type:
jax.Array, shape (…, 3, 3)
- random(key, shape=())[source]#
Uniform random rotation(s) in SO(3).
Uses the Shoemake quaternion sampling method to generate rotations uniformly distributed with respect to the Haar measure on SO(3).
- Parameters:
key (jax.random.PRNGKey) – Random key.
shape (tuple of int, optional) – Batch shape.
- Returns:
R – Random rotation matrix/matrices.
- Return type:
jax.Array, shape (*shape, 3, 3)