题目的意思是说,给你一个三角形的三边(保证数据合法),求它三个旁切圆圆心所围成的面积和图中灰色部分的面积。
内切圆的圆心是三条角平分线的交点,旁切圆的圆心是两个外角的角平分的交点。
推导出发现三角形AEC、BDC、AFB是相似的,可用余弦定理算出角度后利用正弦定理算出边长。
#include <iostream> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> using namespace std; const double pi = acos(-1.0); double anga, angb, angc; double angd, ange, angf; double a, b, c; double AE, AF, BD, BF, CD, CE; double DE, EF, FD; double dsin, esin, fsin; double rd, re, rf; double GetArea(double a, double b, double c) { double p = (a + b + c) / 2.0; return sqrt(p * (p - a) * (p - b) * (p - c)); } double GetR(double a, double b, double c) { return (2.0 * GetArea(a, b, c) / c); } void Calc() { anga = acos((b * b + c * c - a * a) / (2.0 * b * c)); angb = acos((a * a + c * c - b * b) / (2.0 * a * c)); angc = pi - anga - angb; angd = (pi - anga) / 2.0; ange = (pi - angb) / 2.0; angf = pi - angd - ange; dsin = sin(angd); esin = sin(ange); fsin = sin(angf); AF = c / fsin * esin; AE = b / esin * fsin; BD = a / dsin * fsin; BF = c / fsin * dsin; CD = a / dsin * esin; CE = b / esin * dsin; DE = CD + CE; EF = AE + AF; FD = BD + BF; printf("%.2lf ", GetArea(DE, EF, FD)); rd = GetR(BD, CD, a); re = GetR(AE, CE, b); rf = GetR(AF, BF, c); printf("%.2lf\n", (angd * rd * rd + ange * re * re + angf * rf *rf) / 2.0); } int main() { int cas = 1; while(scanf("%lf%lf%lf", &a, &b, &c) && (a || b || c)) { printf("Case %d: ", cas++); Calc(); } return 0; }