Rotate

hdu4998:http://acm.hdu.edu.cn/showproblem.php?pid=4998

题意:给你n个点,以及绕每个点旋转的弧度。然后,问你经过这n次旋转,平面中的点总的效果是相当于哪个点旋转了多少弧度。

题解:我的第一道计算几何。可以选两个点,求出旋转之后的对应点,然后分别求出这两个点的中垂线,中垂线的交点就是要求的点,弧度就是所有弧度之和mod(2*pi)

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
const double pi=3.14159265;
using namespace std;
int n;
struct Point{
double x;
double y;
double s;
}num[];
struct LINE{
double a,b,c;
Point s;
};
Point HHH(Point o,double alpha,Point p) {//点p绕着o旋转alpha弧度
Point tp;
p.x-=o.x;
p.y-=o.y;
tp.x=p.x*cos(alpha)-p.y*sin(alpha)+o.x;
tp.y=p.y*cos(alpha)+p.x*sin(alpha)+o.y;
return tp;
}
bool CCC(LINE l1,LINE l2,Point&p){//两条直线是否相交,如果相交,则交点为p
double d=l1.a*l2.b-l2.a*l1.b;
if(abs(d)<1e-) return false;
p.x = (l2.c*l1.b-l1.c*l2.b)/d;
p.y = (l2.a*l1.c-l1.a*l2.c)/d;
return true;
}
LINE DDD(const Point &_a, const Point &_b){//求两点之间垂直平分线
LINE ret;
ret.s.x = (_a.x + _b.x)/;
ret.s.y = (_a.y + _b.y)/;
ret.a = _b.x - _a.x;
ret.b = _b.y - _a.y;
ret.c = (_a.y - _b.y) * ret.s.y + (_a.x - _b.x) * ret.s.x;
return ret;
} LINE EEE(Point a,Point b){//求经过两点的中垂线
LINE ret;
if(abs(a.x-b.x)<1e-){
ret.a=;
ret.b=;
ret.c=-a.x;
return ret;
}
ret.a=a.y-b.y;
ret.b=b.x-a.x;
ret.c=a.x*b.y-a.y*b.x;
return ret;
}
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
double sum=;
for(int i=;i<=n;i++){
scanf("%lf%lf%lf",&num[i].x,&num[i].y,&num[i].s);
sum+=num[i].s;
}
Point s1,s2;
s1.x=2.345,s1.y=4.123;
s2.x=11.345,s2.y=12.123;
Point t1=s1,t2=s2;
for(int i=;i<=n;i++){
Point temp=HHH(num[i],num[i].s,t1);
t1=temp;
}
for(int i=;i<=n;i++){
Point temp=HHH(num[i],num[i].s,t2);
t2=temp;
}
LINE one1=DDD(s1,t1);
LINE one2=DDD(s2,t2);
Point a;
if(CCC(one1,one2,a)){
if(sum>*pi)
sum-=*pi;
printf("%lf %lf %lf\n",a.x,a.y,sum);
}
else{
LINE ttt=EEE(s1,s2);
CCC(one1,ttt,a);
if(sum>*pi)
sum-=*pi;
printf("%lf %lf %lf\n",a.x,a.y,sum);
}
}
}
上一篇:dsadm-dsconf数据导入导出


下一篇:Python内置函数(18)——bin