Points on Cycle

这次写这个旋转向量法,完全就是套公式x'=xsina-ysina;y'=xsina+ycosa;但是我还是做得很磕磕碰碰,每次输出,把需要的数据输入要结构体或者数组里面都是件难事,让我葛优瘫一下,但是,这次主要还是数学题目所以好理解也好做,不过要注意输出的条件,当y不等输出y小的,否则输出x小的。当然最后还是借鉴了呀。

#include<cstdio>  
#include<cstdlib>  
#include<cstring>  
#include<cmath>  
#include<algorithm>  
#define eps 1e-8  
#define PI acos(-1.0)  
using namespace std;  
struct point{  
    double x,y;  
}p,q;  
int sgn(double n){  
    if(fabs(n)<eps)return 0;  
    if(n<0)return -1;  
    return 1;  
}  
int main()  
{  
    int t,i,j,k;  
    scanf("%d",&t);  
    while(t--){  
        scanf("%lf%lf",&p.x,&p.y);  
        double r=sqrt(p.x*p.x+p.y*p.y);  
        double angle=acos(p.x/r);  
        if(sgn(p.y)<0)angle=2.0*PI-angle;  
        double x1=r*cos(angle+2.0*PI/3.0);  
        double y1=r*sin(angle+2.0*PI/3.0);  
        double x2=r*cos(angle-2.0*PI/3.0);  
        double y2=r*sin(angle-2.0*PI/3.0);  
        if(angle>=PI/2.0&&angle<3.0*PI/2.0)  
            printf("%.3lf %.3lf %.3lf %.3lf
",x1,y1,x2,y2);  
        else   
            printf("%.3lf %.3lf %.3lf %.3lf
",x2,y2,x1,y1);  
    }  
    return 0;  
} 

  

原文地址:https://www.cnblogs.com/yintoki/p/5692384.html