16 if issubclass(a.__class__, np.ndarray)
and issubclass(b.__class__, np.ndarray):
17 return np.allclose(a, b, epsilon)
19 return abs(a - b) < epsilon
24 verbose
and print(
"[Quaternion] Coefficient initialisation")
25 q = Quaternion(1, 2, 3, 4)
27 assert isapprox(np.linalg.norm(q.coeffs()), q.norm())
28 assert isapprox(np.linalg.norm(q.coeffs()), 1)
31 verbose
and print(
"[Quaternion] Coefficient-vector initialisation")
32 v = np.array([0.5, -0.5, 0.5, 0.5])
33 for k
in range(10000):
38 verbose
and print(
"[Quaternion] AngleAxis initialisation")
42 assert isapprox(q.coeffs(), q2.coeffs())
43 assert q2.isApprox(q2)
44 assert q2.isApprox(q2, 1e-2)
48 assert isapprox(Rq.dot(Rq.T), np.eye(3))
52 verbose
and print(
"[Quaternion] Rotation Matrix initialisation")
55 assert isapprox(q.coeffs(), qR.coeffs())
57 assert isapprox(qR[3], 1.0 / np.sqrt(30))
60 print(
"Error, this message should not appear.")
61 except RuntimeError
as e:
63 print(
"As expected, caught exception: ", e)
66 r = AngleAxis(0.1, np.array([1, 0, 0], np.double))
68 print(
"Rx(.1) = \n\n", r.matrix(),
"\n")
69 assert isapprox(r.matrix()[2, 2], cos(r.angle))
70 assert isapprox(r.axis, np.array([1.0, 0, 0]))
73 assert r.isApprox(r, 1e-2)
75 r.axis = np.array([0, 1, 0], np.double).T
76 assert isapprox(r.matrix()[0, 0], cos(r.angle))
82 r2 = AngleAxis(np.dot(R, R))
83 assert isapprox(r2.angle, r.angle * 2)
87 assert ro.__class__ == AngleAxis
92 assert qo.__class__ == Quaternion
94 assert q.norm() == res