Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 3130 | Accepted: 1325 |
Description
(x - h)^2 + (y - k)^2 = r^2 (1)
x^2 + y^2 + cx + dy - e = 0 (2)
Input
Output
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
给三个点求圆的方程
推公式,没什么说的,用克莱姆法则解方程可以方便点不用考虑分母0的情况。
#include <stdio.h> #include <math.h> #include <string.h> #include <algorithm> using namespace std; struct Point { double x,y,z; }; double Cal(Point s,Point t) { return (s.x*s.x-t.x*t.x+s.y*s.y-t.y*t.y)/2; } int main() { Point a[3]; int i; while(scanf("%lf%lf",&a[0].x,&a[0].y)!=EOF) { for (i=1;i<=2;i++) { scanf("%lf%lf",&a[i].x,&a[i].y); } Point a1,a2; a1.x=a[0].x-a[1].x; a2.x=a[0].x-a[2].x; a1.y=a[0].y-a[1].y; a2.y=a[0].y-a[2].y; a1.z=Cal(a[0],a[1]); a2.z=Cal(a[0],a[2]); double x=-(a2.z*a1.y-a1.z*a2.y)/(a2.y*a1.x-a1.y*a2.x); double y=(a2.z*a1.x-a1.z*a2.x)/(a2.y*a1.x-a1.y*a2.x); double r=sqrt((x-a[0].x)*(x-a[0].x)+(y-a[0].y)*(y-a[0].y)); printf("(x %s %.3f)^2 + (y %s %.3f)^2 = %.3f^2\n",x<0?"+":"-",fabs(x),y<0?"+":"-",fabs(y),r); printf("x^2 + y^2 %s %.3fx %s %.3fy %s %.3f = 0\n",2*x<0?"+":"-",fabs(2*x),2*y<0?"+":"-",fabs(2*y),x*x+y*y-r*r>0?"+":"-",fabs(x*x+y*y-r*r)); printf("\n"); } return 0; }