rotation_transform
3D rotation (stored as a unit quaternion).
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 data | Unit 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
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.onvec2
Convert 2
std::string str(rotation_transform const& r)String of the underlying unit quaternion (x y z w) of the rotation.
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 overloadsaffine_rt operator*(rotation_transform const& R, affine_rt const& T)sourceRigid 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)sourceTransform R o T: the rotation is applied after T, rotating its translation as well.
affine_rts operator*(float s, rotation_transform const& r)sourceRotation-translation-scaling transform made of the rotation r scaled by s, with zero translation.
affine_rts operator*(rotation_transform const& r, float s)sourceRotation-translation-scaling transform made of the rotation r scaled by s, with zero translation.
frame operator*(rotation_transform const& R, frame const& f)sourceFrame rotated around the origin: both its orientation and its position are rotated.
rotation_transform operator*(rotation_transform const& r1, rotation_transform const& r2)sourceComposition r1 o r2 of two rotations (product of their quaternions).
vec3 operator*(rotation_transform const& r, vec3 const& p)sourceVector rotated by the rotation.
vec4 operator*(rotation_transform const& r, vec4 const& p)sourceHomogeneous vector whose xyz part is rotated, w being kept.
mat3 operator*(rotation_transform const& r, mat3 const& M)sourceProduct of the rotation matrix with a mat3.
mat4 operator*(rotation_transform const& r, mat4 const& M)sourceProduct 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.