To make things easier, WishingBone decides to put this simple geometry problem at the beginning. Given a triangle, what is the ratio of the area of its inscribed circle to that of its circum circle?
Input
9 integers x1 y1 z1 x2 y2 z2 x3 y3 z3 on one line (-1000 <= x, y, z <= 1000), the three coordinates of the triangle. The three coordinates will not appear collinear.
Process to the end of file.
Output
One ratio per line, exact to three digits to the right of the decimal point.
Sample Input
0 0 0 0 0 1 0 1 0
Sample Output
0.172
Source: WishingBone's Contest #1
三角形公式
外接圆:
a/sinA=b/sinB=c/sinC=2R (R就是外接圆半径)
内切圆:r=2S/(a+b+c),其中S是三角形面积,a、b、c是三角形三边。
海伦公式:S=√[p(p-a)(p-b)(p-c)],其中p=(a+b+c)/2
虽然三个点是空间坐标内的,但是组成的三角形是平面的,求出三条边即可根据以上公式求出外接圆和内切圆半径,其比的平方即为所求面积比#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
struct point{
double x,y,z;
}a,b,c;
double dis(point p1,point p2){
return sqrt( (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) + (p1.z-p2.z)*(p1.z-p2.z) );
}
int main(){
while( ~scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&a.z,&b.x,&b.y,&b.z,&c.x,&c.y,&c.z) ){
double ab = dis(a,b);
double ac = dis(a,c);
double bc = dis(b,c);
double cosa = (ab*ab+ac*ac-bc*bc)/(ab*ac*2);
double sina = sqrt(1.0 - cosa*cosa);
double p = (ab+ac+bc)/2.0;
double S = sqrt( p*(p-ab)*(p-ac)*(p-bc) );
double R = bc / sina / 2.0;
double r = S / p;
printf("%.3lf\n",(r*r)/(R*R));
}
return 0;
}