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. Spring事务属性具体解释

    Spring.是一个Java开源框架,是为了解决企业应用程序开发复杂性由Rod Johnson创建的.框架的主要优势之中的一个就是其分层架构,分层架构同意使用者选择使用哪一个组件,同一时候为 J2EE ...

  2. win10 显示详细信息窗格

      win10 显示详细信息窗格 CreateTime--2018年5月26日09点13分 Author:Marydon 1.说明: win10无法像win7那样将详细信息窗格显示在窗口的底部,只能显 ...

  3. powershell执行脚本

    powershell执行脚本   执行powershell脚本有两种方式: 1.通过命令行参数启动脚本 C:\Windows\System32\WindowsPowerShell\v1.0\power ...

  4. MySQL5.6 主从复制 ERROR 1776 (HY000): Parameters MASTER_LOG_FILE

    主从都开启了gtid,在设置从库的时候遇到了问题 mysql> CHANGE MASTER TO MASTER_HOST=‘xxx’,MASTER_USER='replicant',MASTER ...

  5. Web中路径问题

    如果在web项目中需要使用路径,如:转发.重定向还有超链接等. 原则:”一切web路径以/开始” 那么/的路径一定是相对路径,那么/到底代表哪一个相对路径是需要智慧的. 如果该路径是给服务器使用的,那 ...

  6. vmware-Binary translation is incompatible with long mode on this platform

    解决方法:Binary translation is incompatible with long mode on this platform. Disabling long mode. Withou ...

  7. 非变动性算法源代码分析与使用示例( for_each、min_element 、find_if、search 等)

    非变动性算法代码分析与示例: 一.for_each  C++ Code  1 2 3 4 5 6 7 8 9 10 11 12 13 14   // TEMPLATE FUNCTION for_eac ...

  8. Java类载入器 ClassLoader的解析

    //參考 : http://www.ibm.com/developerworks/cn/java/j-lo-classloader/ 类载入器基本概念 类载入器是 Java 语言的一个创新,也是 Ja ...

  9. 《开源框架那点事儿23》:採用TinyDB组件方式开发

    採用TinyDB组件方式开发 步骤 Icon 前文介绍四则运算的流程编程开发时,说过流程编排在开发反复功能时.能够利用已有的组件库高速开发.对于开发者而言仅仅须要简单配置流程就能够完毕工作了.开发增删 ...

  10. Linux下让进程在后台可靠运行的几种方法

    想让进程在断开连接后依然保持运行?如果该进程已经开始运行了该如何补救? 如果有大量这类需求如何简化操作? 我们经常会碰到这样的问题,用 telnet/ssh 登录了远程的 Linux 服务器,运行了一 ...