就计算几何向量旋转什么的搞搞搞就OK了
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 155;
const double pi = acos(-1.0);
int n, n1, n2;
struct Point {
double x, y;
int id;
Point() {}
Point(double x, double y) {
this->x = x;
this->y = y;
}
} p1, p2, ans[N];
bool cmpid(Point a, Point b) {
return a.id < b.id;
}
typedef Point Vector;
Vector operator + (Vector A, Vector B) {
return Vector(A.x + B.x, A.y + B.y);
}
Vector operator - (Vector A, Vector B) {
return Vector(A.x - B.x, A.y - B.y);
}
Vector operator * (Vector A, double p) {
return Vector(A.x * p, A.y * p);
}
Vector operator / (Vector A, double p) {
return Vector(A.x / p, A.y / p);
}
Vector Rotate(Vector A, double rad) {
return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));
}
double Dot(Vector A, Vector B) {return A.x * B.x + A.y * B.y;} //点积
double Length(Vector A) {return sqrt(Dot(A, A));} //向量的模
int main() {
while (~scanf("%d%d%d", &n, &n1, &n2)) {
scanf("%lf%lf%lf%lf", &p1.x, &p1.y, &p2.x, &p2.y);
if (n1 > n2) {
swap(n1, n2);
swap(p1, p2);
}
double d1 = 2 * pi / n;
double d2 = (n2 - n1) * d1;
double flag = -1;
if (d2 > pi) {
d2 = 2 * pi - d2;
flag *= -1;
}
double d3 = (pi - d2) / 2;
double d4 = (pi - d1) / 2 + flag * d3;
double dis1 = Length(p2 - p1);
double dis2;
if (d2 > pi || d2 < pi) dis2 = dis1 / sin(d2) * sin(d3);
else dis2 = dis1 / 2;
double dis3 = dis2 / sin((pi - d1) / 2) * sin(d1);
Vector v = Rotate((p2 - p1) / dis1 * dis3, d4);
int s = n1;
double d = pi * (n - 2) / n;
for (int i = 0; i < n; i++) {
ans[i] = p1;
ans[i].id = s;
p1 = p1 + v;
v = Rotate(v, -(pi - d));
s++; if (s > n) s -=n;
}
sort(ans, ans + n, cmpid);
for (int i = 0; i < n; i++)
printf("%.6f %.6f\n", ans[i].x, ans[i].y);
}
return 0;
}