public static double calculateDirection(double x, double y) {
if (x == 0) {
if (y > 0) {
return Math.PI / 2;
}
return Math.PI * 3 / 2;
}
if (x > 0 && y >= 0) {
return Math.atan(y / x);
} else if (x > 0 && y < 0) {
// tan < 0
return 2 * Math.PI + Math.atan(y / x);
} else if (x < 0 && y > 0) {
// tan < 0
return Math.PI + Math.atan(y / x);
} else {
// tan > 0
return Math.PI + Math.atan(y / x);
}
}
看象限沒啥好說的。
兩點之間方向
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.