题意:给出空间中四个点A,B,C,D,现在需要找到满足链接:∣AP1∣≥k1∣BP1∣,∣CP2∣≥k2∣DP2∣的p1和p2两点,求同时满足p1和p2两点的所有点的体积。
所用知识:阿氏圆
思路:二维(百度):
三维:
AC代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const double PI = acos(-1);
struct pos
{
ld x,y,z;
};
int T;
pos p[5];
ld k1,k2;
void calc(pos o1,pos o2,ld r1,ld r2)
{
double ans=0.0;
double dis=sqrt((o1.x-o2.x)*(o1.x-o2.x)+(o1.y-o2.y)*(o1.y-o2.y)+(o1.z-o2.z)*(o1.z-o2.z));
//不相交
if(dis>=r1+r2)
ans=0;
//内含
else if (dis+r1<=r2)
ans=(4.00/3.00)*PI*r1*r1*r1;
else if(dis+r2<=r1)
ans=(4.00/3.00)*PI*r2*r2*r2;
else
{
double cos_r1_dis=(r1*r1+dis*dis-r2*r2)/(2.0*dis*r1);
double h1=r1-r1*cos_r1_dis;
ans+=(1.0/3.0)*PI*h1*h1*(3.0*r1-h1);
double cos_r2_dis=(r2*r2+dis*dis-r1*r1)/(2.0*dis*r2);
double h2=r2-r2*cos_r2_dis;
ans+=(1.0/3.0)*PI*h2*h2*(3.0*r2-h2);
}
printf("%.3f\n",ans);
}
int main()
{
cin>>T;
while(T--)
{
for(int i = 0; i < 4; i++)
cin >> p[i].x >> p[i].y >> p[i].z;
cin>>k1>>k2;
double tmp1=k1*k1-1,tmp2=k2*k2-1;
pos O1,O2;
double r1,r2,D1,D2;
//球1
O1.x=(k1*k1*p[1].x-p[0].x)/tmp1;
O1.y=(k1*k1*p[1].y-p[0].y)/tmp1;
O1.z=(k1*k1*p[1].z-p[0].z)/tmp1;
D1=k1*k1*((p[1].x*p[1].x)+(p[1].y*p[1].y)+(p[1].z*p[1].z))-p[0].x*p[0].x-p[0].y*p[0].y-p[0].z*p[0].z;
D1/=tmp1;
r1=sqrt(O1.x*O1.x+O1.y*O1.y+O1.z*O1.z-D1);
//球2
O2.x=(k2*k2*p[3].x-p[2].x)/tmp2;
O2.y=(k2*k2*p[3].y-p[2].y)/tmp2;
O2.z=(k2*k2*p[3].z-p[2].z)/tmp2;
D2=k2*k2*(p[3].x*p[3].x+p[3].y*p[3].y+p[3].z*p[3].z)-p[2].x*p[2].x-p[2].y*p[2].y-p[2].z*p[2].z;
D2/=tmp2;
r2=sqrt(O2.x*O2.x+O2.y*O2.y+O2.z*O2.z-D2);
//printf("o1: %lf %lf %lf r1= %lf\n",O1.x,O1.y,O1.z,r1);
//printf("o2: %lf %lf %lf r2= %lf\n",O2.x,O2.y,O2.z,r2);
calc(O1,O2,r1,r2);
}
return 0;
}