The Circumference of the Circle


Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 Specification

The input file 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 Specification

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.5
0.0 0.0 0.0 1.0 1.0 1.0
5.0 5.0 5.0 7.0 4.0 6.0
0.0 0.0 -1.0 7.0 7.0 7.0
50.0 50.0 50.0 70.0 40.0 60.0
0.0 0.0 10.0 0.0 20.0 1.0
0.0 -500000.0 500000.0 0.0 0.0 500000.0

Sample Output

3.14
4.44
6.28
31.42
62.83
632.24
3141592.65

  

  计算几何,求三角形外心

  题意是给你三个点,让你求穿过这三个点的圆的周长。很显然,这个圆是这三个点构成的三角形的外接圆,只要求出这个外接圆的圆心,就能确定半径r,进而求得外接圆的周长。外接圆的圆心就是三角形的外心,外心的求法是三角新任意两边的垂直平分线线的交点(外心到三角形任意一个顶点的距离相等)。

  那么这个题的重心就转移到了求三角形的外心。我是用解析几何的解法做的,因为知道两点的坐标,可以求出任意两条边的斜截式(y=kx+b)的斜率k和截距b,根据垂直的两条直线k1*k2=-1,求出垂直平分线的斜率,然后在根据边的中点可以写出任意两条边的垂直平分线的斜截式。最后联立三角形两条边的垂直平分线的方程,求得交点,就是三角形的外心。

  需要注意的是,有一条边斜率是0的情况,这条边的垂直平分线的斜率是不存在的(因为是垂直的),所以需要拿出来特殊考虑。

  用解析几何做可能会伤精度,但是应付这道题是够了,有时间把其他做法贴上来。

  代码

 #include <stdio.h>
#include <math.h>
#define PI 3.141592653589793
typedef struct { //定义点
double x,y;
} Point;
double dis(Point a,Point b) //两点距离
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
Point getWai(Point a,Point b,Point c) //解析几何方法,求三角形abc的外心
{
Point w;
Point cen1,cen2; //边ab和边ac的中点
cen1.x = (a.x+b.x)/;
cen1.y = (a.y+b.y)/;
cen2.x = (a.x+c.x)/;
cen2.y = (a.y+c.y)/;
if(a.y==b.y){ //ab的垂线垂直,不存在斜率k的情况
double k2 = -1.0/((a.y-c.y)/(a.x-c.x));
double b2 = cen2.y - k2*cen2.x;
w.x = cen1.x;
w.y = cen1.x*k2 + b2;
return w;
}
else if(a.y==c.y){ //ac的垂线垂直
double k1 = -1.0/((a.y-b.y)/(a.x-b.x));
double b1 = cen1.y - k1*cen1.x;
w.x = cen2.x;
w.y = cen2.x*k1 + b1;
return w;
}
else { //不存在垂线垂直的情况
double k1 = -1.0/((a.y-b.y)/(a.x-b.x));
double b1 = cen1.y - k1*cen1.x;
double k2 = -1.0/((a.y-c.y)/(a.x-c.x));
double b2 = cen2.y - k2*cen2.x;
w.x = (b2-b1)/(k1-k2);
w.y = k1*w.x+b1;
return w;
}
}
int main()
{
Point a,b,c; //三角形的三点
while(scanf("%lf%lf%lf%lf%lf%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y)!=EOF){
Point w = getWai(a,b,c);
double r = dis(w,a);
printf("%.2lf\n",*PI*r);
}
return ;
}

Freecode : www.cnblogs.com/yym2013

poj 1090:The Circumference of the Circle(计算几何,求三角形外心)的更多相关文章

  1. ZOJ Problem Set - 1090——The Circumference of the Circle

      ZOJ Problem Set - 1090 The Circumference of the Circle Time Limit: 2 Seconds      Memory Limit: 65 ...

  2. ZOJ 1090 The Circumference of the Circle

    原题链接 题目大意:已知三角形的三个顶点坐标,求其外接圆的周长. 解法:刚看到这道题时,马上拿出草稿纸画图,想推导出重心坐标,然后求出半径,再求周长.可是这个过程太复杂了,写到一半就没有兴致了,还是求 ...

  3. POJ 2242 The Circumference of the Circle

    做题回顾:用到海伦公式,还有注意数据类型,最好统一 p=(a+b+c)/2; s=sqrt(p*(p-a)*(p-b)*(p-c));//三角形面积,海伦公式 r=a*b*c/(4*s);//这是外接 ...

  4. POJ 2986 A Triangle and a Circle 圆与三角形的公共面积

    计算几何模板 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h& ...

  5. F - The Circumference of the Circle

    Description To calculate the circumference of a circle seems to be an easy task - provided you know ...

  6. UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)

    Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...

  7. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  8. hdu 2105:The Center of Gravity(计算几何,求三角形重心)

    The Center of Gravity Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  9. 【POJ 2195】 Going Home(KM算法求最小权匹配)

    [POJ 2195] Going Home(KM算法求最小权匹配) Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

随机推荐

  1. bzoj-1492 货币兑换Cash (2)——CDQ分治

    题意: 略 见上一篇 题解: 方程还是那个方程f[i]=A[i] * X[j] + B[i] * Y[j]. 化简为Y[i]=(-A[i]/B[i]) * X[i] + f[i]/B[i]这一坨: 既 ...

  2. 【bat】通过for循环复制一张图片100次

    代码如下: @echo off set "F=1" cd C:\Users\Thinkpad\Desktop\img for /L %%F IN (1,1,100) DO COPY ...

  3. Quercus-基于 Java 的 PHP 框架

    Quercus是Caucho公司采用纯Java开发的一个PHP5引擎.基于开源授权协议GPL发布.Quercus自带很多个PHP模块和扩展如 PDF,PDO,MySQL和JSON.可以利用这个引擎在一 ...

  4. Android传感器开发

    2013-07-02 Android 中传感器的种类 加速度,Sensor.TYPE_ACCELEROMETER 陀螺仪,Sensor.TYPE_GYROSCOPE 亮度,Sensor.TYPE_LI ...

  5. js加强小结

    一)回顾JavaScript基础 (1)函数的定义方式 *>>正常方式 function add(num1,num2){...} >>构造器方式 var add = new F ...

  6. Linux-yum在线安装svn步骤

    yum -y install subversion httpd mod_dav_svn 使用yum命令安装svn(subversion),httpd(apache服务器)和svn在apache上的插件 ...

  7. 使用HTML5的Notification API制作web通知的教程(转)

    var notification=new Notification(‘Notification Title',{ body:'Your Message' }); 上面的代码构造了一个简陋的通知栏.构造 ...

  8. 批量修改图像的大小 Python PIL

    #-*-coding:utf-8-*- import os import os.path from PIL import Image import time def ResizeImage(filei ...

  9. AngularJS 中的作用域

    问题引入 使用 Angular 进行过一段时间的开发后,基本上都会遇到一个这样的坑: 123456789101112 <div ng-controller="TestCtrl" ...

  10. Facebook API 入门

    Facebook 商业价值简介 Facebook 是一个社交网络服务网站,于 2004 年 2 月 4 日上线,到 2010 年 2 月 2 日, Facebook 正赶超雅虎将成为全球第三大网站,与 ...