Created
August 29, 2018 00:10
-
-
Save uhho/cbe5f6e7a1ba036093fe6d968c08033b to your computer and use it in GitHub Desktop.
Calculate angle between two vectors
This file contains hidden or 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 numpy as np | |
def unit_vector(vector): | |
return vector / np.linalg.norm(vector) | |
def angle_between(v1, v2): | |
v1_u = unit_vector(v1) | |
v2_u = unit_vector(v2) | |
return np.arccos(np.clip(np.dot(v1_u, v2_u), -1.0, 1.0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment