Created
April 30, 2020 18:09
-
-
Save o4oren/ab22449ea88afa30acc0a0c9925470f9 to your computer and use it in GitHub Desktop.
calc_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