题目连接:点击进入
题目
题意
A、B、C、D、k1、k2 已知,根据不等式, P1 的取值会形成一个图形,P2 类似,求两个图形的交
思路
这个式子取等号是阿波罗尼斯圆,二维平面是圆,三维是球壳,取不等式就变成了实心球,所以就变成了两个球求相交体积。
对式子带入,计算,化简(貌似这里,,,跟知不知道阿波罗尼斯圆没什么关系?!)
备注:公式图片来自于here
代码(模板偷自刘爷)
//#pragma GCC optimize(3)//O3
//#pragma GCC optimize(2)//O2
#include<iostream>
#include<string>
#include<map>
#include<set>
//#include<unordered_map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<fstream>
#define X first
#define Y second
#define best 131
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define lowbit(x) x & -x
#define inf 0x3f3f3f3f
//#define int long long
//#define double long double
//#define rep(i,x,y) for(register int i = x; i <= y;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double pai=acos(-1.0);
const int maxn=1e6+10;
const int mod=998244353;
const double eps=1e-9;
const int N=5e3+10;
//inline int read()
//{
// int k = 0, f = 1 ;
// char c = getchar() ;
// while(!isdigit(c)){if(c == '-') f = -1 ;c = getchar() ;}
// while(isdigit(c)) k = (k << 1) + (k << 3) + c - 48 ,c = getchar() ;
// return k * f ;
//}
double pow2(double x){return x*x;}
double pow3(double x){return x*x*x;}
double dis(double x1,double y1,double z1,double x2,double y2,double z2)
{
return pow2(x1-x2)+pow2(y1-y2)+pow2(z1-z2);
}
double cos(double a,double b,double c){return (b*b+c*c-a*a)/(2*b*c);}
double cap(double r,double h){return pai*(r*3-h)*h*h/3;}
//2球体积交
double sphere_intersect(double x1,double y1,double z1,double r1,double x2,double y2,double z2,double r2)
{
double d=dis(x1,y1,z1,x2,y2,z2);
//相离
if(d>=pow2(r1+r2))return 0;
//包含
if(d<=pow2(r1-r2))return pow3(min(r1,r2))*4*pai/3;
//相交
double h1=r1-r1*cos(r2,r1,sqrt(d)),h2=r2-r2*cos(r1,r2,sqrt(d));
return cap(r1,h1)+cap(r2,h2);
}
//2球体积并
double sphere_union(double x1,double y1,double z1,double r1,double x2,double y2,double z2,double r2)
{
double d=dis(x1,y1,z1,x2,y2,z2);
//相离
if(d>=pow2(r1+r2))return (pow3(r1)+pow3(r2))*4*pai/3;
//包含
if(d<=pow2(r1-r2))return pow3(max(r1,r2))*4*pai/3;
//相交
double h1=r1+r1*cos(r2,r1,sqrt(d)),h2=r2+r2*cos(r1,r2,sqrt(d));
return cap(r1,h1)+cap(r2,h2);
}
double x[4],y[4],z[4],k1,k2;
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--)
{
for(int i=0;i<4;i++)
cin>>x[i]>>y[i]>>z[i];
cin>>k1>>k2;
double x1=(k1*k1*x[1]-x[0])/(k1*k1-1);
double y1=(k1*k1*y[1]-y[0])/(k1*k1-1);
double z1=(k1*k1*z[1]-z[0])/(k1*k1-1);
double r1=sqrt(x1*x1+y1*y1+z1*z1+(x[0]*x[0]+y[0]*y[0]+z[0]*z[0]-k1*k1*(x[1]*x[1]+y[1]*y[1]+z[1]*z[1]))/(k1*k1-1));
double x2=(k2*k2*x[3]-x[2])/(k2*k2-1);
double y2=(k2*k2*y[3]-y[2])/(k2*k2-1);
double z2=(k2*k2*z[3]-z[2])/(k2*k2-1);
double r2=sqrt(x2*x2+y2*y2+z2*z2+(x[2]*x[2]+y[2]*y[2]+z[2]*z[2]-k2*k2*(x[3]*x[3]+y[3]*y[3]+z[3]*z[3]))/(k2*k2-1));
printf("%.3lf\n",sphere_intersect(x1,y1,z1,r1,x2,y2,z2,r2));
}
return 0;
}