Skip to content

Commit a4f7c65

Browse files
authored
Fix/twist pitch clean (#196)
1 parent 7e7fc92 commit a4f7c65

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎spatialmath/twist.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ def pitch(self):
944944
>>> S.pitch
945945
946946
"""
947-
return np.dot(self.w, self.v)
947+
return np.dot(self.w, self.v) / np.dot(self.w, self.w)
948948

949949
def line(self):
950950
"""

‎tests/test_twist.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ def test_exp(self):
179179
tw = Twist3.UnitRevolute([0, 0, 1], [0, 0, 0])
180180
array_compare(tw.exp(pi / 2), SE3.Rz(pi / 2))
181181

182+
def test_pitch(self):
183+
# pitch = (w . v) / (w . w), regression test for missing denominator
184+
185+
# non-unit w: exercises the normalization, would fail without it
186+
tw = Twist3([0, 0, 4], [0, 0, 2])
187+
self.assertAlmostEqual(tw.pitch, 2.0)
188+
189+
# unit w: denominator is 1, sanity check against UnitRevolute's pitch arg
190+
tw = Twist3.UnitRevolute([0, 0, 1], [0, 0, 0], pitch=3)
191+
self.assertAlmostEqual(tw.pitch, 3.0)
192+
182193
def test_arith(self):
183194
# check overloaded *
184195

0 commit comments

Comments
 (0)