A --Keiichi Tsuchiya the Drift King
Topic link: Jie Suanke
answer
There are two situations: the first: the curve can completely accommodate the rectangle; the second: the curve cannot completely accommodate the rectangle.
The first is relatively simple, and the Pythagorean theorem can get the result.
The second method needs to be careful. The problem is the width of the curve. According to the first method, the result will be relatively large, so you need to subtract a small amount of excess.
The specific method is shown in the figure:
AC code
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<list>
#include<set>
#include<deque>
#include<vector>
#include<ctime>
using namespace std;
//#pragma GCC optimize(2)
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ull unsigned long long
#define ll long long
#define rep(i, x, y) for(int i=x;i<=y;i++)
#define mms(x, n) memset(x, n, sizeof(x))
#define mmc(A, tree) memcpy(A, tree, sizeof(tree))
#define INF (0x3f3f3f3f)
#define mod (ull)(1e9+7)
const double PI = (acos(-1.0));
typedef pair<int, int> P;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int T;
scanf("%d", &T);
double a, b, r, d;
while (T--) {
scanf("%lf%lf%lf%lf", &a, &b, &r, &d);
double dd = d * PI / 180.0;
double w = sqrt(((a + r) * (a + r)) + b * b);
double t = acos((a + r) / w);
if (t - dd <= 0) {
printf("%.12f\n", w - r);
} else {
double tt = (t - dd);
double c = 2 * w * sin(tt / 2);
tt = (PI - tt) / 2;
double p = c * cos(tt);
printf("%.12f\n", w - p - r);
}
}
return 0;
}