According to Euler's rotation theorem, any rotation may be described using three angles. If the rotations are written in terms of rotation matrices , , and , then a general rotation can be written as
(1)

The three angles giving the three rotation matrices are called Euler angles. There are several conventions for Euler angles, depending on the axes about which the rotations are carried out. Write the matrix as
(2)

The socalled "convention," illustrated above, is the most common definition. In this convention, the rotation given by Euler angles , where
1. the first rotation is by an angle about the zaxis using ,
2. the second rotation is by an angle about the former xaxis (now ) using , and
3. the third rotation is by an angle about the former zaxis (now ) using .
Note, however, that several notational conventions for the angles are in common use. Goldstein (1980, pp. 145148) and Landau and Lifschitz (1976) use , Tuma (1974) says is used in aeronautical engineering in the analysis of space vehicles (but claims that is used in the analysis of gyroscopic motion), while Bate et al. (1971) use . Goldstein remarks that continental authors usually use , and warns that lefthanded coordinate systems are also in occasional use (Osgood 1937, Margenau and Murphy 195664). Varshalovich (1988, pp. 2123) uses the notation or to denote the Euler angles, and gives three different angle conventions, none of which corresponds to the convention.
Here, the notation is used, a convention that could be used in versions of the Wolfram Language prior to 6 as RotationMatrix3D[phi, theta, psi] (which could be run after loading Geometry`Rotations`) and RotateShape[g, phi, theta, psi] (which could be run after loading Geometry`Shapes`). In the convention, the component rotations are then given by
(3)
 
(4)
 
(5)

so
(6)
 
(7)
 
(8)
 
(9)
 
(10)
 
(11)
 
(12)
 
(13)
 
(14)

To obtain the components of the angular velocity in the body axes, note that for a matrix
(15)

it is true that
(16)
 
(17)

Now, corresponds to rotation about the axis, so look at the component of ,
(18)
 
(19)

The line of nodes corresponds to a rotation by about the axis, so look at the component of ,
(20)
 
(21)
 
(22)

Similarly, to find rotation by about the remaining axis, look at the component of ,
(23)
 
(24)
 
(25)

Combining the pieces gives
(26)

For more details, see Goldstein (1980, p. 176) and Landau and Lifschitz (1976, p. 111).
The convention Euler angles are given in terms of the CayleyKlein parameters by
(27)
 
(28)
 
(29)

In the "convention,"
(30)
 
(31)

Therefore,
(32)
 
(33)
 
(34)
 
(35)

giving rotation matrices
(36)
 
(37)
 
(38)

and is given by
(39)
 
(40)
 
(41)
 
(42)
 
(43)
 
(44)
 
(45)
 
(46)
 
(47)

In the " (pitchrollyaw) convention," is pitch, is roll, and is yaw.
(48)
 
(49)
 
(50)

and is given by
(51)
 
(52)
 
(53)
 
(54)
 
(55)
 
(56)
 
(57)
 
(58)
 
(59)

A set of parameters sometimes used instead of angles are the Euler parameters , , and , defined by
(60)
 
(61)

Using Euler parameters (which are quaternions), an arbitrary rotation matrix can be described by
(62)
 
(63)
 
(64)
 
(65)
 
(66)
 
(67)
 
(68)
 
(69)
 
(70)

(Goldstein 1980, p. 153).
If the coordinates of two sets of points and are known, one rotated with respect to the other, then the Euler rotation matrix can be obtained in a straightforward manner using least squares fitting. Write the points as arrays of vectors, so
(71)

Writing the arrays of vectors as matrices gives
(72)

(73)

and solving for gives
(74)

However, we want the angles , , and , not their combinations contained in the matrix . Therefore, write the matrix
(75)

as a vector
(76)

Now set up the matrices
(77)

Using nonlinear least squares fitting then gives solutions which converge to .