Skip to content

Instantly share code, notes, and snippets.

@o4oren
Created May 2, 2020 16:37
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/6f72dd57a5291366c9a25eb347f1d633 to your computer and use it in GitHub Desktop.
Save o4oren/6f72dd57a5291366c9a25eb347f1d633 to your computer and use it in GitHub Desktop.
Calcualate 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