DirectZ
|
A quaternion class for representing rotations in 3D space. More...
#include <math.hpp>
Public Types | |
using | Base = vec<T, 4> |
Public Member Functions | |
quat ()=default | |
Default constructor. Components are uninitialized. | |
quat (const quat &)=default | |
Copy constructor. | |
quat & | operator= (const quat &)=default |
Copy assignment operator. | |
quat (quat &&) noexcept=default | |
Move constructor. | |
quat & | operator= (quat &&) noexcept=default |
Move assignment operator. | |
template<typename... Args> | |
quat (Args &&... args) | |
Variadic constructor forwarding to vec<T, 4>. | |
quat (T w, T x, T y, T z) | |
Construct quaternion from explicit components. | |
quat< T > | conjugate () const |
Returns the conjugate of the quaternion. | |
quat< T > | inverse () const |
Returns the inverse of the quaternion. | |
vec< T, 3 > | rotate (const vec< T, 3 > &v) const |
Rotates a 3D vector using this quaternion. | |
quat< T > | operator* (const quat< T > &rhs) const |
Quaternion multiplication. | |
void | to_axis_angle (vec< T, 3 > &out_axis, T &out_angle) const |
Converts the quaternion to axis-angle representation. | |
mat< T, 4, 4 > | to_mat4 () const |
Converts the quaternion to a 4x4 rotation matrix. | |
vec & | operator= (const vec &other) |
Assignment operator for component-wise copy. | |
vec & | operator+= (const O &other) |
Compound addition-assignment operator. | |
vec & | operator-= (const O &other) |
Compound subtraction-assignment operator. | |
vec & | operator*= (const O &other) |
Compound multiplication-assignment operator. | |
vec & | operator/= (const O &other) |
Compound division-assignment operator. | |
vec | operator+ (const O &other) const |
Addition operator returning a new vector. | |
vec | operator- (const O &other) const |
Subtraction operator returning a new vector. | |
vec | operator- () const |
Unary negation operator. | |
vec | operator* (const O &other) const |
Multiplication operator returning a new vector. | |
vec | operator/ (const O &other) const |
Division operator returning a new vector. | |
T & | operator[] (size_t i) |
Index operator for non-const access to vector components. | |
const T & | operator[] (size_t i) const |
Index operator for const access to vector components. | |
T | length () const |
Computes the Euclidean length (magnitude) of the vector. | |
vec | normalize () const |
Returns a normalized (unit length) copy of the vector. | |
Public Member Functions inherited from dz::vec< T, 4 > | |
vec (Args... args) | |
Variadic constructor to initialize vector components. | |
vec (const vec< OT, ON > &other) | |
Copy constructor to convert from vectors of different types and/or sizes. | |
vec & | operator= (const vec &other) |
Assignment operator for component-wise copy. | |
T & | operator[] (size_t i) |
Index operator for non-const access to vector components. | |
const T & | operator[] (size_t i) const |
Index operator for const access to vector components. | |
vec & | operator*= (const O &other) |
Compound multiplication-assignment operator. | |
vec & | operator/= (const O &other) |
Compound division-assignment operator. | |
vec & | operator+= (const O &other) |
Compound addition-assignment operator. | |
vec & | operator-= (const O &other) |
Compound subtraction-assignment operator. | |
vec | operator* (const O &other) const |
Multiplication operator returning a new vector. | |
vec | operator/ (const O &other) const |
Division operator returning a new vector. | |
vec | operator+ (const O &other) const |
Addition operator returning a new vector. | |
vec | operator- (const O &other) const |
Subtraction operator returning a new vector. | |
vec | operator- () const |
Unary negation operator. | |
T | length () const |
Computes the Euclidean length (magnitude) of the vector. | |
vec | normalize () const |
Returns a normalized (unit length) copy of the vector. |
Static Public Member Functions | |
static quat< T > | from_axis_angle (const vec< T, 3 > &axis, T angle) |
Constructs a quaternion from an axis-angle representation. |
Public Attributes | |
T | data [N] |
Underlying array storing vector components. | |
Public Attributes inherited from dz::vec< T, 4 > | |
T | data [N] |
Underlying array storing vector components. |
A quaternion class for representing rotations in 3D space.
This struct inherits from vec<T, 4> and represents a quaternion with four components: w, x, y, z. It provides operations including construction, conjugation, inversion, quaternion multiplication, and rotation of a 3D vector.
T | Underlying scalar type (e.g., float, double). |
Default constructor. Components are uninitialized.
Copy constructor.
other | The quaternion to copy. |
Move constructor.
other | The quaternion to move. |
Variadic constructor forwarding to vec<T, 4>.
Args | Variadic template arguments. |
args | Values forwarded to base class constructor. |
Construct quaternion from explicit components.
w | Scalar component. |
x | X vector component. |
y | Y vector component. |
z | Z vector component. |
Returns the conjugate of the quaternion.
The conjugate of (w, x, y, z) is (w, -x, -y, -z).
|
inlinestatic |
Constructs a quaternion from an axis-angle representation.
axis | The normalized axis of rotation. |
angle | The angle of rotation in radians. |
Returns the inverse of the quaternion.
The inverse is the conjugate divided by the squared norm.
Computes the Euclidean length (magnitude) of the vector.
Calculates the square root of the sum of squares of all components.
Returns a normalized (unit length) copy of the vector.
Divides all components by the vector length.
Multiplication operator returning a new vector.
Supports multiplication by a scalar or component-wise multiplication by another vector.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to multiply by. |
Quaternion multiplication.
Multiplies this quaternion by another.
rhs | The right-hand side quaternion. |
Compound multiplication-assignment operator.
Supports multiplication by a scalar or component-wise multiplication by another vector. Throws std::runtime_error if the operand type is unsupported.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to multiply by. |
std::runtime_error | if unsupported operand type is used. |
Addition operator returning a new vector.
Supports addition by a scalar or component-wise addition by another vector.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to add. |
Compound addition-assignment operator.
Supports addition by a scalar or component-wise addition by another vector. Throws std::runtime_error if the operand type is unsupported.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to add. |
std::runtime_error | if unsupported operand type is used. |
Unary negation operator.
Returns a new vector with all components negated.
Subtraction operator returning a new vector.
Supports subtraction by a scalar or component-wise subtraction by another vector.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to subtract. |
Compound subtraction-assignment operator.
Supports subtraction by a scalar or component-wise subtraction by another vector. Throws std::runtime_error if the operand type is unsupported.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to subtract. |
std::runtime_error | if unsupported operand type is used. |
Division operator returning a new vector.
Supports division by a scalar or component-wise division by another vector.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to divide by. |
Compound division-assignment operator.
Supports division by a scalar or component-wise division by another vector. Throws std::runtime_error if the operand type is unsupported.
O | Operand type (scalar T or vec<T, N>). |
other | The scalar or vector to divide by. |
std::runtime_error | if unsupported operand type is used. |
Copy assignment operator.
other | The quaternion to assign from. |
Assignment operator for component-wise copy.
Copies all components from the other vector using memcpy for efficiency.
other | The vector to copy from. |
Move assignment operator.
other | The quaternion to move from. |
Index operator for non-const access to vector components.
No bounds checking is performed.
i | The component index to access. |
Index operator for const access to vector components.
No bounds checking is performed.
i | The component index to access. |
Rotates a 3D vector using this quaternion.
v | The 3D vector to rotate. |
|
inline |
Converts the quaternion to axis-angle representation.
out_axis | Normalized axis of rotation (output). |
out_angle | Angle in radians (output). |
Converts the quaternion to a 4x4 rotation matrix.