39 #include <visp3/core/vpConfig.h>
41 #ifdef VISP_HAVE_CATCH2
43 #include <visp3/core/vpQuaternionVector.h>
45 #define CATCH_CONFIG_RUNNER
48 #ifdef ENABLE_VISP_NAMESPACE
52 TEST_CASE(
"Quaternion interpolation",
"[quaternion]")
64 const double ref_angle_middle = t * (angle0 + angle1);
65 const double margin = 1e-3;
66 const double marginLerp = 1e-1;
74 CHECK(
vpThetaUVector(qLerp).getTheta() == Approx(ref_angle_middle).margin(marginLerp));
80 CHECK(
vpThetaUVector(qNlerp).getTheta() == Approx(ref_angle_middle).margin(margin));
86 CHECK(
vpThetaUVector(qSlerp).getTheta() == Approx(ref_angle_middle).margin(margin));
90 TEST_CASE(
"Quaternion operators",
"[quaternion]")
93 SECTION(
"Addition and subtraction")
98 const double margin = std::numeric_limits<double>::epsilon();
99 std::cout <<
"q3=" << q3 << std::endl;
100 CHECK(q3.
x() == Approx(2.6).margin(margin));
101 CHECK(q3.
y() == Approx(0.4).margin(margin));
102 CHECK(q3.
z() == Approx(-3.0).margin(margin));
103 CHECK(q3.
w() == Approx(4.0).margin(margin));
108 std::cout <<
"q4=" << q4 << std::endl;
109 CHECK(q4.
x() == Approx(q2.x()).margin(margin));
110 CHECK(q4.
y() == Approx(q2.y()).margin(margin));
111 CHECK(q4.
z() == Approx(q2.z()).margin(margin));
112 CHECK(q4.
w() == Approx(q2.w()).margin(margin));
115 SECTION(
"Multiplication")
121 const double margin = std::numeric_limits<double>::epsilon() * 1e4;
122 CHECK(q3.
x() == Approx(3.0).margin(margin));
123 CHECK(q3.
y() == Approx(36.7).margin(margin));
124 CHECK(q3.
z() == Approx(-6.6).margin(margin));
125 CHECK(q3.
w() == Approx(1.3).margin(margin));
132 const double margin = std::numeric_limits<double>::epsilon();
133 CHECK(q1_conj.
x() == Approx(-q1.x()).margin(margin));
134 CHECK(q1_conj.
y() == Approx(-q1.y()).margin(margin));
135 CHECK(q1_conj.
z() == Approx(-q1.z()).margin(margin));
136 CHECK(q1_conj.
w() == Approx(q1.w()).margin(margin));
143 const double margin = 1e-6;
144 CHECK(q1_inv.
x() == Approx(-0.00214111).margin(margin));
145 CHECK(q1_inv.
y() == Approx(-0.026193).margin(margin));
146 CHECK(q1_inv.
z() == Approx(0.00471045).margin(margin));
147 CHECK(q1_inv.
w() == Approx(0.000927816).margin(margin));
153 const double norm = q1.magnitude();
154 CHECK(norm == Approx(37.4318).margin(1e-4));
157 SECTION(
"Normalization")
161 const double margin = 1e-6;
162 const double norm = q1.magnitude();
163 CHECK(norm == Approx(1.0).margin(1e-4));
164 CHECK(q1.x() == Approx(0.0801457).margin(margin));
165 CHECK(q1.y() == Approx(0.98045).margin(margin));
166 CHECK(q1.z() == Approx(-0.176321).margin(margin));
167 CHECK(q1.w() == Approx(0.0347298).margin(margin));
170 SECTION(
"Copy constructor")
173 std::cout <<
"q_copy1=" << q_copy1 << std::endl;
179 CHECK(q_copy2.
data != q_copy1.
data);
180 q_copy1.
set(1, 0, 1, 10);
183 std::cout <<
"q_copy1 after set = " << q_copy1 << std::endl;
184 std::cout <<
"q_copy2=" << q_copy2 << std::endl;
196 CHECK(q_same.data != q1.
data);
201 int main(
int argc,
char *argv[])
203 Catch::Session session;
206 session.applyCommandLine(argc, argv);
208 int numFailed = session.run();
218 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.