page_title: Quaternions and spatial rotation
section_title: Using quaternion as rotations
hierarchical_section_title: Quaternions and spatial rotation / Using quaternion as rotations
caption_attribution_description: English: Representation of how the axis and angle rotation representation can be visualized. It may not be confused with “Euler angles”.
context_page_description: Unit quaternions, also known as versors, provide a convenient mathematical notation for representing orientations and rotations of objects in three dimensions. Compared to Euler angles they are simpler to compose and avoid the problem of gimbal lock. Compared to rotation matrices they are more compact, more numerically stable, and more efficient. Quaternions have applications in computer graphics, computer vision, robotics, navigation, molecular dynamics, flight dynamics, orbital mechanics of satellites and crystallographic texture analysis.
  When used to represent rotation, unit quaternions are also called rotation quaternions as they represent the 3D rotation group. When used to represent an orientation, they are called orientation quaternions or attitude quaternions. The equation for spatial rotations can be summarized for radians about a unit axis as the Quaternion where and.
context_section_description: In 3-dimensional space, according to Euler's rotation theorem, any rotation or sequence of rotations of a rigid body or coordinate system about a fixed point is equivalent to a single rotation by a given angle  about a fixed axis (called the Euler axis) that runs through the fixed point. The Euler axis is typically represented by a unit vector u→. Therefore, any rotation in three dimensions can be represented as a combination of a vector u→  and a scalar . Quaternions give a simple way to encode this axis–angle representation in four numbers, and can be used to apply the corresponding rotation to a position vector, representing a point relative to the origin in R³.
  A Euclidean vector such as (2, 3, 4) or (aₓ, ay, az) can be rewritten as 2 i + 3 j + 4 k or aₓ i + ay j + az k, where i, j, k are unit vectors representing the three Cartesian axes. A rotation through an angle of  around the axis defined by a unit vector
  can be represented by a quaternion. This can be done using an extension of Euler's formula:
  It can be shown that the desired rotation can be applied to an ordinary vector  in 3-dimensional space, considered as a quaternion with a real coordinate equal to zero, by evaluating the conjugation of p by q:
  using the Hamilton product, where p′ = (pₓ′, py′, pz′) is the new position vector of the point after the rotation. In a programmatic implementation, this is achieved by constructing a quaternion whose vector part is p and real part equals zero and then performing the quaternion multiplication. The vector part of the resulting quaternion is the desired vector p′.
  Mathematically, this operation carries the set of all "pure" quaternions p (those with real part equal to zero)—which constitute a 3-dimensional space among the quaternions—into itself, by the desired rotation about the axis u, by the angle θ. (Each real quaternion is carried into itself by this operation. But for the purpose of rotations in 3-dimensional space, we ignore the real quaternions.)
  The rotation is clockwise if our line of sight points in the same direction as u→.
  In this instance, q is a unit quaternion and
  It follows that conjugation by the product of two quaternions is the composition of conjugations by these quaternions: If p and q are unit quaternions, then rotation (conjugation) by pq is
  ,
  which is the same as rotating (conjugating) by q and then by p. The scalar component of the result is necessarily zero.
  The quaternion inverse of a rotation is the opposite rotation, since . The square of a quaternion rotation is a rotation by twice the angle around the same axis. More generally qⁿ is a rotation by n times the angle around the same axis as q. This can be extended to arbitrary real n, allowing for smooth interpolation between spatial orientations; see Slerp.
  Two rotation quaternions can be combined into one equivalent quaternion by the relation:
  in which q′ corresponds to the rotation q₁ followed by the rotation q₂. (Note that quaternion multiplication is not commutative.) Thus, an arbitrary number of rotations can be composed together and then applied as a single rotation.
caption: A visualization of a rotation represented by an Euler axis and angle.
exif: {}