mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-16 14:57:35 +08:00
matrix scalar pre multiplication and general scalar multiplication for
quaternions
This commit is contained in:
@@ -417,6 +417,12 @@ Matrix<Type, M, N> ones() {
|
||||
return m;
|
||||
}
|
||||
|
||||
template<typename Type, size_t M, size_t N>
|
||||
Matrix<Type, M, N> operator*(Type scalar, const Matrix<Type, M, N> &other)
|
||||
{
|
||||
return other * scalar;
|
||||
}
|
||||
|
||||
#if defined(SUPPORT_STDIOSTREAM)
|
||||
template<typename Type, size_t M, size_t N>
|
||||
std::ostream& operator<<(std::ostream& os,
|
||||
|
||||
@@ -104,6 +104,18 @@ public:
|
||||
self = self * other;
|
||||
}
|
||||
|
||||
Quaternion operator*(Type scalar) const
|
||||
{
|
||||
const Quaternion &q = *this;
|
||||
return scalar * q;
|
||||
}
|
||||
|
||||
void operator*=(Type scalar)
|
||||
{
|
||||
Quaternion &q = *this;
|
||||
q = q * scalar;
|
||||
}
|
||||
|
||||
Matrix41 derivative(const Matrix31 & w) const {
|
||||
const Quaternion &q = *this;
|
||||
Type dataQ[] = {
|
||||
|
||||
@@ -133,6 +133,19 @@ int main()
|
||||
q_check *= q_check;
|
||||
assert(q_prod_check == q_check);
|
||||
|
||||
// Quaternion scalar multiplication
|
||||
float scalar = 0.5;
|
||||
Quatf q_scalar_mul(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
Quatf q_scalar_mul_check(1.0f * scalar, 2.0f * scalar,
|
||||
3.0f * scalar, 4.0f * scalar);
|
||||
Quatf q_scalar_mul_res = scalar * q_scalar_mul;
|
||||
assert(q_scalar_mul_check == q_scalar_mul_res);
|
||||
Quatf q_scalar_mul_res2 = q_scalar_mul * scalar;
|
||||
assert(q_scalar_mul_check == q_scalar_mul_res2);
|
||||
Quatf q_scalar_mul_res3(q_scalar_mul);
|
||||
q_scalar_mul_res3 *= scalar;
|
||||
assert(q_scalar_mul_check == q_scalar_mul_res3);
|
||||
|
||||
};
|
||||
|
||||
/* vim: set et fenc=utf-8 ff=unix sts=0 sw=4 ts=4 : */
|
||||
|
||||
Reference in New Issue
Block a user