SGU 120 SGU 228 Archipelago(計算幾何)
Description:
Archipelago Ber-Islands consists of islands that are vertices of equiangular and equilateral -gon. Islands are clockwise numerated. Coordinates of island are , and island . Your task is to find coordinates of all islands.
Input:
In the first line of input there are and separated by spaces. On the next two lines of input there are coordinates of island and (one pair per line) with accuracy digits after decimal point. Each coordinate is more than and less than.
Output:
Write lines with coordinates for every island. Write coordinates in order of island numeration. Write answer with digits after decimal point.
Sample Input:
4 1 3
1.0000 0.0000
1.0000 2.0000
Sample Output:
1.000000 0.000000
0.000000 1.000000
1.000000 2.000000
2.000000 1.000000
題目連結
給出正 邊形第 和 個點,求多邊形所有點
現求出正多邊形重心 ,之後將向量 旋轉 次即可求出正多邊形的所有點
先求出 旋轉到 所需角度 進行旋轉,之後將其向量長度改變為 即可求出正多邊形重心
#include <bits/stdc++.h>
using namespace std;
typedef double db;
const int maxn = 2e2 + 5;
const db eps = 1e-8;
const db pi = acos(-1.0);
int Sgn(db Key) {return fabs(Key) < eps ? 0 : (Key < 0 ? -1 : 1);}
int Cmp(db Key1, db Key2) {return Sgn(Key1 - Key2);}
db Format(db Key) {return Sgn(Key) == 0 ? (db)0 : Key;}
struct Point {db X, Y;};
typedef Point Vector;
bool operator == (Point Key1, Point Key2) {return Cmp(Key1.X, Key2.X) == 0 && Cmp(Key1.Y, Key2.Y) == 0;}
Vector operator - (Vector Key1, Vector Key2) {return (Vector){Key1.X - Key2.X, Key1.Y - Key2.Y};}
Vector operator + (Vector Key1, Vector Key2) {return (Vector){Key1.X + Key2.X, Key1.Y + Key2.Y};}
db operator * (Vector Key1, Vector Key2) {return Key1.X * Key2.X + Key1.Y * Key2.Y;}
db operator ^ (Vector Key1, Vector Key2) {return Key1.X * Key2.Y - Key1.Y * Key2.X;}
Vector operator * (Vector Key1, db Key2) {return (Vector){Key1.X * Key2, Key1.Y * Key2};}
Vector operator / (Vector Key1, db Key2) {return (Vector){Key1.X / Key2, Key1.Y / Key2};}
db GetLen(Vector Key) {return sqrt(Key * Key);}
db DisPointToPoint(Point Key1, Point Key2) {return GetLen(Key2 - Key1);}
Point Rotate(Point Key, db Angle) {return (Point){Key.X * cos(Angle) - Key.Y * sin(Angle),Key.X * sin(Angle) + Key.Y * cos(Angle)};}
Vector Rotate90(Vector Key) {return (Vector){-Key.Y, Key.X};}
struct Line {Point S, T;};
typedef Line Segment;
Point Cross(Line Key1, Line Key2) {
db Temp = ((Key1.S - Key2.S) ^ (Key2.S - Key2.T)) / ((Key1.S - Key1.T) ^ (Key2.S - Key2.T));
return (Point){Key1.S.X + (Key1.T.X - Key1.S.X) * Temp, Key1.S.Y + (Key1.T.Y - Key1.S.Y) * Temp};
}
int N, N1, N2;
db Angle, Rad;
Point points[maxn];
Point Center;
int main(int argc, char *argv[]) {
scanf("%d%d%d", &N, &N1, &N2);
scanf("%lf%lf", &points[N1].X, &points[N1].Y);
scanf("%lf%lf", &points[N2].X, &points[N2].Y);
if (N1 > N2) swap(N1, N2);
Rad = (pi - (db)min(N2 - N1, N + N1 - N2) * 2.0 * pi / (db)N) / 2.0;
if (N2 - N1 == N + N1 - N2) Center = (points[N1] + points[N2]) / 2.0;
else if (N2 - N1 < N + N1 - N2) Center = Rotate(points[N2] - points[N1], -Rad) / 2.0 / cos(Rad) + points[N1];
else Center = Rotate(points[N2] - points[N1], Rad) / 2.0 / cos(Rad) + points[N1];
int Cur = (N1 - 1) == 0 ? N : (N1 - 1), k = 1; Angle = 2.0 * pi / (db)N;
while (Cur != N1) {
if (Cur == N2) {
Cur--; k++;
if (Cur == 0) Cur = N;
continue;
}
points[Cur] = Rotate(points[N1] - Center, Angle * (db)k) + Center;
Cur--; k++;
if (Cur == 0) Cur = N;
}
for (int i = 1; i <= N; ++i) printf("%.6lf %.6lf\n", Format(points[i].X), Format(points[i].Y));
return 0;
}
相關文章
- SGU 124 Broken line(計算幾何)
- SGU 110 Dungeon(立體幾何)
- SGU 505
- SGU 208 Toral Tickets(polay計數)
- SGU 277 Heroes(動態凸包維護)
- 計算幾何
- 計算幾何:模板
- 計算幾何模板
- Something about 計算幾何
- [筆記] 計算幾何筆記
- 計算幾何 —— 二維幾何基礎 —— 距離度量方法
- 計算幾何——平面最近點對
- POJ - 1556 【計算幾何 + 最短路】
- 【學習筆記】計算幾何筆記
- 邊緣計算、霧計算、雲端計算區別幾何?
- BNUOJ 12887 isumi(計算幾何+最大流)
- 計算幾何(一):凸包問題(Convex Hull)
- POJ 1113 Wall(思維 計算幾何 數學)
- HNOI2016礦區(計算幾何+對偶圖)
- 計算機視覺—圖片幾何變換(2)計算機視覺
- CodeForces 887 E. Little Brother(計算幾何+二分)
- [計算幾何]圓與三角形是否相交
- 百度造車,勝算幾何?
- [幾何]計算不規則多邊形的面積、中心、重心
- 【第一道計算幾何題】 UVA11178 Morley‘s Theorem (二維幾何,旋轉直線求求交點)REM
- 丘成桐演講全文:幾何與計算數學的關係
- 【IDL】幾何圖形數學運算函式函式
- 平面幾何
- 神奇的周幾計算器
- 228. Summary Ranges
- sql server 計算兩個時間 相差的 幾天幾時幾分幾秒SQLServer
- 《戴森球計劃》火了,“科幻遊戲”前途幾何?遊戲
- 恆訊科技分析:使用邊緣計算和雲端計算各有何優勢?
- 計算檔案Checksum的幾種方法
- 阿里美團戰事再升級:支付寶入局 勝算幾何?阿里
- 邊緣計算為何會如此受歡迎?
- [計算機網路] - 從英雄聯盟,看資料包何去何從?計算機網路
- 在量子計算時代,企業資料的加密該何去何從?加密