39 #include <visp3/core/vpConfig.h>
41 #if defined(VISP_HAVE_CATCH2)
43 #include <visp3/core/vpQuaternionVector.h>
45 #include <catch_amalgamated.hpp>
47 #ifdef ENABLE_VISP_NAMESPACE
51 TEST_CASE(
"Quaternion interpolation",
"[quaternion]")
63 const double ref_angle_middle = t * (angle0 + angle1);
64 const double margin = 1e-3;
65 const double marginLerp = 1e-1;
73 CHECK(
vpThetaUVector(qLerp).getTheta() == Catch::Approx(ref_angle_middle).margin(marginLerp));
79 CHECK(
vpThetaUVector(qNlerp).getTheta() == Catch::Approx(ref_angle_middle).margin(margin));
85 CHECK(
vpThetaUVector(qSlerp).getTheta() == Catch::Approx(ref_angle_middle).margin(margin));
89 TEST_CASE(
"Quaternion operators",
"[quaternion]")
92 SECTION(
"Addition and subtraction")
97 const double margin = std::numeric_limits<double>::epsilon();
98 std::cout <<
"q3=" << q3 << std::endl;
99 CHECK(q3.
x() == Catch::Approx(2.6).margin(margin));
100 CHECK(q3.
y() == Catch::Approx(0.4).margin(margin));
101 CHECK(q3.
z() == Catch::Approx(-3.0).margin(margin));
102 CHECK(q3.
w() == Catch::Approx(4.0).margin(margin));
107 std::cout <<
"q4=" << q4 << std::endl;
108 CHECK(q4.
x() == Catch::Approx(q2.x()).margin(margin));
109 CHECK(q4.
y() == Catch::Approx(q2.y()).margin(margin));
110 CHECK(q4.
z() == Catch::Approx(q2.z()).margin(margin));
111 CHECK(q4.
w() == Catch::Approx(q2.w()).margin(margin));
114 SECTION(
"Multiplication")
120 const double margin = std::numeric_limits<double>::epsilon() * 1e4;
121 CHECK(q3.
x() == Catch::Approx(3.0).margin(margin));
122 CHECK(q3.
y() == Catch::Approx(36.7).margin(margin));
123 CHECK(q3.
z() == Catch::Approx(-6.6).margin(margin));
124 CHECK(q3.
w() == Catch::Approx(1.3).margin(margin));
131 const double margin = std::numeric_limits<double>::epsilon();
132 CHECK(q1_conj.
x() == Catch::Approx(-q1.x()).margin(margin));
133 CHECK(q1_conj.
y() == Catch::Approx(-q1.y()).margin(margin));
134 CHECK(q1_conj.
z() == Catch::Approx(-q1.z()).margin(margin));
135 CHECK(q1_conj.
w() == Catch::Approx(q1.w()).margin(margin));
142 const double margin = 1e-6;
143 CHECK(q1_inv.
x() == Catch::Approx(-0.00214111).margin(margin));
144 CHECK(q1_inv.
y() == Catch::Approx(-0.026193).margin(margin));
145 CHECK(q1_inv.
z() == Catch::Approx(0.00471045).margin(margin));
146 CHECK(q1_inv.
w() == Catch::Approx(0.000927816).margin(margin));
152 const double norm = q1.magnitude();
153 CHECK(norm == Catch::Approx(37.4318).margin(1e-4));
156 SECTION(
"Normalization")
160 const double margin = 1e-6;
161 const double norm = q1.magnitude();
162 CHECK(norm == Catch::Approx(1.0).margin(1e-4));
163 CHECK(q1.x() == Catch::Approx(0.0801457).margin(margin));
164 CHECK(q1.y() == Catch::Approx(0.98045).margin(margin));
165 CHECK(q1.z() == Catch::Approx(-0.176321).margin(margin));
166 CHECK(q1.w() == Catch::Approx(0.0347298).margin(margin));
169 SECTION(
"Copy constructor")
172 std::cout <<
"q_copy1=" << q_copy1 << std::endl;
178 CHECK(q_copy2.
data != q_copy1.
data);
179 q_copy1.
set(1, 0, 1, 10);
182 std::cout <<
"q_copy1 after set = " << q_copy1 << std::endl;
183 std::cout <<
"q_copy2=" << q_copy2 << std::endl;
195 CHECK(q_same.data != q1.
data);
200 int main(
int argc,
char *argv[])
202 Catch::Session session;
203 session.applyCommandLine(argc, argv);
204 int numFailed = session.run();
210 int main() {
return EXIT_SUCCESS; }
Type * data
Address of the first element of the data array.
Implementation of column vector and the associated operations.
vpColVector & normalize()
static double rad(double deg)
static bool equal(double x, double y, double threshold=0.001)
Implementation of a rotation vector as quaternion angle minimal representation.
const double & z() const
Returns the z-component of the quaternion.
vpQuaternionVector conjugate() const
vpQuaternionVector inverse() const
void set(double x, double y, double z, double w)
static vpQuaternionVector slerp(const vpQuaternionVector &q0, const vpQuaternionVector &q1, double t)
static vpQuaternionVector nlerp(const vpQuaternionVector &q0, const vpQuaternionVector &q1, double t)
const double & x() const
Returns the x-component of the quaternion.
const double & y() const
Returns the y-component of the quaternion.
const double & w() const
Returns the w-component of the quaternion.
static vpQuaternionVector lerp(const vpQuaternionVector &q0, const vpQuaternionVector &q1, double t)
Implementation of a rotation vector as axis-angle minimal representation.