atan(k) 斜率爲k的直線與x軸的夾角 -π/2~π/2
atan2(y,x) 點(x,y)與原點的連線與x軸的夾角 -π~π
PI=acos(-1.0);
cout<<atan(1.0)*180/PI;//45°
cout<<atan2(1.0,1.0)*180/PI;//45° 第一象限
cout<<atan2(-1.0,-1.0)*180/PI;//-135°第三象限
求線段AB與x軸的夾角
A(x1,y1) B(x2,y2)
atan2(y2-y1,x2-x1)
已經定義在math.h裏的值
#define M_E 2.71828182845904523536
#define M_LOG2E 1.44269504088896340736
#define M_LOG10E 0.434294481903251827651
#define M_LN2 0.693147180559945309417
#define M_LN10 2.30258509299404568402
#define M_PI 3.14159265358979323846//PI