当前位置:网站首页>Unity——Mathf. Similarities and differences between atan and atan2

Unity——Mathf. Similarities and differences between atan and atan2

2022-06-26 19:16:00 DESIDERIO

identical

Atan and Atan2 Are all arctangent functions
 Insert picture description here

Such as : There are two points. point(x1,y1), and point(x2,y2), Then the angle calculation method of the slope formed by these two points is :

float angle = Atan((y2-y1) / (x2-x1));
float angle = Atan2( y2-y1, x2-x1 );

difference

1: Parameters are filled in in different ways .

public static float Atan2 (float y, float x);
public static float Atan (float f);

2:Atan2 The advantage is If x2-x1 be equal to 0 It can still be calculated , however Atan Function will cause program error .
3:Mathf.Atan() The range of returned values is [-π/2,π/2],Mathf.Atan() The range of returned values is [-π/2,π/2].

Reference resources

atan Function and atan2 A little difference between functions

原网站

版权声明
本文为[DESIDERIO]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202161737158610.html