计算几何 The Circumference of the Circle

来源:互联网 发布:mac版vmware fusion 编辑:程序博客网 时间:2024/05/20 18:01

To calculate the circumference of a circle seems to be an easy task - provided you know its diameter. But what if you don't?

You are given the cartesian coordinates of three non-collinear points in the plane.
Your job is to calculate the circumference of the unique circle that intersects all three points.

输入

The input will contain one or more test cases. Each test case consists of one line containing six real numbers x1,y1, x2,y2,x3,y3, representing the coordinates of the three points. The diameter of the circle determined by the three points will never exceed a million. Input is terminated by end of file.

输出

For each test case, print one line containing one real number telling the circumference of the circle determined by the three points. The circumference is to be printed accurately rounded to two decimals. The value of pi is approximately 3.141592653589793.

样例输入

样例输出

题目来源

ULM 1996




程序代码:

#include <iostream>#include <cmath>#include <iomanip>using namespace std;const double pi=3.141592653589793;int main(){double x1,y1,x2,y2,x3,y3,a,b,c,st,cir,r,p;while(cin>>x1>>y1>>x2>>y2>>x3>>y3){a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));b=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));c=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));p=(a+b+c)/2;st=sqrt(p*(p-a)*(p-b)*(p-c));//三角形面积,海伦公式r=a*b*c/(4*st);cir=2*pi*r;cout.setf(ios::fixed);cout.precision(2);cout<<cir<<endl;}return 0;}
       cout.setf(ios::fixed);不设置为定点小数的话,cout.precision(2)指的是有效位数为2,如3.1;
       设置为定点小数后,cout.precision(2)指的是小数有效位数为2,如3.14



0 0
原创粉丝点击