typedef struct point {
double x, y;
}point;
//给定两个点
point a(x1,y1),b(x2,y2);
  1. 使用反三角函数atan求斜率,原型如下
float       atan( float arg );
double atan( double arg );
long double atan( long double arg );
double atan( Integral arg );
double angle=atan((y2-y1)/(x2-x1));

返回值

若不出现错误,则返回 arg 在$ [- π/2 ; +π/2]$ 弧度范围中的弧(反)正切( $arctan(arg) $)。值域有限,一四象限,斜率不存在不能求

2. 使用反三角函数atan2求斜率,原型如下

float       atan2( float y, float x );
double atan2( double y, double x );
long double atan2( long double y, long double x );
Promoted atan2( Arithmetic1 y, Arithmetic2 x );

返回值

若不出现错误,则返回 y/x 在 $(-π ; +π] $弧度范围中的弧(反)正切( arctan(y/x) )。值域扩展到四个象限。

atan2(y,x)所表达的意思是坐标原点为起点,指向(y,x)的射线x轴正方向形成角的角度。在x=0的时候:

1.当y>0时,指的是绕逆时针到达射线所旋转的角的角度;

2.而当y<0时,指的是绕顺时针达到射线所旋转的角的角度。

这样就可以求两个点表示的线段(向量)和x轴正向的角度,如下

double angle=atan2((y2-y1),(x2-x1));

最新文章

  1. JS ECMAScript 5中的every 和 some方法进行逻辑判断
  2. DBUtils
  3. js算出生日是当年第多少天
  4. 【转载】Lucene.Net入门教程及示例
  5. JAVA中保留指定小数位方法
  6. rspec+rest-client测试第三方web service
  7. Android启停调试
  8. iOS:FFmpeg视频播放和直播框架
  9. hdu 5438 Ponds dfs
  10. 4.html5中超链接
  11. (转)log4j:WARN No appenders could be found for logger 解决方案
  12. MVC小系列(七)【分部视图中的POST】
  13. UltraEdit v17.10.0,注册机,注册码
  14. Android 中 GridView 常用属性合集
  15. Springboot 项目启动后执行某些自定义代码
  16. loadrunner&#160;脚本优化-参数化之场景中的参数化取值
  17. java 数组转字符串 字符串转数组
  18. var/let/const区别何在??(转载)
  19. ios 清除缓存文件
  20. 一个复杂Json的解析

热门文章

  1. Python pip windows安装
  2. git的commit规范及强制校验
  3. canvas的getImageData和putImageDataAPI
  4. MFCdll的两种调用方法
  5. 菜鸟学习Spring——SpringMVC注解版解析不同格式的JSON串
  6. mac 上配置 maven
  7. (四)svn 服务器端的使用之创建工程目录
  8. 成功解决:FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is
  9. EM自动任务导致数据库缓慢
  10. Ajax 重构的步骤