CGPdocs

rotation_transform

3D rotation (stored as a unit quaternion).

module 09_geometric_transformationsource: rotation_transform.hpp
rotation_transform wraps a unit quaternion: build it from an axis and an angle, two vectors, a frame or a matrix, then rotate points, compose, invert or interpolate.
rotation_transform wraps a unit quaternion: build it from an axis and an angle, two vectors, a frame or a matrix, then rotate points, compose, invert or interpolate. Tap to enlarge.

Fields and methods

Members of the struct rotation_transform. Most of what you do with a CGP type goes through the free functions listed below.

Fields

quaternion dataUnit quaternion (x, y, z, w) storing the rotation, w being the scalar part.

Methods

rotation_transform()Builds the identity rotation, quaternion (0, 0, 0, 1).2 overloads src
rotation_transform(quaternion const& q)Builds the rotation of a quaternion, asserting that its norm is within 0.05 of 1, and stores it normalized. src
Returns the rotation of a unit quaternion, asserting that its norm is within 0.05 of 1 (it is stored as is, not normalized). src
Returns the rotation of angle in radians around axis (normalized internally, so it must be nonzero), counterclockwise by the right-hand rule. src
Returns the rotation of a 3x3 rotation matrix, converted to a quaternion that is then normalized (a warning is printed if the matrix is not orthogonal). src
Returns the rotation of smallest angle mapping the unit vector e_source onto the unit vector e_target (unit norms asserted); for opposite vectors, a rotation of Pi around an orthogonal axis. src
Returns the rotation R such that R e1 = e1_target and R e2 = e2_target, both pairs being asserted to be orthonormal. src
Returns the 3x3 rotation matrix computed from the quaternion. src
Returns a const reference to the stored quaternion. src
Writes in axis and angle the unit axis and the angle in radians (between 0 and 2 Pi) of the rotation, or (1,0,0) and 0 for a near-identity rotation; asserts that the quaternion norm is within 1e-6 of 1. src
Returns the first row of the rotation matrix, computed directly from the quaternion. src
Returns the second row of the rotation matrix, computed directly from the quaternion. src
Returns the third row of the rotation matrix, computed directly from the quaternion. src
Returns the first column of the rotation matrix, i.e. the image of the x axis, computed directly from the quaternion. src
Returns the second column of the rotation matrix, i.e. the image of the y axis, computed directly from the quaternion. src
Returns the third column of the rotation matrix, i.e. the image of the z axis, computed directly from the quaternion. src
Returns the 3x3 matrix of the rotation of angle in radians around axis (Rodrigues formula); unlike from_axis_angle, the axis is not normalized and its unit norm is asserted within 1e-6. src
Writes in axis and angle the unit axis and the angle in radians of a 3x3 rotation matrix, through from_matrix and to_axis_angle. src
Returns the 3x3 rotation matrix of a quaternion assumed to have unit norm (not checked). src
Returns the quaternion of a 3x3 rotation matrix (trace-based method), without normalizing it; a warning is printed if its norm differs from 1 by more than 0.05. src
Returns the unit quaternion (sin(angle/2) u, cos(angle/2)) of the rotation of angle in radians around u, the normalized axis. src
Writes in axis and angle the unit axis and the angle in radians of a quaternion whose unit norm is asserted within 1e-6, or (1,0,0) and 0 when its vector part is below 1e-4. src
Returns the normalized linear interpolation (nlerp, not slerp) between the quaternions of r1 (alpha=0) and r2 (alpha=1), along the shortest path (q2 is negated when dot(q1,q2)<0). src

Functions taking a rotation_transform

Transform 1

rotation_transform inverse(rotation_transform const& r)

Inverse rotation.

Compute 2

affine_rt rotation_around_center(rotation_transform const& R, vec3 const& center)

Rigid transform that applies the rotation R around center instead of the origin, mapping p to R(p - center) + center.

Documented on another page

  • translation_in_plane3D vector of a 2D translation expressed in the xy plane of the given orientation.on vec2

Convert 2

std::string str(rotation_transform const& r)

String of the underlying unit quaternion (x y z w) of the rotation.

std::string type_str(rotation_transform const&)

Type name "rotation_transform".

Functions returning a rotation_transform

Construct 2

rotation_transform rotation_axis_angle(vec3 const& axis, float angle)

Rotation of a given angle in radians around an axis (normalized internally).

rotation_transform trackball_rotation(vec2 const& p0, vec2 const& p1)

Rotation moving the trackball projection of p0 onto that of p1, identity if the two points are closer than 1e-4.

Operators

Show the 14 operators (+, -, *, ==, ...)

operator*

10 overloads
affine_rt operator*(rotation_transform const& R, affine_rt const& T)
source

Rigid transform R o T: the rotation is applied after T, rotating its translation as well.

affine_rts operator*(rotation_transform const& R, affine_rts const& T)
source

Transform R o T: the rotation is applied after T, rotating its translation as well.

affine_rts operator*(float s, rotation_transform const& r)
source

Rotation-translation-scaling transform made of the rotation r scaled by s, with zero translation.

affine_rts operator*(rotation_transform const& r, float s)
source

Rotation-translation-scaling transform made of the rotation r scaled by s, with zero translation.

frame operator*(rotation_transform const& R, frame const& f)
source

Frame rotated around the origin: both its orientation and its position are rotated.

rotation_transform operator*(rotation_transform const& r1, rotation_transform const& r2)
source

Composition r1 o r2 of two rotations (product of their quaternions).

vec3 operator*(rotation_transform const& r, vec3 const& p)
source

Vector rotated by the rotation.

vec4 operator*(rotation_transform const& r, vec4 const& p)
source

Homogeneous vector whose xyz part is rotated, w being kept.

mat3 operator*(rotation_transform const& r, mat3 const& M)
source

Product of the rotation matrix with a mat3.

mat4 operator*(rotation_transform const& r, mat4 const& M)
source

Product of the rotation, as a 4x4 matrix, with a mat4.

rotation_transform& operator*=(rotation_transform& r1, rotation_transform const& r2)

In-place composition r1 = r1 o r2.

std::ostream& operator<<(std::ostream& s, rotation_transform const& r)

Write the underlying unit quaternion of the rotation to the stream.

Documented on another page

  • operator*Rigid transform T o R: the rotation is applied before T.on affine_rt
  • operator*Transform T o R: the rotation is applied before T.on affine_rts
CGP - Computer Graphics Programming.