27 #ifndef RL_MATH_QUATERNIONBASEADDONS_H
28 #define RL_MATH_QUATERNIONBASEADDONS_H
30 template<
typename OtherDerived>
34 return ((qd * this->derived().conjugate()) * Scalar(2)).vec();
37 template<
typename OtherDerived1,
typename OtherDerived2>
39 angularAcceleration(
const QuaternionBase<OtherDerived1>& qd,
const QuaternionBase<OtherDerived2>& qdd)
const
41 return ((qdd * this->derived().conjugate() + qd * qd.conjugate()) * Scalar(2)).vec();
47 Scalar theta = this->derived().vec().norm();
48 Scalar sinTheta = ::sin(theta);
49 Scalar cosTheta = ::cos(theta);
53 if (theta > Scalar(0))
55 q.vec() = sinTheta * this->derived().vec() / theta;
70 return (Quaternion<Scalar>(Scalar(0), omega.x(), omega.y(), omega.z()) * this->derived()) * Scalar(0.5);
73 template<
typename OtherDerived>
74 Quaternion<Scalar>
lerp(
const Scalar& t,
const QuaternionBase<OtherDerived>& other)
const
76 return Quaternion<Scalar>((Scalar(1) - t) * coeffs() + t * other.coeffs());
82 Scalar theta = ::acos(this->derived().w());
83 Scalar sinTheta = ::sin(theta);
87 if (sinTheta > Scalar(0))
89 q.vec() = theta * this->derived().vec() / sinTheta;
101 template<
typename OtherDerived>
103 operator+(
const QuaternionBase<OtherDerived>& other)
const
105 return Quaternion<Scalar>(this->derived().coeffs() + other.coeffs());
108 template<
typename OtherDerived>
110 operator-(
const QuaternionBase<OtherDerived>& other)
const
112 return Quaternion<Scalar>(this->derived().coeffs() - other.coeffs());
118 return Quaternion<Scalar>(this->derived().coeffs() * scalar);
124 return Quaternion<Scalar>(this->derived().coeffs() / scalar);
128 pow(
const Scalar& t)
const
130 return (this->derived().
log() * Scalar(t)).exp();
133 template<
typename OtherDerived>
137 return (Quaternion<Scalar>(Scalar(0), omegad.x(), omegad.y(), omegad.z()) * this->derived() + Quaternion<Scalar>(Scalar(0), omega.x(), omega.y(), omega.z()) * qd) * Scalar(0.5);
149 template<
typename OtherDerived>
153 eigen_assert(rand(0) >= Scalar(0));
154 eigen_assert(rand(0) <= Scalar(1));
155 eigen_assert(rand(1) >= Scalar(0));
156 eigen_assert(rand(1) <= Scalar(1));
157 eigen_assert(rand(2) >= Scalar(0));
158 eigen_assert(rand(2) <= Scalar(1));
160 Quaternion<Scalar> tmp;
161 tmp.w() = rand.norm();
162 tmp.vec() = sigma.cwiseProduct(rand);
164 this->derived() = mean * tmp.exp();
179 eigen_assert(rand(0) >= Scalar(0));
180 eigen_assert(rand(0) <= Scalar(1));
181 eigen_assert(rand(1) >= Scalar(0));
182 eigen_assert(rand(1) <= Scalar(1));
183 eigen_assert(rand(2) >= Scalar(0));
184 eigen_assert(rand(2) <= Scalar(1));
186 Scalar sigma1 = ::std::sqrt(Scalar(1) - rand(0));
187 Scalar sigma2 = ::std::sqrt(rand(0));
188 Scalar theta1 = Scalar(2) *
static_cast<Scalar
>(M_PI) * rand(1);
189 Scalar theta2 = Scalar(2) *
static_cast<Scalar
>(M_PI) * rand(2);
191 this->derived().w() = ::std::cos(theta2) * sigma2;
192 this->derived().x() = ::std::sin(theta1) * sigma1;
193 this->derived().y() = ::std::cos(theta1) * sigma1;
194 this->derived().z() = ::std::sin(theta2) * sigma2;
197 template<
typename OtherDerived>
201 Quaternion<Scalar> tmp = this->derived().conjugate() * other;
202 return this->derived() * tmp.pow(t) * tmp.log();
205 template<
typename OtherDerived1,
typename OtherDerived2,
typename OtherDerived3>
207 squad(
const Scalar& t,
const QuaternionBase<OtherDerived1>& a,
const QuaternionBase<OtherDerived2>& b,
const QuaternionBase<OtherDerived3>& other)
const
209 return this->derived().slerp(t, other).slerp(Scalar(2) * t * (Scalar(1) - t), a.slerp(t, b));
212 template<
typename OtherDerived1,
typename OtherDerived2>
214 squadControlPoint(
const QuaternionBase<OtherDerived1>& previous,
const QuaternionBase<OtherDerived2>& next)
const
216 return this->derived() * (((this->derived().conjugate() * previous).
log() + (this->derived().conjugate() * next).
log()) / Scalar(-4)).
exp();
219 template<
typename OtherDerived1,
typename OtherDerived2,
typename OtherDerived3>
221 squadFirstDerivative(
const Scalar& t,
const QuaternionBase<OtherDerived1>& a,
const QuaternionBase<OtherDerived2>& b,
const QuaternionBase<OtherDerived3>& other)
const
223 Quaternion<Scalar> u = this->derived().slerp(t, other);
224 Quaternion<Scalar> v = a.slerp(t, b);
225 Quaternion<Scalar> w = u.inverse() * v;
226 Quaternion<Scalar> ud = u * (this->derived().conjugate() * other).
log();
227 Quaternion<Scalar> vd = v * (a.conjugate() * b).
log();
228 Quaternion<Scalar> wd = u.conjugate() * vd - u.pow(Scalar(-2)) * ud * v;
229 Scalar tmp = Scalar(2) * t * (Scalar(1) - t);
230 return u * (w.pow(tmp) * (Scalar(2) - Scalar(4) * t) * w.log() + w.pow(tmp - Scalar(1)) * tmp * wd) + ud * w.pow(tmp);
233 #endif // RL_MATH_QUATERNIONBASEADDONS_H