要你先求出此正多邊形的中心,再不斷的瞬時針旋轉求答案。
--------------------------------------------------------------------------------------------------------------------
當你逆時針旋轉角,則向量(x, y)會變成下圖:
透過上式,可以解二元一次方程式求出中心
再來因為他是要瞬時針旋轉,記得要改成負的
然後Pi值要精準,因為 x, y 都很大(Pi = 3.1415926535897932384626)
//By momo
#include<cstdio>
#include<cmath>
#include<algorithm>
#define N 200
#define EPS 1e-9
#define Pi (3.1415926535897932384626)
using namespace std;
int n, a, b;
double ansx[N], ansy[N];
void find(double a1, double b1, double c1, double a2, double b2, double c2, double& x, double& y){
x = (b2*c1-b1*c2) / (a1*b2-a2*b1);
y = (a2*c1-a1*c2) / (a2*b1-a1*b2);
}
int main(){
double x, y, x1, y1, x2, y2;
scanf("%d%d%d", &n, &a, &b);
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
if(a > b) b += n;
double theta = 2.0 * Pi * (b-a) / n;
double phi = 2.0 * Pi * (-1) / n;
double sn = sin(theta), cs = cos(theta);
double snp = sin( phi), csp = cos( phi);
find(cs-1, sn, x1*cs+y1*sn-x2, -sn, cs-1, y1*cs-x1*sn-y2, x, y);
double xi = x1-x, yi = y1-y;
for(int i = 0; i < n; i++){
int pos = (a+i-1) % n;
ansx[pos] = xi+x; ansy[pos] = yi+y;
double nx = xi * csp - yi * snp;
double ny = yi * csp + xi * snp;
xi = nx, yi = ny;
}
for(int i = 0; i < n; i++) printf("%.6lf %.6lf\n", ansx[i]+EPS, ansy[i]+EPS);
}
#include<cstdio>
#include<cmath>
#include<algorithm>
#define N 200
#define EPS 1e-9
#define Pi (3.1415926535897932384626)
using namespace std;
int n, a, b;
double ansx[N], ansy[N];
void find(double a1, double b1, double c1, double a2, double b2, double c2, double& x, double& y){
x = (b2*c1-b1*c2) / (a1*b2-a2*b1);
y = (a2*c1-a1*c2) / (a2*b1-a1*b2);
}
int main(){
double x, y, x1, y1, x2, y2;
scanf("%d%d%d", &n, &a, &b);
scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
if(a > b) b += n;
double theta = 2.0 * Pi * (b-a) / n;
double phi = 2.0 * Pi * (-1) / n;
double sn = sin(theta), cs = cos(theta);
double snp = sin( phi), csp = cos( phi);
find(cs-1, sn, x1*cs+y1*sn-x2, -sn, cs-1, y1*cs-x1*sn-y2, x, y);
double xi = x1-x, yi = y1-y;
for(int i = 0; i < n; i++){
int pos = (a+i-1) % n;
ansx[pos] = xi+x; ansy[pos] = yi+y;
double nx = xi * csp - yi * snp;
double ny = yi * csp + xi * snp;
xi = nx, yi = ny;
}
for(int i = 0; i < n; i++) printf("%.6lf %.6lf\n", ansx[i]+EPS, ansy[i]+EPS);
}
沒有留言:
張貼留言