POJ2242_The Circumference of the Circle(几何/三角形外接圆周长/模板)

来源:互联网 发布:sql关联查询 编辑:程序博客网 时间:2024/05/20 19:49
The Circumference of the Circle
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 7017 Accepted: 4353

Description

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. 

Input

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.

Output

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.

Sample Input

0.0 -0.5 0.5 0.0 0.0 0.50.0 0.0 0.0 1.0 1.0 1.05.0 5.0 5.0 7.0 4.0 6.00.0 0.0 -1.0 7.0 7.0 7.050.0 50.0 50.0 70.0 40.0 60.00.0 0.0 10.0 0.0 20.0 1.00.0 -500000.0 500000.0 0.0 0.0 500000.0

Sample Output

3.144.446.2831.4262.83632.243141592.65

Source

Ulm Local 1996
解题报告
表示几何模板党。。。
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#define PI  3.141592653589793using namespace std;struct point{    double x,y;}p1,p2,p3;struct line{    point a,b;};point intersection(line u,line v){    point ret=u.a;    double t=((u.a.x-v.a.x)*(v.a.y-v.b.y)-(u.a.y-v.a.y)*(v.a.x-v.b.x))    /((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));    ret.x+=(u.b.x-u.a.x)*t;    ret.y+=(u.b.y-u.a.y)*t;    return ret;}point circumcenter(point a,point b,point c){    line u,v;    u.a.x=(a.x+b.x)/2;    u.a.y=(a.y+b.y)/2;    u.b.x=u.a.x-a.y+b.y;    u.b.y=u.a.y+a.x-b.x;    v.a.x=(a.x+c.x)/2;    v.a.y=(a.y+c.y)/2;    v.b.x=v.a.x-a.y+c.y;    v.b.y=v.a.y+a.x-c.x;    return intersection(u,v);}double dis(point p1,point p2){    return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));}int main(){    while(cin>>p1.x>>p1.y>>p2.x>>p2.y>>p3.x>>p3.y)    {        point c=circumcenter(p1,p2,p3);//        printf("%.2lf %.2lf\n",c.x,c.y);        double r=dis(p1,c);        //printf("%.2lf\n",r);        printf("%.2lf\n",2*PI*r);    }    return 0;}


0 0
原创粉丝点击