A 多边形与圆
题意
任意凸多边形在圆内滚动,由1号点开始离开到1号点再次滚动到圆内1号点所滚动的弧长是多少?
思路
计算几何
∠k1=acos2Rx[i][i−1]∠k2=acos2Rx[i][i+1]∠i=acos2∗x[i][i−1]∗x[i][i+1]x[i][i−1]2+x[i][i+1]2−x[i−1][i+1]2∠θ=∠k1+∠k2−∠il=∠θ∗x[1][i]
acos返回值为弧度制。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll maxn = 1e6 + 5;
const int N = 200;
ll n,R;
double x[N][N],a[N],b[N],d[N];
double len(int i,int j){
return sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]));
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>R;
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i];
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
x[i][j]=len(i,j);
}
}
double res=0;
for(int i=2;i<=n;i++){
double u=acos(x[i][i-1]/(2.0*R));
double v=acos(x[i][i%n+1]/(2.0*R));
double w=acos(((x[i][i-1])*(x[i][i-1])+(x[i][i%n+1])*(x[i][i%n+1])-(x[i%n+1][i-1])*(x[i%n+1][i-1]))/(2.0*x[i][i-1]*x[i][i%n+1]));
double k=(u+v-w)*x[1][i];
res+=k;
}
printf("%.10lf",res);
return 0;
}