Created
July 20, 2015 22:02
-
-
Save unitycoder/1362b5fcb219ff0b3c0c to your computer and use it in GitHub Desktop.
Get 0-360 Angle Between 2D Lines
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
Vector3 from = p1-pMiddle; | |
Vector3 to = p2-pMiddle; | |
float angle = AngleBetween(from, to); | |
float AngleBetween(Vector3 vector1, Vector3 vector2) | |
{ | |
var sin = vector1.x * vector2.y - vector2.x * vector1.y; | |
var cos = vector1.x * vector2.x + vector1.y * vector2.y; | |
float angle = Mathf.Atan2(sin, cos) * (180f / Mathf.PI); | |
if (angle<0) angle+=360; | |
return angle ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment