目录
win10系统
这个头文件在visual studio的 sdk中
引用方法:
#include<math.h>
cmakelist.txt
需要cmake生成makefile的工程文件有对math库的依赖,主要在cmakelist.txt添加依赖:
-
LINK_LIBRARIES(m) #括号中添加标准库名称,math的库用m表示
-
ps:需在add_executable(main ${DIR_SRCS})前添加
target_link_libraries(${ProjectName} m)
linux gcc方式
Linux 下使用常用的 数学函数时需要包含math.h头文件,但是仅仅包含math.h头文件是不够的,还需要在Makefile文件中gcc命令后面添加 -lm,这个是表示链接数学函数库,相似的使用线程编程的时候需要链接thread库: -lpthread。
#include <math.h>
double atan2( double y, double x );
函数返回y/x的反正切值,并且它可以通过x,y的符号判断
(x,y)所表示的象限,其返回的也是对应象限的角度值
gcc编译命令:
gcc ****** -lm
l 表示库 m表示数学库
c++使用pi
#include <math.h>
#define PI acos(-1)
c++ 计算物体角度:
#include <math.h>
#define pi acos(-1)
float angle_camera=32.3;
float ccc=tan(angle_camera/180*pi);
//print(ccc,ll)
float angle1 = atan2((xmin+xmax)/2, 320/ccc);
angle1=angle1*180 / pi;