为防止广告,目前nocow只有登录用户能够创建新页面。如要创建页面请先登录/注册(新用户需要等待1个小时才能正常使用该功能)。

Sgu/120

来自NOCOW
< Sgu
跳转到: 导航, 搜索

先通过正弦定理算出顶点到中心的距离r,通过相似算出中心o的坐标。算出点N1和中心的角度phi,即可算出每个点和中心的差角delta,得出每个点的坐标。代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define dis(a, b) sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y))
typedef struct { double x, y; } point;
const double pi = 3.1415926535897932384626;
 
double r, phi, delta;
point v[151], mid, o;
int N, a, b;
 
int main()
{
    scanf("%d %d %d", &N, &a, &b);
    scanf("%lf %lf %lf %lf", &v[a].x, &v[a].y, &v[b].x, &v[b].y);
    if (a > b) swap(a, b);
    r = dis(v[a], v[b]) / sin(pi * (b - a) / N) / 2;
    mid.x = (v[a].x + v[b].x) / 2;
    mid.y = (v[a].y + v[b].y) / 2;
    o.x = mid.x + (v[b].y - v[a].y) / tan(pi * (b - a) / N) / 2;
    o.y = mid.y - (v[b].x - v[a].x) / tan(pi * (b - a) / N) / 2;
    phi = asin((v[a].y - o.y) / r);
    if (acos((v[a].x - o.x) / r) > pi / 2)
       if (phi >= -1e10) phi = pi - phi;
          else           phi = -pi - phi;
    for (int i = 1; i <= N; ++i)
        if (i != a && i != b)
        {
           delta = phi + 2 * pi * (a - i) / N;
           v[i].x = o.x + r * cos(delta);
           v[i].y = o.y + r * sin(delta);
        }
    for (int i = 1; i <= N; ++i)
        printf("%.6lf %.6lf\n", v[i].x, v[i].y);
    return 0;
}
// From FingerSed
/by Logic
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int maxn=200;
const double PI=acos(-1.0),eps=1e-10;
int n,n1,n2;
double r,ang;
struct Point
{
	double x,y;
	void scan() { scanf("%lf%lf",&x,&y); }
	void print() { printf("%lf %lf\n",x,y);	}
};
typedef Point Vector;
Point O,p1,p2;
Vector seg[maxn]; 
Vector operator + (Point A,Point B) { return (Vector){A.x+B.x,A.y+B.y}; }
Vector operator - (Point A,Point B) { return (Vector){A.x-B.x,A.y-B.y}; }
Vector operator * (Vector A,double k) {	return (Vector){A.x*k,A.y*k}; }
Vector operator / (Vector A,double k) {	return (Vector){A.x/k,A.y/k}; }
double len(Vector A) { return sqrt(A.x*A.x+A.y*A.y); }
Vector rot(Vector A,double rad)
{
	return (Vector){A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad)};
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("data.in","r",stdin);
#endif
	int i,j;
	double ang0;
	Vector t;
	scanf("%d%d%d",&n,&n1,&n2);
	p1.scan(),p2.scan();
	ang=PI*2/n;
	ang0=ang*(n2-n1)/2;
	t=p2-p1;
	r=len(t)/2/sin(ang0);
	Vector R=rot(t,PI*3/2);
	O=(p2+p1)/2+R*r*cos(ang0)/len(R);
	seg[n1-1]=p1-O;
	for(i=0;i<n;i++)
		seg[(n1-i-2+n)%n]=rot(seg[(n1-i-1+n)%n],ang);
	for(i=0;i<n;i++)
		(O+seg[i]).print();
	return 0;
}
个人工具