poj 1329 Circle Through Three Points(三点求圆方程)

来源:互联网 发布:玻璃配方计算软件 编辑:程序博客网 时间:2024/05/10 13:35
Circle Through Three Points
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 2785 Accepted: 1179

Description

Your team is to write a program that, given the Cartesian coordinates of three points on a plane, will find the equation of the circle through them all. The three points will not be on a straight line. 
The solution is to be printed as an equation of the form 
(x - h)^2 + (y - k)^2 = r^2(1)

and an equation of the form 
x^2 + y^2 + cx + dy - e = 0(2)

Input

Each line of input to your program will contain the x and y coordinates of three points, in the order Ax, Ay, Bx, By, Cx, Cy. These coordinates will be real numbers separated from each other by one or more spaces.

Output

Your program must print the required equations on two lines using the format given in the sample below. Your computed values for h, k, r, c, d, and e in Equations 1 and 2 above are to be printed with three digits after the decimal point. Plus and minus signs in the equations should be changed as needed to avoid multiple signs before a number. Plus, minus, and equal signs must be separated from the adjacent characters by a single space on each side. No other spaces are to appear in the equations. Print a single blank line after each equation pair.

Sample Input

7.0 -5.0 -1.0 1.0 0.0 -6.01.0 7.0 8.0 6.0 7.0 -2.0

Sample Output

(x - 3.000)^2 + (y + 2.000)^2 = 5.000^2x^2 + y^2 - 6.000x + 4.000y - 12.000 = 0(x - 3.921)^2 + (y - 2.447)^2 = 5.409^2x^2 + y^2 - 7.842x - 4.895y - 7.895 = 0

Source

Southern California 1989,UVA 190

题目:http://poj.org/problem?id=1329

题意:给你三个点,三点保证不共线,求过三个点的圆的方程

分析:选择两个点对,分别求出垂直平分线,然后求交点即可,我的做法是求出两垂直平分线的极角,和中点,然后联立两个方程,求出中点到圆心的距离,然后求出圆心

PS:极角貌似精度还行,再次1Y了

代码:

#include<cmath>#include<cstdio>#include<iostream>using namespace std;double ax,ay,bx,by,cx,cy,r,a1,a2,x,y;void out(double x){    printf("%c %.3lf",x<0?'+':'-',fabs(x));}int main(){    while(~scanf("%lf%lf%lf%lf%lf%lf",&ax,&ay,&bx,&by,&cx,&cy))    {        a1=atan2(by-ay,bx-ax)+acos(-1.0)/2;        a2=atan2(cy-by,cx-bx)+acos(-1.0)/2;        ax=(ax+bx)/2,ay=(ay+by)/2;        bx=(cx+bx)/2,by=(cy+by)/2;        r=(sin(a2)*(ax-bx)+cos(a2)*(by-ay))/(sin(a1)*cos(a2)-sin(a2)*cos(a1));        x=ax+r*cos(a1),y=ay+r*sin(a1);        r=(cx-x)*(cx-x)+(cy-y)*(cy-y);        printf("(x ");        out(x);        printf(")^2 + (y ");        out(y);        printf(")^2 = %.3lf^2\n",sqrt(r));        printf("x^2 + y^2 ");        out(2*x);        printf("x ");        out(2*y);        printf("y ");        out(r-x*x-y*y);        puts(" = 0\n");    }    return 0;}


原创粉丝点击