Circle Through Three Points

本文介绍如何利用三个平面坐标点求解通过这三个点的圆的方程,并提供了求解过程的详细步骤和示例代码。

Circle Through Three Points

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 37   Accepted Submission(s) : 10
Problem 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.0
1.0 7.0 8.0 6.0 7.0 -2.0
 

 

Sample Output
(x - 3.000)^2 + (y + 2.000)^2 = 5.000^2
x^2 + y^2 - 6.000x + 4.000y - 12.000 = 0

(x - 3.921)^2 + (y - 2.447)^2 = 5.409^2
x^2 + y^2 - 7.842x - 4.895y - 7.895 = 0
 

 

Source
PKU
 1 #include <string.h>
 2 #include <stdlib.h>
 3 #include <stdio.h>
 4 #include <math.h>
 5 typedef struct point { double x, y; }point;
 6 typedef struct line{point a,b;}line;
 7 point intersection(line u,line v)
 8 {
 9     point ret=u.a;
10     double t=((u.a.x-v.a.x)*(v.a.y-v.b.y)-(u.a.y-v.a.y)*(v.a.x-v.b.x))/((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));
11     ret.x+=(u.b.x-u.a.x)*t;
12     ret.y+=(u.b.y-u.a.y)*t;
13     return ret;
14 }
15 point circumcenter(point a,point b,point c)
16 {
17     line u,v;
18     u.a.x=(a.x+b.x)/2;
19     u.a.y=(a.y+b.y)/2;
20     u.b.x=u.a.x-a.y+b.y;
21     u.b.y=u.a.y+a.x-b.x;
22     v.a.x=(a.x+c.x)/2;
23     v.a.y=(a.y+c.y)/2;
24     v.b.x=v.a.x-a.y+c.y;
25     v.b.y=v.a.y+a.x-c.x;
26     return intersection(u,v);
27 }
28 double distance(point p1,point p2)
29 {
30     return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
31 }
32 int main()
33 {
34     point L1,L2,L3,S;
35     int T,i,x1,y1,x2,y2,x3,y3;
36     double Len;
37     while( scanf("%lf%lf%lf%lf%lf%lf",&L1.x,&L1.y,&L2.x,&L2.y,&L3.x,&L3.y)!=EOF)
38     {
39         S=circumcenter(L1,L2,L3);
40         Len=distance(S,L1);
41         printf("(x ");
42         if(S.x>0)printf("- %.3f)^2 + (y ",S.x);
43         else printf("+ %.3f)^2 + (y ",-S.x);
44         if(S.y>0)printf("- %.3f)^2 = %.3f^2\n",S.y,Len);
45         else printf("+ %.3f)^2 = %.3f^2\n",-S.y,Len);
46         printf("x^2 + y^2 ");
47         if(2*S.x>0)printf("- %.3fx ",2*S.x);
48         else printf("+ %.3fx ",-2*S.x);
49         if(2*S.y>0)printf("- %.3fy ",2*S.y);
50         else printf("+ %.3fy ",-2*S.y);
51         if(S.x*S.x+S.y*S.y-Len*Len>0)printf("+ %.3f = 0\n",S.x*S.x+S.y*S.y-Len*Len);
52         else printf("- %.3f = 0\n",-(S.x*S.x+S.y*S.y-Len*Len));
53         putchar(10);
54     }
55     return 0;
56 }
View Code

 

转载于:https://www.cnblogs.com/Wurq/articles/3929267.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值