HDU 4998 Rotate 简单几何旋转问题

题意:给出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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值