Last active
March 28, 2024 07:42
-
-
Save jernwerber/f2cb1fc89ed25fb34ef0663261be116e to your computer and use it in GitHub Desktop.
Get direction (unit vector tuple)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def get_direction(startPos, endPos): | |
# returns a direction (unit vector tuple) pointing from startPos to endPos | |
# startPos and endPos are tuples of x,y positions | |
sx, sy = startPos | |
ex, ey = endPos | |
mag = math.sqrt((ex-sx)**2 + (ey-sy)**2) | |
return ((ex-sx)/mag, (ey-sy)/mag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment