Skip to content

Instantly share code, notes, and snippets.

@jrainlau
Last active January 11, 2019 08:22
Show Gist options
  • Save jrainlau/026ae9931cfe618c598c4c6cb31598d4 to your computer and use it in GitHub Desktop.
Save jrainlau/026ae9931cfe618c598c4c6cb31598d4 to your computer and use it in GitHub Desktop.
笛卡尔坐标转极坐标算法
// 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