[英]How to find angle of point from x-axis independant of quadrant?
給定一個點(x,y),如何計算x軸的角度?
| . <- (x,y)
| /
| /
| /
|/
--------+---------
|
|
目前我有
Math.atan(y/x) * 180 / Math.PI;
但是,這不能正確表示所有坐標。 這是每個象限(逆時針)中的結果。
Quadrant 1: 0 -> -90
Quadrant 2: 90 -> 0
Quadrant 3: 0 -> -90
Quadrant 4: 90 -> 0
我該如何寫一條語句,使我得到與任何點的x軸成的角度,以使象限的結果如下所示。
Quadrant 1: 0 -> 90
Quadrant 2: 90 -> 180
Quadrant 3: 180 -> 270
Quadrant 4: 270 -> 360
基本上,我該如何在所有四個象限中進行這項工作?
請使用Math.atan2()
因為它在前兩個象限中返回0-> 180,在后兩個象限中返回-180-> 0。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.