Skip to content

Instantly share code, notes, and snippets.

@o4oren
Created April 30, 2020 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save o4oren/ab22449ea88afa30acc0a0c9925470f9 to your computer and use it in GitHub Desktop.
Save o4oren/ab22449ea88afa30acc0a0c9925470f9 to your computer and use it in GitHub Desktop.
calc_angle
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