sgu 120 分类: sgu 2015-02-09 17:19 106人阅读 评论(0) 收藏

sgu120

题意:给出正n边形的两个点(x1,y1),(x2,y2),求正n边形所有点坐标


首先要知道

向量(x,y)逆时针旋转a(rad)得到(x,y)
有这样一个关系>
x=xcos(a)ysin(a)
y=xsin(a)+ycos(a)
证明:
x轴旋转到向量(x,y)的角为b(rad)(x,y)长度为L

有>
x=Lcos(b)
y=Lsin(b)

x=Lcos(a+b)
y=Lsin(a+b)

而>
cos(a+b)=cos(a)cos(b)sin(a)sin(b)
sin(a+b)=sin(a)cos(b)+cos(a)sin(b)

推得>
x=xcos(a)ysin(a)
y=xsin(a)+ycos(a)


解法:
套公式,列方程,解出正n边形中心O点坐标
然后用向量解出其他每个点的坐标

因为是保留6位小数,所以还要特判 -0.000000 的情况



计算几何就是。。。唉不说了,说起来满满都是泪

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define eps 0.0000001

struct node{double x,y;int s;}n1,n2,f,f1,ans;
int n;

double p,q;
double pi;
double a,b;

int main()
{
    int i;

    #ifndef ONLINE_JUDGE
    freopen("sgu120.in","r",stdin);
    freopen("sgu120.out","w",stdout); 
    #endif

    scanf("%d%d%d",&n,&n1.s,&n2.s);

    scanf("%lf%lf",&n1.x,&n1.y);
    scanf("%lf%lf",&n2.x,&n2.y);

    pi=acos(-1);

    a=((double)n2.s-n1.s)/n*pi*2;

    p=n1.x-n2.x*cos(a)+n2.y*sin(a);
    q=n1.y-n2.x*sin(a)-n2.y*cos(a);

    f.x=(p*((double)1-cos(a))-q*sin(a))/((double)1-cos(a))/2;
    f.y=(p*sin(a)+q*((double)1-cos(a)))/((double)1-cos(a))/2;

    b=((double)n1.s-1)/n*pi*2;

    f1.x=(n1.x-f.x)*cos(b)-(n1.y-f.y)*sin(b);
    f1.y=(n1.x-f.x)*sin(b)+(n1.y-f.y)*cos(b);

    for(i=1;i<=n;i++)
    {
        b=((double)1-i)/n*pi*2;

        ans.x=f1.x*cos(b)-f1.y*sin(b)+f.x;
        ans.y=f1.x*sin(b)+f1.y*cos(b)+f.y;

        if(fabs(ans.x)<eps)
            printf("0.000000 ");
        else
            printf("%.6lf ",ans.x);

        if(fabs(ans.y)<eps)
            printf("0.000000\n");
        else
            printf("%.6lf\n",ans.y);

    }


    #ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
    #endif
    return 0;
}

话说这编辑器真好玩^_^

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2015-02-09 17:19  <Dash>  阅读(199)  评论(0编辑  收藏  举报