5 #include <gtest/gtest.h> 15 f = Eigen::IOFormat(Eigen::FullPrecision);
29 EXPECT_TRUE(q1.isApprox(q2, 1.e-12));
38 EXPECT_TRUE(q3.isApprox(q4, 1.e-12));
44 Eigen::Quaterniond q_eig(1., 2., 3., 4.);
68 EXPECT_TRUE(aa1.axis().isApprox(aa2.axis()));
84 EXPECT_EQ(1.1, q1.
x());
85 EXPECT_EQ(2.1, q1.
y());
86 EXPECT_EQ(3.1, q1.
z());
87 EXPECT_EQ(4.1, q1.
w());
90 EXPECT_EQ(q1.
w(), 4.1);
151 double thx = M_PI / 4.;
152 double thy = M_PI / 3.;
153 double thz = -M_PI / 6.;
156 qz(0., 0., std::sin(thz / 2.), std::cos(thz / 2.));
161 EXPECT_TRUE(q.isApprox(q_swing * q_twist, 1.e-10));
164 EXPECT_TRUE(q.isApprox(q_swing * q_twist, 1.e-10));
167 EXPECT_TRUE(q.isApprox(q_swing * q_twist, 1.e-10));
172 EXPECT_TRUE(q.isApprox(q_swing * q_twist, 1.e-10));
174 q.swingTwistDecomposition(
Vector3d(0., 1., 0.), q_swing, q_twist);
175 EXPECT_TRUE(q.isApprox(q_swing * q_twist, 1.e-10));
177 q.swingTwistDecomposition(
Vector3d(1., 0., 0.), q_swing, q_twist);
178 EXPECT_TRUE(q.isApprox(q_swing * q_twist, 1.e-10));
188 EXPECT_TRUE(q.isApprox(q_swing * q_twist, 1.e-10));
190 q.
set(0., 0., 0., -1);
193 EXPECT_TRUE(q.isApprox(q_swing * q_twist, 1.e-10));
195 q.
set(0., 0., 0., -1);
198 EXPECT_TRUE(q.isApprox(q_swing * q_twist, 1.e-10));
201 int main(
int argc,
char** argv)
203 ::testing::InitGoogleTest(&argc, argv);
204 return RUN_ALL_TESTS();
EIGEN_STRONG_INLINE double & w()
int main(int argc, char **argv)
void swingTwistDecomposition(const Vector3d &twist_axis, Quaternion &swing, Quaternion &twist)
Decompose a quaternion into a swing then twist quaternion where the twist is about the given axis...
EIGEN_STRONG_INLINE Vector3d vec() const
Get vector part.
static bool checkVector4dEpsilonClose(const RobotDynamics::Math::Vector4d &v1, const RobotDynamics::Math::Vector4d &v2, const double epsilon)
EIGEN_STRONG_INLINE double & y()
void sanitize()
sanitize the quaternion by negating each element if the w element is less than zero ...
Quaternion that are used for singularity free joints.
TEST_F(QuaternionFixture, Sanitize)
EIGEN_STRONG_INLINE double & x()
static bool checkVector3dEpsilonClose(const RobotDynamics::Math::Vector3d &v1, const RobotDynamics::Math::Vector3d &v2, const double epsilon)
Quaternion slerp(double alpha, const Quaternion &quat) const
From Wikipedia: In computer graphics, Slerp is shorthand for spherical linear interpolation, introduced by Ken Shoemake in the context of quaternion interpolation for the purpose of animating 3D rotation. It refers to constant-speed motion along a unit-radius great circle arc, given the ends and an interpolation parameter between 0 and 1.
EIGEN_STRONG_INLINE double & z()
Quaternion conjugate() const
void set(double x, double y, double z, double w)
Eigen::AngleAxisd AxisAngle
SpatialTransform Xrot(double angle_rad, const Vector3d &axis)
Get spatial transform from angle and axis.
static AxisAngle toAxisAngle(Quaternion q)
Get axis angle representation of a quaternion.