Created
May 2, 2020 16:37
-
-
Save o4oren/6f72dd57a5291366c9a25eb347f1d633 to your computer and use it in GitHub Desktop.
Calcualate angle
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
private fun calculateAngle(x: Float, y: Float): Float { | |
val px = (x / width.toFloat()) - 0.5 | |
val py = ( 1 - y / height.toFloat()) - 0.5 | |
var angle = -(Math.toDegrees(atan2(py, px))) | |
.toFloat() + 90 | |
if (angle > 180) angle -= 360 | |
return angle | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment