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. (转)android适配各种分辨率的问题

    Android设备屏幕的尺寸是各式各样的,如小米是4英寸的,Xoom平板是10英寸:分辨率也千奇百怪,800×480,960×540等:Android版本的碎片化问题更是萦绕于心,不过在设计应用时可以 ...

  2. 转:RHEL6.3 安装GCC 记录

    本文参考:http://blog.163.com/phys_atom/blog/static/1676445532012229814992/ 如果直接使用GUN GCC官方的源码来安装是不成功的,因为 ...

  3. OpenCV iOS开发(一)——安装(转)

    OpenCV是一个开源跨平台的的计算机视觉和机器学习库,可以用来做图片视频的处理.图形识别.机器学习等应用.本文将介绍OpenCV iOS开发中的Hello World起步. 安装 OpenCV安装的 ...

  4. RMAN Recovery Catalog

    RMAN用来存放数据库元数据的schema. the catalog includes the following types of metadata:-Data file and archived ...

  5. Tomcat服务器配置https协议(Tomcat HTTPS/SSL 配置)

    通常商用服务器使用https协议需要申请SSL证书,证书都是收费的,价格有贵的有便宜的.它们的区别是发行证书的机构不同,贵的证书机构更权威,证书被浏览器否决的几率更小. 非商业版本可以通过keytoo ...

  6. 手动集成OWIN

    1.Install-Package Microsoft.AspNet.Identity.Owin Owin的很大亮点之一就是它可以让我们的ASP.NET 网站摆脱IIS,但是毕竟大多数的ASP.NET ...

  7. Oracle开发者守则

    下面为Oracle大师级语录: Oracle Database developers should follow is to do everything they can in SQL. What t ...

  8. js 温故而知新 用typeof 来判断一个未定义的变量

    一直以为,如果你使用一个未定义的变量,肯定会报错.甚至根本不可能有这种场景. 但仔细想想还是有的,譬如你要判断全局是否存在$变量.或者要为全局暴漏一个全局变量之前,先判断是否有这个变量. typeof ...

  9. sso单点登录研究

    iframe跨域通信的通用解决方案http://www.alloyteam.com/2012/08/lightweight-solution-for-an-iframe-cross-domain-co ...

  10. Spring注解-@Configuration注解、@Bean注解以及配置自动扫描、bean作用域

    1.@Configuration标注在类上,相当于把该类作为spring的xml配置文件中的<beans>,作用为:配置spring容器(应用上下文) package com.test.s ...