def angle_diff(a, b):
""" Calculates the difference between angle a and angle b (both should be in radians)
the difference is always based on the closest rotation from angle a to angle b
examples:
angle_diff(.1,.2) -> -.1
angle_diff(.1, 2*math.pi - .1) -> .2
angle_diff(.1, .2+2*math.pi) -> -.1
"""
a = ThetaRange.normalize_angle(a)
b = ThetaRange.normalize_angle(b)
d1 = a-b
d2 = 2*math.pi - math.fabs(d1)
if d1 > 0:
d2 *= -1.0
if math.fabs(d1) < math.fabs(d2):
return d1
else:
return d2
评论列表
文章目录