atan与atan2的区别
形状上下文的代码已经写成好久了,今天猛然发现这个ShapeContext直方图对任何形状都是分布在一、四区间的。这才意识到写错了。这个问题浪费了我接近半天的时间,直到单步才知道atan2的返回值有问题。原来atan2是不用你费心去判断区间的,其区别如下。还有个错误,是强制转换为整形时括号的位置不对!
atan, atan2
Calculates the arctangent of x (atan) or the arctangent of y/x (atan2).
double atan( double x );
double atan2( double y, double x );
Routine |
Required Header |
Compatibility |
atan |
<math.h> |
ANSI, Win 95, Win NT |
atan2 |
<math.h> |
ANSI, Win 95, Win NT |
For additional compatibility information, see Compatibility in the Introduction.
Libraries
LIBC.LIB |
Single thread static library, retail version |
LIBCMT.LIB |
Multithread static library, retail version |
MSVCRT.LIB |
Import library for MSVCRT.DLL, retail version |
Return Value
atan returns the arctangent of x. atan2 returns the arctangent of y/x. If x is 0, atanreturns 0. If both parameters of atan2 are 0, the function returns 0. You can modify error handling by using the _matherr routine. atan returns a value in the range –π/2 to π/2 radians; atan2 returns a value in the range –π to π radians, using the signs of both parameters to determine the quadrant of the return value.
Parameters
x, y
Any numbers
Remarks
The atan function calculates the arctangent of x. atan2 calculates the arctangent ofy/x. atan2 is well defined for every point other than the origin, even if x equals 0 and ydoes not equal 0.
事实上这是个很简单的函数运用问题,但当时的疏忽知道几个月后才被发现!真的很惭愧,总想着去写个涵括多种方法的目标跟踪程序,但到现在我的程序都只能跑一段,不规则的出现堆栈报错,却一直不知道怎么去差错。另外,我的VS2003经常在编译时产生异常直接关闭,还让我给微软提交错误报告,真不知道是不是系统有问题!不管这些了,今天的教训是在以后写代码的路上,要仔细点!多写写把, 自己看的写的实在是太少了!