Skip to content

Commit ec2c023

Browse files
committedJul 6, 2018
[BALL] Fix Quaternion_test
When constructing axis-angles from quaternions, Eigen flips the rotation axis if the real component of the quaternion is negative. Since this does not affect the validity of the rotation, the result is still correct. The test case has been adjusted to also accept the alternative representation with flipped axis and modified angle of (2\pi - old_angle).
1 parent 0d1c2dc commit ec2c023

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed
 

‎test/Quaternion_test.C

+31-8
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,24 @@ CHECK(void toAxisAngle(TVector3<T>& axis, T& angle))
193193
Quaternion q(v1, a);
194194
q.toAxisAngle(v2, ang);
195195
v1.normalize();
196-
TEST_REAL_EQUAL(ang, a)
197-
TEST_REAL_EQUAL(v2.x, v1.x)
198-
TEST_REAL_EQUAL(v2.y, v1.y)
199-
TEST_REAL_EQUAL(v2.z, v1.z)
196+
/*
197+
* There are two valid axis-angle representations for the same
198+
* rotation, namely (v, a) and (-v, 2\pi-a). Since the actual
199+
* result depends on the eigen3 version used, we have to test
200+
* both versions here.
201+
*/
202+
if(v2.x < 0) {
203+
TEST_REAL_EQUAL(ang, 2 * BALL::Constants::PI - a)
204+
TEST_REAL_EQUAL(v2.x, -v1.x)
205+
TEST_REAL_EQUAL(v2.y, -v1.y)
206+
TEST_REAL_EQUAL(v2.z, -v1.z)
207+
}
208+
else {
209+
TEST_REAL_EQUAL(ang, a)
210+
TEST_REAL_EQUAL(v2.x, v1.x)
211+
TEST_REAL_EQUAL(v2.y, v1.y)
212+
TEST_REAL_EQUAL(v2.z, v1.z)
213+
}
200214
RESULT
201215

202216
CHECK(void toEulerAngles(T& yaw, T& pitch, T& roll))
@@ -217,17 +231,26 @@ RESULT
217231

218232
CHECK(T getAngle() const)
219233
Quaternion q(v,a);
220-
TEST_REAL_EQUAL(q.getAngle(),a)
234+
// see toAxisAngle check
235+
TEST_EQUAL((abs(q.getAngle()-a) < 1e-4 || abs(q.getAngle() - 2 * BALL::Constants::PI + a) < 1e-4), true)
221236
RESULT
222237

223238
CHECK(TVector3<T> getAxis())
224239
Quaternion q(v,a);
225240
Vector3 v1(v);
226241
v1.normalize();
227242
Vector3 v2 = q.getAxis();
228-
TEST_REAL_EQUAL(v2.x, v1.x)
229-
TEST_REAL_EQUAL(v2.y, v1.y)
230-
TEST_REAL_EQUAL(v2.z, v1.z)
243+
// see toAxisAngle check
244+
if(v2.x < 0) {
245+
TEST_REAL_EQUAL(v2.x, -v1.x)
246+
TEST_REAL_EQUAL(v2.y, -v1.y)
247+
TEST_REAL_EQUAL(v2.z, -v1.z)
248+
}
249+
else {
250+
TEST_REAL_EQUAL(v2.x, v1.x)
251+
TEST_REAL_EQUAL(v2.y, v1.y)
252+
TEST_REAL_EQUAL(v2.z, v1.z)
253+
}
231254
RESULT
232255

233256
CHECK(TMatrix4x4<T>& getRotationMatrix(TMatrix4x4<T>& m) const throw())

0 commit comments

Comments
 (0)
Please sign in to comment.