ZOJ 1090 The Circumference of the Circle(计算三角形的外接圆)

来源:互联网 发布:淘宝装修页尾代码 编辑:程序博客网 时间:2024/05/16 05:43

提交地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1090


这是我最喜欢做的题之一,因为这种题我感觉 做一遍以后就会了,不做心里总是感觉这个地方不会,有点担心。

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 numbersx1,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.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


先来看看涉及的公式吧!

按照书上来吧:

先看个圆的公式:(x-xo)²+(y-yo)²=r²

已知三点可一代入求得 圆心(xo,yo) 和 半径 r

但是推到公式太复杂。

让我们来换个公式。

已知三点可以求得三条边长a,b,c

sinA/a=sinB/b=sinC/c = 2r

A,B,C为角;

c²=a²+b²-2abcosC

sinC²+cosC²=1

由这些公式就能推到了

sinC²=(c/2r)²

cosC²=((a²+b²-c²)/2ab)²

#include<iostream>#include<stdio.h>#include<math.h>#define  PI 3.141592653589793using namespace std;int main(){double x1,y1,x2,y2,x3,y3;while(cin>>x1>>y1>>x2>>y2>>x3>>y3){double af = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);double bf = (x1-x3)*(x1-x3)+(y1-y3)*(y1-y3);double cf = (x2-x3)*(x2-x3)+(y2-y3)*(y2-y3);double left =(af+bf-cf)*(af+bf-cf)/(4*af*bf);double sinc2=1-left;double r = sqrt(cf/sinc2/4);printf("%.2lf\n",r*PI*2);}}

这些代码就足够了,我的af,bf,cf等是a的平方,b的平方,c的平方。自己推导一下 就出来了,平方太多别乱了 我刚做的时候就乱了,不出结果,浪费了很长时间。

下面再说下一个公式:

三角形外接圆半径为r=abc/4s;

根据海伦公式计算面积:s=sqrt(p(p-a)(p-b)(p-c)) 其中 p=(a+b+c)/2;

这个公式同样可以推到出来。

好了!

感谢自己坚持!


1 0
原创粉丝点击