码迷,mamicode.com
首页 > 其他好文 > 详细

计算点与x轴正半轴夹角atan2(double y,double x),返回弧度制(-PI,PI]

时间:2015-12-30 01:54:27      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:

精度比acos , asin 什么的高些。

Parameters

y
Value representing the proportion of the y-coordinate.
x
Value representing the proportion of the x-coordinate.

If both arguments passed are zero, a domain error occurs.

所以使用前只需排除x=y=0的情况

例子:

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

#define PI 3.14159265

int main ()
{
  double x, y, result;
  x = -10.0;
  y = 10.0;
  result = atan2 (y,x) * 180 / PI;
  printf ("The arc tangent for (x=%f, y=%f) is %f degrees\n", x, y, result );
  return 0;
}

结果:

The arc tangent for (x=-10.000000, y=10.000000) is 135.000000 degrees.

返回值为(-PI,PI]的例子

printf("%lf",atan2(0,-1)*180/PI);

输出:180.000000

 

计算点与x轴正半轴夹角atan2(double y,double x),返回弧度制(-PI,PI]

标签:

原文地址:http://www.cnblogs.com/chenhuan001/p/5087574.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!