poj 1090:The Circumference of the Circle(计算几何,求三角形外心)
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(计算几何,求三角形外心)的更多相关文章
- 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 ...
- ZOJ 1090 The Circumference of the Circle
原题链接 题目大意:已知三角形的三个顶点坐标,求其外接圆的周长. 解法:刚看到这道题时,马上拿出草稿纸画图,想推导出重心坐标,然后求出半径,再求周长.可是这个过程太复杂了,写到一半就没有兴致了,还是求 ...
- 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);//这是外接 ...
- POJ 2986 A Triangle and a Circle 圆与三角形的公共面积
计算几何模板 #include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h& ...
- F - The Circumference of the Circle
Description To calculate the circumference of a circle seems to be an easy task - provided you know ...
- UVa 11437:Triangle Fun(计算几何综合应用,求直线交点,向量运算,求三角形面积)
Problem ATriangle Fun Input: Standard Input Output: Standard Output In the picture below you can see ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- hdu 2105:The Center of Gravity(计算几何,求三角形重心)
The Center of Gravity Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- 【POJ 2195】 Going Home(KM算法求最小权匹配)
[POJ 2195] Going Home(KM算法求最小权匹配) Going Home Time Limit: 1000MS Memory Limit: 65536K Total Submiss ...
随机推荐
- [转发]在Visual Studio 2010/2012/2013/2015上使用C#开发Android/IOS安装包和操作步骤
官方学习文档:http://developer.xamarin.com/guides/android/getting_started/ 官方学习例子:http://developer.xamarin. ...
- js 回调函数 精析
UpdateTime--2018年9月13日16点51分 1.什么是回调函数? 在JavaScript中,回调函数具体的定义为: 函数A作为参数(函数引用)传递到另一个函数B中,并且这个函数B执行 ...
- Android自定义控件-折线图
好长时间没有更新博客了,终于可以抽出时间写点东西了,写点什么呢?最近在qq群里边有人问,下边的这个控件怎么画?如下图所示:图可以左右拖动,直到显示完全为止.刚开始看到这个效果图,我也想了一下总共分为以 ...
- kernel4.1 ioctl调用
在4.1内核中开发时遇到个奇怪的问题: 用户空间的ioctl无法调用到内核空间的unlock_ioctl 排查源码发现 546 int do_vfs_ioctl(struct file *filp, ...
- C++多态有哪几种方式?
C++多态方式: (1)静态多态(重载,模板) 是在编译的时候,就确定调用函数的类型. (2)动态多态(覆盖,虚函数实现) 在运行的时候,才确定调用的是哪个函数,动态绑定.运行基类指针指向派生类的对象 ...
- powershell 卸载KB hotfix补丁
- 区别getElementByID,getElementsByName,getElementsByTagName
以人来举例说明,人有能标识身份的身份证,有姓名,有类别(大人.小孩.老人)等. 1. ID 是一个人的身份证号码,是唯一的.所以通过getElementById获取的是指定的一个人. 2. Name ...
- centos 无法ping内网 Destination Host Unreachable
centos 突然无法ping内网了. 本来是一直是好好的. 在这之前,当前服务器(centos 192.168.1.30)大量的在操作内网192.168.1.20服务器的数据库.. 会不会是流量大了 ...
- [原]C#设置文件夹用户权限
var security = new DirectorySecurity(); string path=@"C:\temp" //设置权限的应用为文件夹本身.子文件夹及文件,所 ...
- MySQL存储过程使用实例详解
本文介绍关于在MySQL存储过程游标使用实例,包括简单游标使用与游标循环跳出等方法 例1.一个简单存储过程游标实例 DROP PROCEDURE IF EXISTS getUserInfo $$CRE ...