- 题目描述:
在一个平面内有两个点,求两个点分别和原点的连线的夹角的大小。
注:夹角的范围[0,180],两个点不会在圆心出现。
- 思路:
使用数学反三角函数分别求出两点与x轴夹角弧度值,再对弧度值做差,进而求出夹角角度。
- 细节:
对于反三角函数的选择有很多,每一种都可以选择,这里采用的是atan2。既然使用反三角函数,就要有math.h的预处理文件。以及定义点坐标时应使用double定义。
- 源代码:
#include<iostream> #include <math.h> #include<cstdio> using namespace std; #define PI 3.141592653 int main() { double x1,y1,x2,y2,a1,a2,a3; int n; cin>>n; for(int i=0;i<n;i++) { cin>>x1>>y1>>x2>>y2; a1=atan2(y1,x1); a2=atan2(y2,x2); a3=fabs(a1-a2); printf("%.2lf\n",a3*180/PI); } return 0; }