题意:给出两个点在两个坐标系中的坐标,求两个坐标系的夹角。
思路:只要求出一这两个点为向量在两个坐标系(即两个向量的夹角)
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const double PI = 3.14159265358; struct node { double x,y,w; }a[1005]; bool cmp(node b1,node b2) { return b1.w < b2.w; } double fin(double x1,double y1,double x2,double y2)//求向量夹角 { double t=(x1*x2+y1*y2)/(sqrt(x1*x1+y1*y1)*sqrt(x2*x2+y2*y2)); double ret = acos(t); return ret*180/PI; } int main() { int T,n,i; scanf("%d",&T); while(T--) { scanf("%d",&n); for(i = 0; i < n; i++) scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].w); sort(a,a+n,cmp); double x1,x2,y1,y2; scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); x1 = x2 - x1; y1 = y2 - y1; x2 = a[1].x - a[0].x; y2 = a[1].y - a[0].y; printf("%.3lf\n",fin(x1,y1,x2,y2)); } return 0; }