【C++学习笔记】atan()和atan2()函数使用

提示:atan()和atan2()为基于<cmath>(math.h)头文件的计算函数,可用于角度归一化。

一、atan()函数

1.输入要求

double atan (double x);      
float atan (float x);
long double atan (long double x);     
double atan (T x);           // additional overloads for integral types

2.输出范围

atan(x)函数返回以弧度为单位的角度,范围为[-pi/2,+pi/2],包含-pi/2和+pi/2的。由此可以看出,atan(x)函数只能区分一象限和四象限的点。取一象限和三象限任意一点Ai(ai,bi)计算x=bi/ai,x均为正值。对于二象限和四象限则均为负值。

3.example

输出值为45

/* atan example */
#include <stdio.h>      /* printf */
#include <math.h>       /* atan */

#define PI 3.14159265

int main ()
{
  double param, result;
  param = 1.0;
  result = atan (param) * 180 / PI;
  printf ("The arc tangent of %f is %f degrees\n", param, result );
  return 0;
}

二、atan2()函数

1.输入要求

double atan2 (double y , double x);
float atan2 (float y , float x);
long double atan2 (long double y , long double x);
double atan2 (Type1 y , Type2 x);       // additional overloads

2.输出范围

atan2(x)函数返回以弧度为单位的角度,范围为[-pi,+pi],包含-pi和+pi的。函数内部考虑了参数x,y 的符号。所以可以区分坐标点在哪个象限。

3.example

输出值为135

/* atan example */
#include <stdio.h>      /* printf */
#include <math.h>       /* atan */

#define PI 3.14159265

int main ()
{
  double param, result;
  param = 1.0;
  result = atan (param) * 180 / PI;
  printf ("The arc tangent of %f is %f degrees\n", param, result );
  return 0;
}

参考链接

cplusplus.com/reference/cmath/atan/

cplusplus.com/reference/cmath/atan2/

C++中atan()与atan2()的区别和用法_c++ atan atan2-CSDN博客

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值