题意:一个平面绕着一些点旋转,输入保证最后的结果是绕着一个确定的点旋转一个角度得到。求这个点和角度
代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const double pi=acos(-1);
struct Point
{
double x,y;
Point(double x=0,double y=0):x(x),y(y){}
};
typedef Point Vector;
Vector operator + (Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}
Vector operator - (Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
Vector operator * (Vector a,double p){return Vector(a.x*p,a.y*p);}
Vector operator / (Vector a,double p){return Vector(a.x/p,a.y/p);}
bool operator < (const Point &a,Point& b)
{
return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
const double eps =1e-9;
int dcmp(double x)
{
if(fabs(x)<eps)return 0;else return x<0?-1:1;
}
bool operator == (const Point& a,const Point &b)
{
return dcmp(a.x-b.x)==0&&dcmp(a.y-b.y)==0;
}
double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
double Length(Vector a){return sqrt(Dot(a,a));}
double Angle(Vector a,Vector b){return acos(Dot(a,b)/Length(a)/Length(b));}
Vector Rotate(Vector a,double rad)
{
return Vector(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}
double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;}
Point GLI(Point p,Vector v,Point q,Vector w)
{
Vector u=p-q;
double t=Cross(w,u)/Cross(v,w);
return p+v*t;
}
int main()
{
//freopen("data.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
Point ss;
double ans=0;
for(int i=0;i<n;++i)
{
Point r;
double p;
scanf("%lf%lf%lf",&r.x,&r.y,&p);
ans+=p;
if(dcmp(ans)==0)ans=0;
if(dcmp(ans-2*pi)==0)ans=2*pi;
if(ans>=2*pi)ans-=2*pi;
if(ans<0)ans+=2*pi;
Vector tmp=ss-r;
tmp=Rotate(tmp,p);
ss=r+tmp;
}
double th=(pi-ans)/2;//得到起点和终点以及旋转角度以后,将起点,终点,要求的点看成一个三角形,解三角形
Point r;
Vector tmp1=r-ss;
Vector tmp2=ss-r;
tmp2=Rotate(tmp2,th);
tmp1=Rotate(tmp1,-th);
r=GLI(r,tmp2,ss,tmp1);
printf("%.5lf %.5lf %.5lf\n",r.x,r.y,ans);
}
return 0;
}