rtm/quatd.h¶
#include "rtm/quatd.h"
quat_set¶
quatd quat_set(double x, double y, double z, double w)
Creates a quaternion from all 4 components.
quat_identity¶
quatd quat_identity()
Returns the identity quaternion.
The return value also converts to quatf.
Setters, getters, and casts¶
quat_load¶
quatd quat_load(const double* input)
Loads an unaligned quaternion from memory.
quatd quat_load(const float4d* input)
Loads an unaligned quat from memory.
vector_to_quat¶
quatd vector_to_quat(vector4d input)
Casts a vector4 to a quaternion.
quat_cast¶
quatd quat_cast(quatf input)
Casts a quaternion float32 variant to a float64 variant.
quat_get_x¶
double quat_get_x(quatd input)
Returns the quaternion [x] component (real part).
quat_get_x_as_scalar¶
scalard quat_get_x_as_scalar(quatd input)
Returns the quaternion [x] component (real part).
quat_get_y¶
double quat_get_y(quatd input)
Returns the quaternion [y] component (real part).
quat_get_y_as_scalar¶
scalard quat_get_y_as_scalar(quatd input)
Returns the quaternion [y] component (real part).
quat_get_z¶
double quat_get_z(quatd input)
Returns the quaternion [z] component (real part).
quat_get_z_as_scalar¶
scalard quat_get_z_as_scalar(quatd input)
Returns the quaternion [z] component (real part).
quat_get_w¶
double quat_get_w(quatd input)
Returns the quaternion [w] component (imaginary part).
quat_get_w_as_scalar¶
scalard quat_get_w_as_scalar(quatd input)
Returns the quaternion [w] component (imaginary part).
quat_set_x¶
quatd quat_set_x(quatd input, double lane_value)
Sets the quaternion [x] component (real part) and returns the new value.
quat_set_y¶
quatd quat_set_y(quatd input, double lane_value)
Sets the quaternion [y] component (real part) and returns the new value.
quat_set_z¶
quatd quat_set_z(quatd input, double lane_value)
Sets the quaternion [z] component (real part) and returns the new value.
quat_set_w¶
quatd quat_set_w(quatd input, double lane_value)
Sets the quaternion [w] component (imaginary part) and returns the new value.
quat_store¶
void quat_store(quatd input, double* output)
void quat_store(quatd input, float4d* output)
Writes a quaternion to unaligned memory.
Arithmetic¶
quat_conjugate¶
quatd quat_conjugate(quatd input)
Returns the quaternion conjugate.
quat_add¶
quatd quat_add(quatd lhs, quatd rhs)
Adds two quaternions.
quat_mul¶
quatd quat_mul(quatd lhs, quatd rhs)
Multiplies two quaternions. Note that due to floating point rounding, the result might not be perfectly normalized. Multiplication order is as follow: local_to_world = quat_mul(local_to_object, object_to_world)
quatd quat_mul(quatd quat, double scalar)
Multiplies a quaternion with a scalar.
quat_mul_vector3¶
vector4d quat_mul_vector3(vector4d vector, quatd rotation)
Multiplies a quaternion and a 3D vector, rotating it. Multiplication order is as follow: world_position = quat_mul_vector3(local_vector, local_to_world)
quat_dot¶
double quat_dot(quatd lhs, quatd rhs)
Quaternion dot product: lhs . rhs.
quat_dot_as_scalar¶
scalard quat_dot_as_scalar(quatd lhs, quatd rhs)
Quaternion dot product: lhs . rhs.
quat_length_squared¶
double quat_length_squared(quatd input)
Returns the squared length/norm of the quaternion.
quat_length_squared_as_scalar¶
scalard quat_length_squared_as_scalar(quatd input)
Returns the squared length/norm of the quaternion.
quat_length¶
double quat_length(quatd input)
Returns the length/norm of the quaternion.
quat_length_as_scalar¶
scalard quat_length_as_scalar(quatd input)
Returns the length/norm of the quaternion.
quat_length_reciprocal¶
double quat_length_reciprocal(quatd input)
Returns the reciprocal length/norm of the quaternion.
quat_length_reciprocal_as_scalar¶
scalard quat_length_reciprocal_as_scalar(quatd input)
Returns the reciprocal length/norm of the quaternion.
quat_normalize¶
quatd quat_normalize(quatd input)
Returns a normalized quaternion. Note that if the input quaternion is invalid (pure zero or with NaN/Inf), the result is undefined.
quat_normalize_deterministic¶
quatd quat_normalize_deterministic(quatd input)
Returns a normalized quaternion using a deterministic algorithm. This ensures that for a given input, the output will be identical on all platforms that implement IEEE-754. This can be slower than quat_normalize. Note that if the input quaternion is invalid (pure zero or with NaN/Inf), the result is undefined.
quat_lerp¶
quatd quat_lerp(quatd start, quatd end, double alpha)
Returns the linear interpolation between start and end for a given alpha value. The formula used is: ((1.0 - alpha) * start) + (alpha * end). Interpolation is stable and will return 'start' when 'alpha' is 0.0 and 'end' when it is 1.0. This is the same instruction count when FMA is present but it might be slightly slower due to the extra multiplication compared to: start + (alpha * (end - start)). Note that if 'start' and 'end' are on the opposite ends of the hypersphere, 'end' is negated before we interpolate. As such, when 'alpha' is 1.0, either 'end' or its negated equivalent is returned. Furthermore, if 'start' and 'end' aren't exactly normalized, the result might not match exactly when 'alpha' is 0.0 or 1.0 because we normalize the resulting quaternion.
quat_slerp¶
quatd quat_slerp(quatd start, quatd end, double alpha)
Returns the spherical interpolation between start and end for a given alpha value. If the angle between the two inputs is near zero, the function uses the weights (1.0 - alpha) and alpha. See: https://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/index.htm Perhaps try this someday: http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/
quat_neg¶
quatd quat_neg(quatd input)
Returns a component wise negated quaternion.
quat_rotation_log¶
quatd quat_rotation_log(quatd input)
Returns the quaternion logarithm for a 3D rotation.
quat_rotation_exp¶
quatd quat_rotation_exp(quatd input)
Returns the quaternion exponential for a 3D rotation. The result might not be fully normalized if the input is near zero.
Conversion to/from axis/angle/euler¶
quat_to_axis_angle¶
void quat_to_axis_angle(quatd input, vector4d& out_axis, double& out_angle)
Returns the rotation axis and rotation angle that make up the input quaternion.
quat_get_axis¶
vector4d quat_get_axis(quatd input)
Returns the rotation axis part of the input quaternion.
quat_get_angle¶
double quat_get_angle(quatd input)
Returns the rotation angle part of the input quaternion.
quat_from_axis_angle¶
quatd quat_from_axis_angle(vector4d axis, double angle)
Creates a quaternion from a rotation axis and a rotation angle.
quat_from_euler¶
quatd quat_from_euler(double pitch, double yaw, double roll)
Creates a quaternion from Euler Pitch/Yaw/Roll angles. Pitch is around the Y axis (right) Yaw is around the Z axis (up) Roll is around the X axis (forward)
Comparisons and masking¶
quat_is_finite¶
bool quat_is_finite(quatd input)
Returns true if the input quaternion does not contain any NaN or Inf, otherwise false.
quat_is_normalized¶
bool quat_is_normalized(quatd input, double threshold=0.00001)
Returns true if the input quaternion is normalized, otherwise false.
quat_are_equal¶
bool quat_are_equal(quatd lhs, quatd rhs)
Returns true if the two quaternions are equal component wise, otherwise false.
quat_near_equal¶
bool quat_near_equal(quatd lhs, quatd rhs, double threshold=0.00001)
Returns true if the two quaternions are nearly equal component wise, otherwise false.
quat_near_identity¶
bool quat_near_identity(quatd input, double threshold_angle=2.82729655E-7)
Returns true if the input quaternion is nearly equal to the identity quaternion by comparing its rotation angle.
quat_select¶
quatd quat_select(mask4d mask, quatd if_true, quatd if_false)
Per component selection depending on the mask: mask != 0 ? if_true : if_false Note that if the mask lanes are not all identical, the resulting quaternion may not be normalized.