【模板】 四面体体积公式
代码:
1 /************************************************************************* 2 > File Name: poj2208.cpp 3 # File Name: poj2208.cpp 4 # Author : xiaobuxie 5 # QQ : 760427180 6 # Email:760427180@qq.com 7 # Created Time: 2019年10月23日 星期三 19时57分37秒 8 ************************************************************************/ 9 10 #include<iostream> 11 #include<cstdio> 12 #include<map> 13 #include<cmath> 14 #include<cstring> 15 #include<set> 16 #include<queue> 17 #include<vector> 18 #include<algorithm> 19 using namespace std; 20 typedef long long ll; 21 #define inf 0x3f3f3f3f 22 #define eps 1e-8 23 int sgn(double x){ 24 if(fabs(x) < eps) return 0; 25 if(x<0) return -1; 26 return 1; 27 } 28 // 求四面体的体积,欧拉公式. 29 // p, q, r 为AB,AC,AD, n, m, l 为BC, BD, CD 30 // V = ( (OA x OB)*OC )/6 OAB做底,C做顶点,先叉乘后点乘 31 double calV(double p,double q,double r,double n,double m,double l){ 32 double rr = r*r, mm = m*m,nn = n*n; 33 double pp = p*p, qq = q*q,ll = l*l; 34 double x1 = (pp + qq - nn)/2.0 ,x2 = (pp + rr - mm)/2.0,x3 = (qq + rr -ll)/2.0; 35 double v = pp * ( qq * rr - x3 * x3 ) - x1 * (x1 * rr - x2 * x3 ) + x2 * ( x1 * x3 - qq * x2 ); 36 return sqrt(v)/6.0; 37 } 38 int main(){ 39 double p,q,r,n,m,l; 40 while(~scanf("%lf %lf %lf %lf %lf %lf",&p,&q,&r,&n,&m,&l)){ 41 printf("%.4f\n",calV(p,q,r,n,m,l)); 42 } 43 return 0; 44 }