【编码随笔】使用atan2而不是atan
来源:互联网 发布:mac能玩gta5吗 编辑:程序博客网 时间:2024/05/16 19:17
【编码随笔】是自己在coding过程中遇到的一些小问题或者突然想起来的知识点,稍作记录。
【阿甘补充2013.10.30:仔细看参数,atan2(const double y, const double x),是先写y再写x,不要搞错了,下文写的MyAtan写法不对。】
今天想使用反正切函数,想起数学中反正切函数只提供[-PI/2, PI/2]之间的函数值。
搜索发现math.h里的atan函数也是这个返回值范围。
正要准备着手写个返回[-PI, PI]的函数,MyAtan()。
再搜索发现原来已经有atan2了,作罢。
不过还是把代码贴出来。
double MyAtan(const double x, const double y){if ( fabs(x) < 1.0){return y > 0.0 ? M_PI_2 : -M_PI_2;}else if ( x > 0.0 ){atan( y / x);}else{double ret = atan( y / x);return y > 0.0 ? ret - M_PI_2 : ret + M_PI_2; }}
当要使用到返回[0, 2*PI]的时候,只需这样操作就可:
atan2(double, double) + M_PI
【版权声明:
1、本人对本博客内所有原创文章享有版权,转载请注明作者本人,并以链接形式注明出处。
2、侵犯本人版权相关利益者,个人会在新浪微博、CSDN博客中永久追踪及谴责。同时,保留追究法律责任的权利。向您的厚道致谢。
gwf
初稿 2013.4.29】
- 【编码随笔】使用atan2而不是atan
- atan与atan2函数
- atan 和 atan2
- atan和atan2
- atan和atan2
- Fortran库函数atan与atan2
- Math.atan与Math.atan2
- Math.atan与Math.atan2
- ATan2与ATan的区别
- Math.atan与Math.atan2
- as3 中的数学函数atan与atan2
- as3 中的数学函数atan与atan2
- C语言中的atan和atan2
- 正切atan2(y,x)与atan(x)
- atan、atanf、atanl、atan2、atan2f、atan2l
- cmath中的atan函数和atan2函数
- C语言中的atan和atan2
- C语言中的atan和atan2
- HDOJ 1811 Rank of Tetris (拓扑排序+并查集)
- 关于Bin文件的解析
- WinCE6.0bootloader的研究
- 安装了Win7以及XP双系统后,怎么卸载Win 7并删除win7启动项
- Java compiler level does not match the version of the installed Java project facet
- 【编码随笔】使用atan2而不是atan
- Sicily 1033 City Road (SOJ 1033)【dp动态规划】
- 听写笔迹
- 【算法】选择排序
- link
- wince 中断
- 多点触摸图片放缩
- Wince驱动结构分析
- WinCE6.0驱动移植( 驱动模型变化, 以及与WinCE5.0的比较)