Skip to content

Instantly share code, notes, and snippets.

@orlp
Created October 28, 2011 16:07
Show Gist options
  • Save orlp/1322646 to your computer and use it in GitHub Desktop.
Save orlp/1322646 to your computer and use it in GitHub Desktop.
def interpolate_angle(a, b, alpha):
a, b = math.radians(a), math.radians(b)
# add up weighted unit vectors
vx = math.cos(a) * (1 - alpha) + math.cos(b) * alpha
vy = math.sin(a) * (1 - alpha) + math.sin(b) * alpha
# is our unit vector undefined? then return counter-clockwise increasing rotation
if vx == 0 and vy == 0:
return (math.degrees(a) + 180 * alpha) % 360
# calculate angle
return math.degrees(math.atan2(vy, vx)) % 360
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment