四面体内接圆圆心坐标计算模板

设四面体的四个点为A_1,A_2,A_3,A_4

A_i所对的面的面积为S_i

A_i顶点的坐标为(x_i,y_i,z_i)

那么四面体的內接圆圆心的坐标:(x,y,z)


\[
\color{black}{x=\frac{x1*s1+x2*s2+x3*s3+x4*s4}{s1+s2+s3+s4}}
\]
\[
\color{black}{y=\frac{y1*s1+y2*s2+y3*s3+y4*s4}{s1+s2+s3+s4}
}
\]
\[
\color{black}{z=\frac{z1*s1+z2*s2+z3*s3+z4*s4}{s1+s2+s3+s4}
}
\]
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long LL;

#define inf int(0x3f3f3f3f)
#define mod ll(1e9+7)
#define eps double(1e-7)
#define pi acos(-1.0)
#define lson  root << 1
#define rson  root << 1 | 1

struct Point
{
    ll x,y,z;
} mi[20];

Point operator-(Point a,Point b)
{
    return (Point)
    {
        b.x-a.x,b.y-a.y,b.z-a.z
    };
}

double dis(Point a)
{
    return sqrt(a.x*a.x+a.y*a.y+a.z*a.z);
}

Point cross(Point a,Point b)
{
    return {a.y*b.z-b.y*a.z,a.z*b.x-a.x*b.z,a.x*b.y-a.y*b.x};
}

double dot(Point a,Point b)
{
    return a.x*b.x+a.y*b.y+a.z*b.z;
}

int main()
{
    while(scanf("%lld%lld%lld",&mi[1].x,&mi[1].y,&mi[1].z)!=EOF)
    {
        for(int i=2; i<=4; i++)
            cin>>mi[i].x>>mi[i].y>>mi[i].z;
        if(dot(cross(mi[2]-mi[1],mi[3]-mi[1]),mi[4])==0)
        {
            printf("No such condition!");
            continue;
        }
        double s1=dis(cross(mi[3]-mi[2],mi[4]-mi[2]))/2.0;
        double s2=dis(cross(mi[3]-mi[1],mi[4]-mi[1]))/2.0;
        double s3=dis(cross(mi[2]-mi[1],mi[4]-mi[1]))/2.0;
        double s4=dis(cross(mi[3]-mi[1],mi[2]-mi[1]))/2.0;
        double rx=(s1*mi[1].x+s2*mi[2].x+s3*mi[3].x+s4*mi[4].x)/(s1+s2+s3+s4);
        double ry=(s1*mi[1].y+s2*mi[2].y+s3*mi[3].y+s4*mi[4].y)/(s1+s2+s3+s4);
        double rz=(s1*mi[1].z+s2*mi[2].z+s3*mi[3].z+s4*mi[4].z)/(s1+s2+s3+s4);
        printf("%.4f %.4f %.4f\n",rx,ry,rz);
    }
}