当题意就是一个物体每次绕着一个点旋转一个角度,旋转n次后等价于从开始状态绕一个点旋转一定角度后直接到达最终状态。求这个点的坐标和旋转角度。
当时做的时候就自己yy了一个做法就在那搞,,没想到居然过了,现在来看我都有点佩服自己当时是怎么想的了。
#include<stdio.h>
#include<math.h>
#define PI 3.1415926535
struct s
{
double xx,yy;
};
s f1(s l,s r,double p0)
{
s temp;
l.xx-=r.xx;
l.yy-=r.yy;
temp.xx=l.xx*cos(p0)-l.yy*sin(p0);
temp.yy=l.xx*sin(p0)+l.yy*cos(p0);
temp.xx+=r.xx;
temp.yy+=r.yy;
return temp;
}
int main()
{
int n,T;
double z,ans,x,y,le;
s k,t,r,mid,con;
scanf("%d",&T);
while(T--)
{
t.xx=0;
t.yy=110;
ans=0;
scanf("%d",&n);
while(n--)
{
scanf("%lf%lf%lf",&k.xx,&k.yy,&z);
ans+=z;
if(ans>=2*PI)
ans-=2*PI;
t=f1(t,k,z);
}
mid.xx=(t.xx)/2;
mid.yy=(t.yy+110)/2;
if(t.xx==0)
{
con.yy=mid.yy;
con.xx=( t.xx+(110-con.yy)*sin(ans) )/(1-cos(ans)) ;
}
else if(t.yy==110)
{
con.xx=mid.xx;
con.yy=(t.yy+con.xx*sin(ans) )/(cos(ans)+1 );
}
else
{
le=(t.yy-110)/(t.xx);
// printf("%lf\n",le);
double b=mid.yy+mid.xx/le;
le=-1*(1/le);
// printf("%lf %lf\n",le,b);
con.xx=(-1*t.xx-(110-b)*sin(ans))/(cos(ans)-1-sin(ans)*le);
con.yy=le*con.xx+b;
}
printf("%.10lf %.10lf %.10lf\n",con.xx,con.yy,ans);
}
return 0;
}