ZOJ1090 The Circumference of the Circle
计算几何题,使用的数学公式参考http://topic.csdn.net/t/20050329/22/3892541.html
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
const double PI = 3.141592653589793;
double Distance(double x1,double y1,double x2,double y2)
{//两点间的距离
double deltaX = x1-x2;
double deltaY = y1-y2;
return sqrt(deltaX*deltaX+deltaY*deltaY);
}
double CaculateCircum(double x1,double y1,double x2,double y2,double x3,double y3)
{//计算三角形外接圆周长
//海伦公式计算三角形面积
double a,b,c,L,S;
a = Distance(x1,y1,x2,y2);
b = Distance(x2,y2,x3,y3);
c = Distance(x1,y1,x3,y3);
L = (a+b+c)/2;
S = sqrt(L*(L-a)*(L-b)*(L-c));
//计算三角形外接圆周长
return PI*a*b*c/(2*S);
}
int main(void)
{
double x1,y1,x2,y2,x3,y3,circum;
while(cin>>x1>>y1>>x2>>y2>>x3>>y3)
{
circum = CaculateCircum(x1,y1,x2,y2,x3,y3);
cout<<fixed<<setprecision(2)<<circum<<endl;
}
return 0;
}
#include <iomanip>
#include <cmath>
using namespace std;
const double PI = 3.141592653589793;
double Distance(double x1,double y1,double x2,double y2)
{//两点间的距离
double deltaX = x1-x2;
double deltaY = y1-y2;
return sqrt(deltaX*deltaX+deltaY*deltaY);
}
double CaculateCircum(double x1,double y1,double x2,double y2,double x3,double y3)
{//计算三角形外接圆周长
//海伦公式计算三角形面积
double a,b,c,L,S;
a = Distance(x1,y1,x2,y2);
b = Distance(x2,y2,x3,y3);
c = Distance(x1,y1,x3,y3);
L = (a+b+c)/2;
S = sqrt(L*(L-a)*(L-b)*(L-c));
//计算三角形外接圆周长
return PI*a*b*c/(2*S);
}
int main(void)
{
double x1,y1,x2,y2,x3,y3,circum;
while(cin>>x1>>y1>>x2>>y2>>x3>>y3)
{
circum = CaculateCircum(x1,y1,x2,y2,x3,y3);
cout<<fixed<<setprecision(2)<<circum<<endl;
}
return 0;
}
作者:洞庭散人
出处:http://phinecos.cnblogs.com/
本博客遵从Creative Commons Attribution 3.0 License,若用于非商业目的,您可以自由转载,但请保留原作者信息和文章链接URL。
posted on 2008-10-31 10:20 Phinecos(洞庭散人) 阅读(544) 评论(0) 编辑 收藏 举报