Calculates the geometry. The first four points whether the coplanar, Coplanar is no solution. It then calculates the center coordinate and then calculates the distance from the center to either side.
#include <cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<iostream>using namespaceStd;typedefLong LongLL;#defineEPS 1e-8#defineZero (x) (((x) >0? ( x):-(x)) <eps)structpoint3{Doublex, Y, z;};structline3{Point3 A, b;};structplane3{point3 a,b,c;};//Calculate cross product product product product U x Vpoint3 Xmult (point3 U,point3 v) {POINT3 ret; Ret.x=u.y*v.z-v.y*u.z; Ret.y=u.z*v.x-u.x*v.z; Ret.z=u.x*v.y-u.y*v.x; returnret;}//Compute dot Product product product product U. VDoubleDmult (Point3 U,point3 v) {returnu.x*v.x+u.y*v.y+u.z*v.z;}//Vector Difference U-vpoint3 subt (point3 U,point3 v) {POINT3 ret; Ret.x=u.x-v.x; Ret.y=u.y-v.y; Ret.z=u.z-v.z; returnret;}//take plane method vectorPoint3 Pvec (Plane3 s) {returnXmult (Subt (s.a,s.b), Subt (S.B,S.C));} Point3 Pvec (point3 s1,point3 s2,point3 S3) {returnXmult (Subt (S1,S2), Subt (S2,S3));}//Two-point distance, single-parameter orientation magnitudeDoubledis (point3 p1,point3 p2) {returnsqrt ((p1.x-p2.x) * (p1.x-p2.x) + (P1.Y-P2.Y) * (P1.Y-P2.Y) + (p1.z-p2.z) * (p1.z-p2.z));}//Vector sizeDoubleVlen (Point3 p) {returnsqrt (p.x*p.x+p.y*p.y+p.z*p.z);}intDots_onplane (point3 a,point3 b,point3 c,point3 d) {returnZero (Dmult (Pvec (a,b,c), Subt (D,a)));}//point to plane distanceDoublePtoplane (point3 p,point3 s1,point3 s2,point3 S3) {returnFabs (Dmult (Pvec (S1,S2,S3), Subt (P,S1))/Vlen (Pvec (S1,S2,S3));}DoubleArea (Point3 a,point3 b,point3 c) {DoubleAb=dis (A, B), Bc=dis (b,c), ac=dis (a,c); Doublep= (AB+BC+AC)/2; returnsqrt (p* (p-ab) * (P-BC) * (P-( ac));}intMain () {Point3 p[5]; while(~SCANF ("%LF%LF%LF", &p[1].x,&p[1].y,&p[1].z)) { for(intI=2; i<=4; i++) scanf ("%LF%LF%LF",&p[i].x,&p[i].y,&p[i].z); if(Dots_onplane (p[1],p[2],p[3],p[4]) {printf ("o o o o\n");Continue; } DoubleSabc=area (p[1],p[2],p[3]); DoubleSabd=area (p[1],p[2],p[4]); DoubleSacd=area (p[1],p[3],p[4]); DoubleSbcd=area (p[2],p[3],p[4]); DoubleS=sabc+sabd+sacd+SBCD; Point3 Heart; Heart.x= (sabc*p[4].x+sabd*p[3].x + sacd*p[2].x+sbcd*p[1].x)/R; Heart.y= (sabc*p[4].y+sabd*p[3].y + sacd*p[2].y+sbcd*p[1].Y)/S; Heart.z= (sabc*p[4].z+sabd*p[3].z + sacd*p[2].z+sbcd*p[1].Z)/S; printf ("%.4lf%.4lf%.4lf%.4lf\n", Heart.x,heart.y,heart.z,ptoplane (heart,p[1],p[2],p[3])); } return 0;}
HDU 5733 Tetrahedron