题目链接:https://nanti.jisuanke.com/t/39270
圆参数: x y r;
点参数: x1 y1;
分两种情况:一种是x1>=x+r,此时两点距离为 直线加四分之一的圆弧
另一种就是:从点到圆上的切线距离,加’两段‘圆弧
具体看代码,画画图,挺容易的。
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define JD(x) setprecision(x)
const double PI = acos(-1.0);
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
priority_queue<int, vector<int>, greater<int> >q;
int s[maxn];
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int t;cin>>t;
while(t--){
double x,y,r,x1,y1;
cin>>x>>y>>r>>x1>>y1;
if(x1<x){
x1=x+x-x1;
}
double h=0.25*2*PI*r;
if(x1>=x+r){
int tempx=x+r;
printf("%.4f\n",(h+sqrt((x1-tempx)*(x1-tempx)+(y1-y)*(y1-y))));
}
else{
double temp1=atan((x1-x)/(y1-y));
double temp2=acos((r)/sqrt((x1-x)*(x1-x) + (y1-y)*(y1-y)));
printf("%.4f\n",h+sqrt( (x1-x)*(x1-x) + (y1-y)*(y1-y)- r*r)+(PI/2.0-temp1-temp2)*r);
}
}
return 0;
}