题意:给出n次旋转(包括旋转中心与旋转角度),求与这n次等价的旋转中心与旋转角度
方法:引入任意两点,利用向量旋转公式,求得最终的点,然后利用直线相交求圆心,圆心出来了,角度也就出来了。
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
const int N=505;
const double pi=acos(-1.0);
struct point{
double x,y;
point(double _x=0,double _y=0):x(_x),y(_y){}
point operator *(double m){
return point(x*m,y*m);
}
point operator +(point m){
return point(x+m.x,y+m.y);
}
point operator - (point m){
return point(x-m.x,y-m.y);
}
void out(){
printf("(%.3lf,%.3lf)\n",x,y);
}
}P;
double cross(point A,point B){
return A.x*B.y-A.y*B.x;
}
point rotate(point m,double rad){
return point(m.x*cos(rad)-m.y*sin(rad),m.x*sin(rad)+m.y*cos(rad));
}
typedef point Vector;
point getlineintersection(point p,Vector v,point q,Vector w){
Vector u=p-q;
double t=cross(w,u)/cross(v,w);
return p+v*t;
}
Vector normal(Vector A){
return Vector(-A.y,A.x);
}
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));
}
int n;
void work(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
point A(0,0),B(-1,0);
point AA(0,0),BB(-1,0);
//point temp;
double x,y,z;
for(int i=0;i<n;i++){
scanf("%lf%lf%lf",&P.x,&P.y,&z);
// temp=A-P;
// temp=rotate(temp,z);
// printf("(%.3lf,,%.3lf),,\n",temp.x,temp.y);
A=rotate(A-P,z)+P;
B=rotate(B-P,z)+P;
//A.out();B.out();
}
point C=A*0.5,D=(BB+B)*0.5;
point O=getlineintersection(C,normal(A-AA),D,normal(B-BB));
double ans=angle(AA-O,A-O);
if(cross(AA-O,A-O)>=0)
printf("%.10lf %.10lf %.10lf\n",O.x,O.y,ans);
else printf("%.10lf %.10lf %.10lf\n",O.x,O.y,2.0*pi-ans);
}
}
int main(){
freopen("data_in.txt","r",stdin);
work();
return 0;
}