8000 Merge pull request #82 from KPereida/master · kaigeli/spatialmath-python@07c6f62 · GitHub
[go: up one dir, main page]

Skip to content

Commit 07c6f62

Browse files
Merge pull request bdaiinstitute#82 from KPereida/master
Fix qangle function and add associated test
2 parents 33bb8db + c38dd2f commit 07c6f62

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

spatialmath/base/quaternions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ def qangle(q1: ArrayLike4, q2: ArrayLike4) -> float:
985985

986986
q1 = smb.getvector(q1, 4)
987987
q2 = smb.getvector(q2, 4)
988-
return 2.0 * math.atan2(smb.norm(q1 - q2), smb.norm(q1 + q2))
988+
return 4.0 * math.atan2(smb.norm(q1 - q2), smb.norm(q1 + q2))
989989

990990

991991
def qprint(

tests/base/test_quaternions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,16 @@ def test_r2q(self):
218218
with self.assertRaises(ValueError):
219219
nt.assert_array_almost_equal(q1a, r2q(r1.R, order="aaa"))
220220

221+
def test_qangle(self):
222+
# Test function that calculates angle between quaternions
223+
q1 = [1., 0, 0, 0]
224+
q2 = [1 / np.sqrt(2), 0, 1 / np.sqrt(2), 0] # 90deg rotation about y-axis
225+
nt.assert_almost_equal(qangle(q1, q2), np.pi / 2)
226+
227+
q1 = [1., 0, 0, 0]
228+
q2 = [1 / np.sqrt(2), 1 / np.sqrt(2), 0, 0] # 90deg rotation about x-axis
229+
nt.assert_almost_equal(qangle(q1, q2), np.pi / 2)
230+
221231

222232
if __name__ == "__main__":
223233
unittest.main()

0 commit comments

Comments
 (0)
0