步骤公式:
已知三角形三边长a、b、c
外接圆半周长: p = a + b + c 2 p = {a + b + c\over2} p=2a+b+c
外接圆面积: S = p ( p − a ) ( p − b ) ( p − c ) S= \sqrt{p(p – a)(p – b) (p – c)} S=p(p−a)(p−b)(p−c)
外接圆直径: d = a b c 2 S d = {abc\over2S} d=2Sabc
外接圆半径: R = a b c 4 S R={abc\over4S} R=4Sabc
外接圆周长: C = 2 π R C=2\pi R C=2πR
例题: HDU 1374 – The Circumference of the Circle
题意: 给出三个点的坐标,求出这三个点所构成三角形的外接圆周长。
思路: 直接套用公式即可。
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
#define pi 3.141592653589793
using namespace std;
int main() {
double x1,y1,x2,y2,x3,y3;
while(cin>>x1>>y1>>x2>>y2>>x3>>y3) {
double x = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
double y = sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
double z = sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
double p = (x+y+z)/2.0;
double s = sqrt(p*(p-x)*(p-y)*(p-z));
double d = x*y*z/(2.0*s);
cout<<fixed<<setprecision(2)<<pi*d<<endl;
}
return 0;
}