Last active
November 16, 2016 00:47
-
-
Save omikun/02ca156405b0822c5f0e4edd9bc777e4 to your computer and use it in GitHub Desktop.
Vector math
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
float AngleBetweenVector2(Vector2 vec1, Vector2 vec2) | |
{ | |
Vector2 diference = vec2 - vec1; | |
float sign = (vec2.y < vec1.y)? -1.0f : 1.0f; | |
return Vector2.Angle(Vector2.right, diference) * sign; | |
} | |
float cosAngleBetweenVector3(Vector3 vec1, Vector3, vec2) | |
{ | |
float dot = Vector3.Dot(vec1,vec2); | |
// Divide the dot by the product of the magnitudes of the vectors | |
return dot/(vec1.magnitude*vec2.magnitude); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment