erot
Introduced in 0.99
Synopsis

Rotation matrix from Euler angles.

Rp = erot(Angles)
Rp = erot(alpha,beta,gamma)
Description

erot returns an 3x3 rotation matrix in Rp. The 3-element vector Angles=[alpha beta gamma] defines the three Euler angles for the rotation in radians. They can be also specified as three separate arguments alpha, beta and gamma.

For a detailed description of the associated rotation, the convention used, and mathematical formulas see the page on relative orientations.

Basically, erot provides a transformation matrix for passive rotations of vectors and matrices

  v1 = Rp*v;   A1 = Rp*A*Rp.';
i.e. Rp does not rotate the quantity itself, but the coordinate system in which it is represented. So after the rotation, the vector/matrix is still the same, only its representation has changed. In some contexts, a passive rotation is also called a basis transform.

Ra = Rp.' is the corresponding active transformation. The active rotation is also a composition of three rotations: first by -gamma around z, then by -beta around y, and last by -alpha around z. In this case it is the vector or matrix rather than the coordinate system which changes orientation.

Examples

To rotate the basis of the matrix A so that the final Z axis is along -z, and (X,Y) = (-y,-x), type

A = [1 2 3; 4 5 6; 7 8 9];
Rp = erot(pi/2,pi,0);
A1= Rp*A*Rp.'
A1 =
    5.0000    4.0000    6.0000
    2.0000    1.0000    3.0000
    8.0000    7.0000    9.0000

To rotate a magnetic field vector from the z direction to a direction in the first quadrant specified by the polar angles theta (down from z axis, elevation complement) and phi (counterclockwise around z from x, azimuth), use an active rotation.

B = [0;0;9.5]; theta = 20; phi = 75;
Rp = erot([phi theta 0]*pi/180);
Ra = Rp.'; B1 = Ra*B
B1 =
    0.8410
    3.1385
    8.9271
Algorithm

See relative orientations for details.

See also

ang2vec, eulang, vec2ang