#unity/日常积累 ## 相同 Atan 和 Atan2 都是求反正切函数 ![[Pasted image 20240328165125.png]] 如:有两个点 point(x1,y1), 和 point(x2,y2),那么这两个点形成的斜率的角度计算方法分别是: ``` cs float angle = Atan((y2-y1) / (x2-x1)); float angle = Atan2( y2-y1, x2-x1 ); ``` ## 区别 1:参数的填写方式不同。 ``` cs public static float Atan2 (float y, float x); public static float Atan (float f); ``` 2:Atan2 的优点在于 如果 x2-x1等于0 依然可以计算,但是Atan函数就会导致程序出错。 3:Mathf.Atan()返回的值的范围是[-π/2,π/2],Mathf.Atan()返回的值的范围是[-π/2,π/2]。