2#include <NDEVR/Vector.h>
3#include <NDEVR/Angle.h>
4#include <NDEVR/Matrix.h>
12 template<
class t_angle_type,
class t_axis_type>
21 template<
class t_type>
26 :
Vector<4, t_type>(t_type(1), t_type(0), t_type(0), t_type(0))
31 constexpr Quaternion(t_type x, t_type y, t_type z, t_type w)
32 :
Vector<4, t_type>(x, y, z, w)
35 :
Vector<4, t_type>(x, x, x, x)
37 template<
class t_angle_type,
class t_axis_type>
43 for (
uint01 i = 0; i < 3; i++)
47 template<
class t_angle_type>
69 template<
class t_angle_type>
85 template<
class t_angle_type>
112 for (
uint01 i = 0; i < 3; i++)
119 return q /
dot((*
this), (*
this));
123 return Quaternion((*
this)[
X] / s, (*
this)[
Y] / s, (*
this)[
Z] / s, (*
this)[
W] / s);
144 template<
class t_vec_type>
165 result[0] = ww * v[0] + 2 * wy * v[2] - 2 * wz * v[1] +
166 xx * v[0] + 2 * xy * v[1] + 2 * xz * v[2] -
167 zz * v[0] - yy * v[0];
168 result[1] = 2 * xy * v[0] + yy * v[1] + 2 * yz * v[2] +
169 2 * wz * v[0] - zz * v[1] + ww * v[1] -
170 2 * wx * v[2] - xx * v[1];
171 result[2] = 2 * xz * v[0] + 2 * yz * v[1] + zz * v[2] -
172 2 * wy * v[0] - yy * v[2] + 2 * wx * v[1] -
173 xx * v[2] + ww * v[2];
217 t_type x2 = (*this)[
X] + (*this)[
X];
218 t_type y2 = (*this)[
Y] + (*this)[
Y];
219 t_type z2 = (*this)[
Z] + (*this)[
Z];
220 t_type xx2 = (*this)[
X] * x2;
221 t_type xy2 = (*this)[
X] * y2;
222 t_type xz2 = (*this)[
X] * z2;
223 t_type yy2 = (*this)[
Y] * y2;
224 t_type yz2 = (*this)[
Y] * z2;
225 t_type zz2 = (*this)[
Z] * z2;
226 t_type sx2 = (*this)[
W] * x2;
227 t_type sy2 = (*this)[
W] * y2;
228 t_type sz2 = (*this)[
W] * z2;
232 1 - (yy2 + zz2), xy2 + sz2, xz2 - sy2, 0,
233 xy2 - sz2, 1 - (xx2 + zz2), yz2 + sx2, 0,
234 xz2 + sy2, yz2 - sx2, 1 - (xx2 + yy2), 0,
238 static Quaternion<fltp08> difference(
const Quaternion<fltp08>& q1,
const Quaternion<fltp08>& q2)
242 static Quaternion<fltp04> difference(
const Quaternion<fltp04>& q1,
const Quaternion<fltp04>& q2)
255 template<
class t_type>
256 struct Constant<Quaternion<t_type>>
259 constexpr const static Quaternion<t_type>
Min{ 0 };
280 template<
class t_type>
281 static constexpr bool IsInvalid(
const Quaternion<t_type>& value)
283 for (
uint01 dim = 0; dim < 4; ++dim)
The primary angle storage class for this API. Stores an angle in an optimized format.
Definition StringStream.h:540
static Angle asin(t_value_type value)
Computes the principal value of the arc sine of the given value.
Definition Angle.h:305
static Angle atan2(t_value_type x, t_value_type y)
measures the counterclockwise angle between the positive x-axis and the point (x, y)
Definition Angle.h:328
static Angle acos(t_value_type value)
Computes the principal value of the arc cosine of the given value.
Definition Angle.h:294
Definition Matrix.hpp:176
https://www.3dgep.com/understanding-quaternions/
Definition Quaternion.hpp:23
constexpr Quaternion()
Definition Quaternion.hpp:25
Vector< 3, Angle< t_angle_type > > euler() const
Definition Quaternion.hpp:86
AxisAngle< t_angle_type, t_type > axisAngle() const
Definition Quaternion.hpp:48
Quaternion operator*(const Quaternion &q2) const
Definition Quaternion.hpp:125
constexpr Quaternion(const Vector< 4, t_type > &vec)
Definition Quaternion.hpp:28
Quaternion conjugate() const
Definition Quaternion.hpp:108
void setFromEuler(Vector< 3, Angle< t_angle_type > > euler)
Definition Quaternion.hpp:70
constexpr Quaternion(Angle< t_angle_type > angle, Vector< 3, t_axis_type > axis)
Definition Quaternion.hpp:38
const Quaternion operator/(t_type s) const
Definition Quaternion.hpp:121
Matrix< t_type > toMatrix() const
Definition Quaternion.hpp:213
constexpr Quaternion(t_type x, t_type y, t_type z, t_type w)
Definition Quaternion.hpp:31
Vector< 3, t_vec_type > operator*(const Vector< 3, t_vec_type > &v) const
Definition Quaternion.hpp:145
constexpr Quaternion(t_type x)
Definition Quaternion.hpp:34
Quaternion invert() const
Definition Quaternion.hpp:116
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
constexpr Vector< t_dims, t_new_type > as() const
Definition Vector.hpp:300
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
t_type dot(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
Definition VectorFunctions.hpp:1030
@ ROLL
Definition Angle.h:45
@ YAW
Definition Angle.h:47
@ PITCH
Definition Angle.h:46
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
@ DEGREES
Definition Angle.h:58
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type cos(const Angle< t_type > &angle)
Performs optimized cosine operation on the given angle using pre-computed lookup table for optimal sp...
Definition AngleFunctions.h:124
t_type sqrt(const t_type &value)
Definition VectorFunctions.hpp:1225
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Changes an input with a negative sign, to a positive sign.
Definition AngleFunctions.h:645
std::enable_if<!ObjectInfo< t_type >::Float, fltp08 >::type sin(const Angle< t_type > &angle)
Performs optimized sine operation on the given angle using pre-computed lookup table for optimal spee...
Definition AngleFunctions.h:79
@ Y
Definition BaseValues.hpp:169
@ X
Definition BaseValues.hpp:167
@ Z
Definition BaseValues.hpp:171
@ W
Definition BaseValues.hpp:173
An angle about a particular, defined 3D axis.
Definition Quaternion.hpp:14
Vector< 3, t_axis_type > axis
Definition Quaternion.hpp:16
Angle< t_angle_type > angle
Definition Quaternion.hpp:15
static const t_type Invalid
Definition BaseValues.hpp:234
static const t_type Min
Definition BaseValues.hpp:235
static const t_type Max
Definition BaseValues.hpp:236