Last active
January 11, 2019 08:22
-
-
Save jrainlau/026ae9931cfe618c598c4c6cb31598d4 to your computer and use it in GitHub Desktop.
笛卡尔坐标转极坐标算法
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
// v2 | |
function angle (x, y) { | |
let angleRate = 360 * Math.atan(y / x) / (2 * Math.PI) |> parseInt |> Math.abs | |
if (y >= 0 && x < 0) { | |
angleRate = 180 - angleRate | |
} else if (y < 0 && x <= 0) { | |
angleRate += 180 | |
} else if (y < 0 && x > 0) { | |
angleRate = 360 - angleRate | |
} | |
return angleRate | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment