|
geomc 1.0
A c++ linear algebra template library
|
Quaternion class. More...
#include <geomc/linalg/Quaternion.h>
Public Types | |
| using | elem_t |
| The coordinate type of this object. | |
| using | point_t |
| The type of a point in this object's space. | |
| typedef Quat< T > | self_t |
Self type. I.e., Vec<T,N> if a vector, Quat<T> if a quaternion. | |
Public Member Functions | |
| Quat () | |
| Construct a quaternion with all elements 0. | |
| Quat (const std::initializer_list< T > &items) | |
| Quat (const T v[4]) | |
Construct a quaternion from the contents of the 4-element array v | |
| Quat (const Vec< T, 3 > &v, T w) | |
Construct a quaternion with vector part v and real part w. | |
| Quat (const Vec< T, 4 > &v) | |
Construct a quaternion from the 4D vector v. | |
| Quat (T x, T y, T z, T w) | |
Construct a quaternion with elements (x, y, z, w) | |
| self_t | abs () const |
| Element-wise absolute value. | |
| self_t | add (const self_t &v) const |
| Vector addition. | |
| self_t | align (const self_t &from, const self_t &to) const |
Apply a rotation to this which aligns the unit vectors from with to. | |
| T | angle () const |
| T | angle_to (const self_t &v) const |
| Angle between vectors. | |
| index_t | argmax () const |
| Return the index of the coordinate with the largest absolute value. | |
| index_t | argmin () const |
| Return the index of the coordinate with the smallest absolute value. | |
| T * | begin () |
| const T * | begin () const |
| self_t | bounce_on (const self_t &normal) const |
| Elastic collision. | |
| self_t | ceil () const |
| Element-wise ceiling function. | |
| self_t | clamp (const self_t &lo, const self_t &hi) const |
| Element-wise clamp. | |
| Quat< T > | conj () const |
| The complex conjugate of this quaternion; also the inverse rotation. | |
| T | dist (const self_t &pt) const |
| Distance between points. | |
| T | dist2 (const self_t &pt) const |
| Distance squared to a point. | |
| T | dot (const self_t &v) const |
| Dot product. | |
| T * | end () |
| const T * | end () const |
| Quat< T > | exp () const |
Quaternion exponential eq. | |
| self_t | floor () const |
| Element-wise floor function. | |
| T | fraction_on (const self_t &axis) const |
Return the component of this that projects to axis, as a fraction of axis's length. | |
| T & | get (index_t idx) |
| const T & | get (index_t idx) const |
| Vec< T, 3 > | imag () const |
| The vector part of this quaternion. | |
| bool | is_zero () const |
Return true if all elements are zero. | |
| Quat< T > | log () const |
| Quaternion natural log. | |
| T | mag () const |
| Euclidean norm (magnitude). | |
| T | mag2 () const |
| Squared magnitude. | |
| T | max () const |
| Maximum element. | |
| self_t | max (const self_t &v) const |
Element-wise maximum of two Vecs. | |
| T | min () const |
| Minimum element. | |
| self_t | min (const self_t &v) const |
Element-wise minimum of two Vecs. | |
| self_t | mix (const self_t &v, T mix) const |
| Linear interpolation. | |
| Quat< T > | mult (const Quat< T > &q) const |
| Quaternion multiplication. | |
| template<typename U> | |
| operator Quat< U > () const | |
Cast this Quat to a new coordinate type U. | |
| operator Vec< U, N > () const | |
| Element typecast. | |
| bool | operator!= (const self_t &vv) const |
| Inequality test. | |
| self_t & | operator*= (const self_t &vv) |
| Element-wise multiplication and assignment. | |
| self_t & | operator*= (T s) |
| Scalar multiplication and assignment. | |
| self_t | operator+ (const self_t &v) const |
| Element-wise addition. | |
| self_t & | operator+= (const self_t &vv) |
| Element-wise addition and assignment. | |
| self_t | operator- () const |
| Negation. | |
| self_t | operator- (const self_t &v) const |
| Element-wise subtraction. | |
| self_t & | operator-= (const self_t &vv) |
| Subtraction and assignment. | |
| self_t & | operator/= (T s) |
| Scalar division and assignment. | |
| bool | operator== (const self_t &vv) const |
| Equality test. | |
| T & | operator[] (index_t idx) |
| Vector element access. | |
| const T & | operator[] (index_t idx) const |
| Vector element access. | |
| T | product () const |
| Multiply all elements together. | |
| self_t | project_on (const self_t &axis) const |
| Orthogonal projection to an axis. | |
| T | real () const |
| The scalar part of this quaternion. | |
| self_t | reflect_about (self_t normal) const |
| Reflection about a normal. | |
| PointType< T, M >::point_t | resized () const |
| Resized copy of a vector. | |
| Quat< T > | rotation_scale (T t) const |
Interpolate this unit quaternion with the null rotation according to the interpolation parameter 0 <= t <= 1. | |
| self_t | round () const |
| Round each element to the nearest integer. | |
| self_t | scale (const self_t &v) const |
| Element-wise multiplication. | |
| self_t | scale (T a) const |
| Scalar multiple. | |
| index_t | size () const |
The number of elements in this vector. Always equal to N. | |
| Quat< T > | slerp (const Quat< T > &q1, T t) const |
| Spherical linear interpolation, per Ken Shoemake. Interpolate smoothly between two quaternion orientation states. | |
| self_t | sub (const self_t &v) const |
| Vector subtraction. | |
| T | sum () const |
| Sum the elements of the vector. | |
| Vec< T, 3 > | to_angular_velocity () const |
| Convert this unit quaternion to an angular velocity representation, with the magnitude of the axis representing the rate of rotation in radians. | |
| Vec< T, 4 > | to_axis_angle_rotation () const |
Convert this unit quaternion to an axis-angle rotation representation (x, y, z, radians). | |
| self_t | unit () const |
| Vector normalization. | |
| self_t | with_length (T mag) const |
Compute a vector with the direction of this and a new magnitude mag. | |
Static Public Member Functions | |
| static Quat< T > | identity () |
| static Quat< T > | rotation_direction_align (const Vec< T, 3 > &unit_v, const Vec< T, 3 > &unit_align_with) |
| Rotation to align one vector with another. | |
| static Quat< T > | rotation_from_axis_angle (const Vec< T, 3 > &axis, T radians) |
| Rotation quaternion from an axis and angle. | |
Static Public Attributes | |
| static constexpr index_t | N |
| The dimension of this object. | |
| static const self_t | ones |
| static const self_t | unit_x |
| static const self_t | zeros |
Protected Attributes | |
| T | v [N] |
Friends | |
| Vec< T, 3 > | operator* (const Quat< T > &q, const Vec< T, 3 > &v) |
| Quaternion conjugation, ‘q * v * q’`. | |
| Quat< T > | operator* (const Quat< T > &q1, const Quat< T > &q2) |
| Quaternion multiplication. | |
| Vec< T, 3 > | operator* (const Vec< T, 3 > &v, const Quat< T > &q) |
| Quaternion inverse conjugation, q' * v * q. | |
Quaternion class.
(x, y, z) is the vector part, while w is the real part. This class differs slightly from convention in that the real part is the last coordinate rather than the first; this scheme was chosen to maintain naming consistency with the rest of the library.
|
inherited |
The type of a point in this object's space.
An N-vector of T if N > 1, otherwise a T.
|
inline |
Construct a quaternion from a brace-initialization list. (c++11)
Example: Quat<float> q = {0, 0, 0, 1};
| items | A brace-initializer list. |
|
inlineinherited |
Element-wise absolute value.
x such that x[i] = abs(this[i]). Vector addition.
| v | Another vector. |
x such that x[i] = this[i] + v[i].
|
inlineinherited |
Angle between vectors.
| v | Another vector. |
this and v, between 0 and pi.
|
inlineinherited |
|
inlineinherited |
Elastic collision.
Treat this as a velocity vector or incident ray; this function returns the velocity reflected off of a surface with normal normal. Convenience for -reflect_about(normal).
| normal | Normal of surface to "bounce" on. |
|
inlineinherited |
Element-wise ceiling function.
x such that x[i] = ceil(this[i]). Element-wise clamp.
| lo | Element-wise lower extremes. |
| hi | Element-wise upper extremes. |
x[i] is clamped between lo[i] and hi[i].
|
inlineinherited |
Distance between points.
| pt | Another point. |
this and pt.
|
inlineinherited |
Distance squared to a point.
| pt | Another point. |
this and pt.
|
inlineinherited |
Dot product.
| v | Another vector. |
this with v.
|
inlineinherited |
|
inlineinherited |
|
inline |
Quaternion exponential eq.
q.imag() by angle 2 * |q| and a scaling by eq.real().
|
inlineinherited |
Element-wise floor function.
x such that x[i] = floor(this[i]).
|
inlineinherited |
Return the component of this that projects to axis, as a fraction of axis's length.
| axis | An arbitrary basis vector. |
|
inlineinherited |
Get the element at index idx.
| idx | Index of element. |
idx.
|
inlineinherited |
Get the element at index idx.
| idx | Index of element. |
idx.
|
inlineinherited |
Euclidean norm (magnitude).
|
inlineinherited |
Squared magnitude.
|
inlineinherited |
Maximum element.
Element-wise maximum of two Vecs.
| v | Another vector. |
x such that x[i] = max(this[i], v[i]).
|
inlineinherited |
Minimum element.
Element-wise minimum of two Vecs.
| v | Another vector. |
x such that x[i] = min(this[i], v[i]). Linear interpolation.
A mix parameter of 0 evaluates to this, while 1 is v.
| v | Another vector. |
| mix | A mixing factor between 0 and 1. |
this with v. Element typecast.
U.
|
inlineinherited |
Inequality test.
true if any corresponding elements of this and vv are unequal, false otherwise.
|
inlineinherited |
Negation.
|
inlineinherited |
Equality test.
true if all corresponding elements of this and vv are equal, false otherwise.
|
inlineinherited |
Vector element access.
| idx | Index of element to retrieve. |
idx.
|
inlineinherited |
Vector element access.
| idx | Index of element to retrieve. |
idx. Orthogonal projection to an axis.
| axis | A direction vector. |
axis with magnitude equal to the component of this aligned with axis. Reflection about a normal.
| normal | Axis of reflection. |
Resized copy of a vector.
| M | Dimension of new vector. |
M. If M is larger than N, the new elements will be set to zero. If M is 1, then the return type is T.
|
inlinestatic |
Rotation to align one vector with another.
| v | Unit vector to align. |
| alignWith | Unit direction to align with. |
v into alignment with alignWith.
|
inlinestatic |
Rotation quaternion from an axis and angle.
| axis | Axis of rotation (not necessesarily a unit vector) |
| angle | Angle of rotation in radians |
angle radians about axis. Element-wise multiplication.
| v | Another vector. |
x such that x[i] = this[i] * v[i].
|
inlineinherited |
Scalar multiple.
| a | A constant scale factor. |
x such that x[i] = this[i] * a. Spherical linear interpolation, per Ken Shoemake. Interpolate smoothly between two quaternion orientation states.
| q1 | The rotation at t = 1. |
| t | Interpolation parameter between 0 and 1. |
Vector subtraction.
| v | Another vector. |
x such that x[i] = this[i] - v[i].
|
inlineinherited |
Vector normalization.
|
inlineinherited |
Compute a vector with the direction of this and a new magnitude mag.
If this is the zero vector, it will remain unchanged.
Quaternion conjugation, ‘q * v * q’`.
If q is a unit quaternion, then q * v is a rotation of v by q.
Quaternion inverse conjugation, q' * v * q.
If q is a unit quaternion, then v * q is a rotation of v by q-1.