The circumference of the Circle
http://poj.org/problem?id=2242
Time limit:1000ms
Memory limit:65536k
Description
To calculate the circumference of a circle seems to is an easy task-provided your know its diameter. But What if you don ' t?
You are are given the Cartesian coordinates of three non-collinear points in the plane.
The Your job is to calculate the circumference of the unique circle this intersects all three points.
Input
The input would contain one or more test cases. Each test case consists of the ' one line ' containing six real numbers x1,y1, X2,y2,x3,y3, representing the ' th ' Ree points. The diameter of the circle determined by the three points'll never exceed a million. The Input is terminated by the end of file.
Output
For each test case, print one line containing one real number telling the circumference of the circle determined by the TH Ree points. The circumference is 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
Source
ULM Local 1996
By
s= (a*b*sinc)/2
And
c/sinc= circumcircle diameter d
Have
D= (a*b*c)/(2*s)
S is derived from the area of the direction (determinant)
Note: C + + on POJ does not support C99, but g++ supports
Complete code:
/*0ms,588kb*/
#include <cstdio>
#include <cmath>
const Double PI = ACOs ( -1.0);
Inline double area (double x0, double y0, double x1, double y1, double x2, double y2)
{return
fabs (x0 * y1 + x2 * y0 + x1 * y2-x2 * y1-x0 * y2-x1 * y0);
int main (void)
{
double x0, y0, x1, y1, x2, y2;
while (~SCANF ("%lf%lf%lf%lf%lf%lf", &x0, &y0, &x1, &y1, &x2, &y2))
printf ("%.2f\n", Hypot (X0-X1, y0-y1) * Hypot (X1-X2, y1-y2) * Hypot (X0-X2, y0-y2) * Pi/area (x0, y0, x1, y1, x2, y2));
return 0;
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/