ZOJ.1439 Area Ratio【三角形外接圆内切圆】 2015/10/20

Area Ratio

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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是三角形面积,abc是三角形三边。

海伦公式: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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值