题意:给出一个三角形,求内切圆与外接圆的面积比
分析:简单题
三个顶点已知,可以利用海伦公式求出三角形面积S
假设三条边的边长分别为a,b,c
外接圆半径为R,内切圆半径为r
公式如下:
abc/4/R = S
rp = S (p为三角形半周长)
分析:简单题
三个顶点已知,可以利用海伦公式求出三角形面积S
假设三条边的边长分别为a,b,c
外接圆半径为R,内切圆半径为r
公式如下:
abc/4/R = S
rp = S (p为三角形半周长)
最后,圆的面积比就是半径平方的面积比
代码如下:
#include <cstdio>
#include <cmath>
using namespace std;
struct Point3{
double x,y,z;
Point3(double x=0, double y=0, double z=0):x(x),y(y),z(z){}
};
typedef Point3 Vector3;
Vector3 operator +(Vector3 A, Vector3 B) { return Vector3(A.x+B.x,A.y+B.y,A.z+B.z); }
Vector3 operator -(Vector3 A, Vector3 B) { return Vector3(A.x-B.x,A.y-B.y,A.z-B.z); }
Vector3 operator *(Vector3 A, double p) { return Vector3(A.x*p,A.y*p,A.z*p); }
double Dot3(Vector3 A, Vector3 B) { return A.x*B.x+A.y*B.y+A.z*B.z; }
double Length(Vector3 A) { return sqrt(Dot3(A,A)); }
Point3 a,b,c;
int main(){
double x,y,z;
while (scanf("%lf%lf%lf",&x,&y,&z)==3){
a = Point3(x,y,z);
scanf("%lf%lf%lf",&x,&y,&z); b = Point3(x,y,z);
scanf("%lf%lf%lf",&x,&y,&z); c = Point3(x,y,z);
Vector3 ac = c-a, ab = b-a , bc = b-c;
double d1 = Length(ac), d2 = Length(ab), d3 = Length(bc);
double p = (d1+d2+d3)*0.5;
double s = sqrt(p*(p-d1)*(p-d2)*(p-d3));
double R = d1*d2*d3*0.25/s;
double r = s/p;
printf("%.3f\n",r*r/R/R);
}
return 0;
}