atan与atan2的区别
相比较ATan,ATan2究竟有什么不同?本篇介绍一下ATan2的用法及使用条件。
对于tan(θ) = y / x:
θ = ATan(y / x)求出的θ取值范围是[-PI/2, PI/2]。
θ = ATan2(y, x)求出的θ取值范围是[-PI, PI]。
当 (x, y) 在第一象限, 0 < θ < PI/2.
当 (x, y) 在第二象限 PI/2 < θ≤PI.
当 (x, y) 在第三象限, -PI < θ < -PI/2.
当 (x, y) 在第四象限, -PI/2 < θ < 0.
当点(x, y)在象限的边界也就是坐标轴上时:
当 y 是 0,x 为非负值, θ = 0.
当 y 是 0, x 是 负值, θ = PI.
当 y 是 正值, x 是 0, θ = PI/2.
当 y 是 负值, x 是 0, θ = -PI/2.
由此可知,一般情况下用ATan即可,当对所求出角度的取值范围有特殊要求时,应使用ATan2。
atan 和 atan2 都是求反正切函数,如:有两个点 point(x1,y1), 和 point(x2,y2);
那么这两个点形成的斜率的角度计算方法分别是:
float angle = atan( (y2-y1)/(x2-x1) );
或
float angle = atan2( y2-y1, x2-x1 );
atan 和 atan2 区别:
1:参数的填写方式不同;
2:atan2 的优点在于 如果 x2-x1等于0 依然可以计算,但是atan函数就会导致程序出错;
结论: atan 和 atan2函数,建议用 atan2函数;
atan与atan2的区别的更多相关文章
- C语言math.h库函数中atan与atan2的区别
源: C语言math.h库函数中atan与atan2的区别 C语言中的atan和atan2
- 反正切函数atan与atan2的区别
atan 和 atan2 都是求反正切函数,如:有两个点 point(x1,y1), 和 point(x2,y2); 那么这两个点形成的斜率的角度计算方法分别是: float angle = atan ...
- atan atan2的区别!
atan与atan2的使用=范围不一样! 今天调一一下午的BUG!终于发现了是ATAN的错! atan()函数: atan(y/x); 带一个参数!注意X不能为0,否则…………, 还有求出的角度为-p ...
- atan 和 atan2
转自http://blog.csdn.net/chinabinlang/article/details/6802686 atan函数与atan2函数的一点区别 . atan 和 atan2 都是求反 ...
- C语言中的atan和atan2(转)
在C语言的math.h或C++中的cmath中有两个求反正切的函数atan(double x)与atan2(double y,double x) 他们返回的值是弧度 要转化为角度再自己处理下. 前者 ...
- atan()与atan2()
Atan2 函数介绍 atan2原型:extern float atan2(float y, float x);用法:#include <math.h>功能:求y/x(弧度表示)的反正切值 ...
- C语言中的atan和atan2
本文内容为转载,是在阅读 RTKLIB源码时意识到的这个问题,原文地址为:https://www.cnblogs.com/dutlei/archive/2013/01/14/2860332.html ...
- atan和atan2反正切计算
typedef struct point { double x, y; }point; //给定两个点 point a(x1,y1),b(x2,y2); 使用反三角函数atan求斜率,原型如下 flo ...
- ATan2与ATan的区别
相比较ATan,ATan2究竟有什么不同?本篇介绍一下ATan2的用法及使用条件. 对于tan(θ) = y / x: θ = ATan(y / x)求出的θ取值范围是[-PI/2, PI/2]. θ ...
随机推荐
- B1954 The xor-longest Path
爆炸入口 给定一颗带权值的,节点数为n的树,求树上路径最大异或和. solution: 先dfs将所有点到根的异或和算出来.然后放进tire树中贪心. #include<cstdio> # ...
- CUDA数组分配
原问链接 概述:数组分配可以通过cudaMallocArray()和cudaMalloc3DArray() 1.cudaMallocArray() cudaError_t cudaMallocArra ...
- Vue nodejs商城项目-项目概述
项目概况 用vue2.0 +node.js +MongonDB 做了一个商城系统 技术选型 Vue2.0+node.js+express+MongoDB+axios+vuex 构建工具 Webpack ...
- CocoaAsyncSocket使用
代理的.h文件 #import <Foundation/Foundation.h> #import "GCDAsyncSocket.h" typedef void(^S ...
- vue 用户输入搜索 与无限下拉
vue项目中,用户输入关键字搜索,并且手机端做无限下拉 watch: { 'getListForm.searchKey'(val) { this.radioChange(); // 还有其他逻辑,内部 ...
- MySql错误1045 Access denied for user 'root'@'localhost' (using password:YES)
1.先停止mysql服务 2.进入mysql的安装路径,找到并打开my.ini文件,找到[mysqld],在该行下面添加 skip_grant_tables,也就是通知mysql,在登陆的时候跳过密码 ...
- linux文件共享之samba,nfs的搭建
Samba server简介 Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成.SMB(Server Messages Block,信息服务块)是一种在局 ...
- 【Python 2 到 3 系列】 print 是函数
v3.0 以前,print一直作为语法结构存在,他是python语法的一部分:这个理解起来可能有点蹩脚,但的确是这样. print 一直被定以为一个statement,也就是说,他跟return/tr ...
- TCL之表达式
- Codeforces Round #449 (Div. 2) C. DFS
C. Nephren gives a riddle time limit per test 2 seconds memory limit per test 256 megabytes input st ...