Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spatialmath/base/quaternions.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ def qangle(q1: ArrayLike4, q2: ArrayLike4) -> float:

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


def qprint(
Expand Down
10 changes: 10 additions & 0 deletions tests/base/test_quaternions.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ def test_r2q(self):
with self.assertRaises(ValueError):
nt.assert_array_almost_equal(q1a, r2q(r1.R, order="aaa"))

def test_qangle(self):
# Test function that calculates angle between quaternions
q1 = [1., 0, 0, 0]
q2 = [1 / np.sqrt(2), 0, 1 / np.sqrt(2), 0] # 90deg rotation about y-axis
nt.assert_almost_equal(qangle(q1, q2), np.pi / 2)

q1 = [1., 0, 0, 0]
q2 = [1 / np.sqrt(2), 1 / np.sqrt(2), 0, 0] # 90deg rotation about x-axis
nt.assert_almost_equal(qangle(q1, q2), np.pi / 2)


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