zoukankan      html  css  js  c++  java
  • hdu4998 Rotate 计算几何

    Noting is more interesting than rotation!

    Your little sister likes to rotate things. To put it easier to analyze, your sister makes n rotations. In the i-th time, she makes everything in the plane rotate counter-clockwisely around a point ai by a radian of pi.

    Now she promises that the total effect of her rotations is a single rotation around a point A by radian P (this means the sum of pi is not a multiplier of 2π).

    Of course, you should be able to figure out what is A and P :).

     

    计算几何

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<cmath>
     6 using namespace std;
     7 const double eps=1e-8;
     8 const double pi=acos(-1.0);
     9 
    10 int sgn(double x){
    11     if(fabs(x)<eps) return 0;
    12     if(x<0) return -1;
    13     else return 1;
    14 }
    15 
    16 struct Point{
    17     double x,y;
    18     Point(){}
    19     Point(double _x,double _y){
    20         x=_x;
    21         y=_y;
    22     }
    23     Point operator -(const Point &b)const{
    24         return Point(x-b.x,y-b.y);
    25     }
    26     double operator ^(const Point &b)const{
    27         return x*b.y-y*b.x;
    28     }
    29     double operator *(const Point &b)const{
    30         return x*b.x+y*b.y;
    31     }
    32     Point operator +(const Point &b)const{
    33         return Point(x+b.x,y+b.y);
    34     }
    35     Point operator *(const double &k)const{
    36         return Point(x*k,y*k);
    37     }
    38     Point operator /(const double &k)const{
    39         return Point(x/k,y/k);
    40     }
    41     Point rotate(Point p,double angle){
    42         Point v=(*this)-p;
    43         double c=cos(angle),s=sin(angle);
    44         return Point(p.x+v.x*c-v.y*s,p.y+v.x*s+v.y*c);
    45     }
    46     double len2(){
    47         return x*x+y*y;
    48     }
    49 };
    50 
    51 struct Line{
    52     Point s,e;
    53     Line(){}
    54     Line(Point _s,Point _e){
    55         s=_s;
    56         e=_e;
    57     }
    58     Point crosspoint(Line v){
    59         double a1=(v.e-v.s)^(s-v.s);
    60         double a2=(v.e-v.s)^(e-v.s);
    61         return Point((s.x*a2-e.x*a1)/(a2-a1),(s.y*a2-e.y*a1)/(a2-a1));
    62     }
    63     Point lineprog(Point p){
    64         return s+( ((e-s)*((e-s)*(p-s)))/((e-s).len2()) );
    65     }
    66 };
    67 
    68 void solve(){
    69     int n,i;
    70     double x,y,p,nx,ny,np;
    71     Point a,b,c,d,e,f,g;
    72     Line l1,l2,l3,l4;
    73     scanf("%d",&n);
    74     scanf("%lf%lf%lf",&nx,&ny,&np);
    75     for(i=2;i<=n;i++){
    76         scanf("%lf%lf%lf",&x,&y,&p);
    77         a=Point(nx,ny);b=Point(x,y);
    78         d=a.rotate(b,p);c=b.rotate(a,-np);
    79         l1=Line(c,b);l2=Line(a,d);
    80         e=l1.lineprog(a);f=l2.lineprog(b);
    81         l3=Line(a,e);l4=Line(b,f);
    82         g=l3.crosspoint(l4);
    83         nx=g.x;ny=g.y;
    84         np=np+p;
    85         if(np>2*pi) np-=2*pi;
    86     }
    87     printf("%lf %lf %lf
    ",nx,ny,np);
    88 }
    89 
    90 int main(){
    91     int t;
    92     scanf("%d",&t);
    93     while(t)solve();
    94     return 0;
    95 }
    View Code
  • 相关阅读:
    vector常规用法(leedcode)
    creaor小游戏数据表配置引发的相关问题
    cocos2dx conversion to dalvik format failed
    Java中如何实现列表对象(List)的灵活查找?/java中Listgen根据某个元素获取对象
    MySql忘记root用户密码
    命令行模式下备份和恢复mysql数据库
    mysql开启日志
    Python操作Excel文件
    Python操作Json文件
    Python操作xml文件
  • 原文地址:https://www.cnblogs.com/cenariusxz/p/6598629.html
Copyright © 2011-2022 走看看