atan和atan2反正切计算

typedef struct point {
    double x, y;
}point;
//给定两个点
point a(x1,y1),b(x2,y2);
  1. 使用反三角函数atan求斜率,原型如下
float       atan( float arg );  
double      atan( double arg );
long double atan( long double arg );
double      atan( Integral arg );
double angle=atan((y2-y1)/(x2-x1));

返回值
若不出现错误,则返回 arg 在$ [- π/2 ; +π/2]$ 弧度范围中的弧(反)正切( $arctan(arg) $)。值域有限,一四象限,斜率不存在不能求

  1. 使用反三角函数atan2求斜率,原型如下
float       atan2( float y, float x );
double      atan2( double y, double x );
long double atan2( long double y, long double x );
Promoted    atan2( Arithmetic1 y, Arithmetic2 x );

返回值
若不出现错误,则返回 y/x 在 $(-π ; +π] $弧度范围中的弧(反)正切( arctan(y/x) )。值域扩展到四个象限。
atan2(y,x)所表达的意思是坐标原点为起点,指向(y,x)的射线x轴正方向形成角的角度。在x=0的时候:
1.当y>0时,指的是绕逆时针到达射线所旋转的角的角度;
2.而当y<0时,指的是绕顺时针达到射线所旋转的角的角度。

这样就可以求两个点表示的线段(向量)和x轴正向的角度,如下

double angle=atan2((y2-y1),(x2-x1));

转载于:https://www.cnblogs.com/FlyerBird/p/9326102.html

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值