35 q.
w = std::cos(half.
x) * std::cos(half.
y) * std::cos(half.
z) + std::sin(half.
x) * std::sin(half.
y) * std::sin(half.
z);
36 q.
x = std::sin(half.
x) * std::cos(half.
y) * std::cos(half.
z) - std::cos(half.
x) * std::sin(half.
y) * std::sin(half.
z);
37 q.
y = std::cos(half.
x) * std::sin(half.
y) * std::cos(half.
z) + std::sin(half.
x) * std::cos(half.
y) * std::sin(half.
z);
38 q.
z = std::cos(half.
x) * std::cos(half.
y) * std::sin(half.
z) - std::sin(half.
x) * std::sin(half.
y) * std::cos(half.
z);
50 const T half = angle / 2;
53 q.
x = axis.
x * std::sin(half);
54 q.
y = axis.
y * std::sin(half);
55 q.
z = axis.
z * std::sin(half);
68 const T dot = u1.
dot(u2);
71 if (dot > T(0.999999))
74 if (dot < T(-0.999999)) {
77 if (axis.
x == 0 && axis.
y == 0 && axis.
z == 0)
78 axis = Vector3<T>{0, 1, 0}.
cross(u1);
86 const Vector3<T> axis = u1.
cross(u2);
89 const T
w = std::sqrt((u1Length * u1Length) * (u2Length * u2Length)) + dot;
102 const T magnitude = std::sqrt(
w *
w +
x *
x +
y *
y +
z *
z);
104 if (magnitude == 0) {
105 w = 1;
x = 0;
y = 0;
z = 0;
108 w /= magnitude;
x /= magnitude;
y /= magnitude;
z /= magnitude;
125 const Quaternion p(0, point.
x - center.x, point.
y - center.y, point.
z - center.z);
128 return {q.
x + center.x, q.
y + center.y, q.
z + center.z};
134 w * other.
w -
x * other.
x -
y * other.
y -
z * other.
z,
135 w * other.
x +
x * other.
w +
y * other.
z -
z * other.
y,
136 w * other.
y -
x * other.
z +
y * other.
w +
z * other.
x,
137 w * other.
z +
x * other.
y -
y * other.
x +
z * other.
w
Une rotation dans l'espace, parametree par son scalaire.
Definition Quaternion.hpp:23
void enforceSign()
Choisit la representation a w positif.
Definition Quaternion.hpp:117
double y
Definition Quaternion.hpp:141
Quaternion(T w, T x, T y, T z)
Definition Quaternion.hpp:27
static Quaternion fromEulerAngles(T x, T y, T z)
Definition Quaternion.hpp:31
static Quaternion fromAxisAngle(T angle, Vector3< T > axis)
Une rotation d'un angle autour d'un axe.
Definition Quaternion.hpp:48
static Quaternion identity()
Definition Quaternion.hpp:29
Quaternion conjugate() const
Definition Quaternion.hpp:98
double x
Definition Quaternion.hpp:141
Quaternion operator*(const Quaternion &other) const
Compose deux rotations. L'ordre compte.
Definition Quaternion.hpp:132
double w
Definition Quaternion.hpp:141
void normalize()
Le ramene sur la sphere unite. Un quaternion nul devient l'identite.
Definition Quaternion.hpp:101
static Quaternion fromVectors(const Vector3< T > &v1, const Vector3< T > &v2, const Vector3< T > referenceUp={0, 1, 0})
La rotation qui amene v1 sur v2.
Definition Quaternion.hpp:62
Quaternion()
Definition Quaternion.hpp:26
Vector3< T > rotate(Vector3< T > point, Vector3< T > center={0, 0, 0}) const
Tourne un point autour d'un centre.
Definition Quaternion.hpp:124
double z
Definition Quaternion.hpp:141
Quaternion< double > Quaternionf
Definition Quaternion.hpp:144
Definition Vector3.hpp:20
Vector3 normalized() const
Definition Vector3.hpp:94
T x
Definition Vector3.hpp:21
std::conditional< std::is_floating_point< T >::value, T, double >::type magnitude() const
Definition Vector3.hpp:78
T y
Definition Vector3.hpp:21
Vector3 cross(const Vector3 &other) const
Definition Vector3.hpp:65
T dot(const Vector3 &other) const
Definition Vector3.hpp:62
T z
Definition Vector3.hpp:21