输入不共线的三个点坐标(x1, y1)(x2, y2)(x3, y3), 求出其过这三点的唯一圆的周长
不知道哪错了,请帮忙看看指错~~#include<stdio.h>
#include<math.h>
#define PI 3.141592653589793
int main()
{
double x1, y1, x2, y2, x3, y3, d, e, r;
while(scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3) == 6)
{
d = ((x2 * x2- x3 * x3) * (y2 - y1) - (x1 * x1 - x2 * x2) * (y3 - y2)) / ((x1 - x2) * (y3 - y2) - (x2 - x3) * (y2 - y1));
e = (x1 * x1 - x2 * x2 + d * (x1 - x2)) / (y2 - y1);
r = sqrt((x1 + d / 2) * (x1 + d / 2) + (y1 + e / 2) * (y1 + e / 2));
printf("%.2lf\n", 2 * PI * r);
}
return 0;
}
/*(a, b)设为圆心的坐标,x1, y1, x2, y2, x3, y3分别为不共线三个点的坐标,已知(x - a)^ 2 + (y - b) ^ 2 = r ^ 2
拆开来就是x^2 - 2ax + a ^ 2 + y ^ 2 - 2by + b ^ 2 - r ^ 2 = 0,令d = -2a, e = -2b, f = a ^ 2 + b ^ 2 - r ^ 2
即为 x ^ 2 + dx + ey + f = 0,所以有式子 x1^ 2 + dx1 + ey1 + f = 0……1
x2 ^ 2 + dx2 + ey2 + f = 0……2
x3 ^ 2 + dx3 + ey3 + f = 0……3
联立1与2得, (x1 ^ 2 - x2 ^ 2) + d(x1 - x2) + e(y1 - y2) = 0…… 4
联立3与2得,(x2 ^ 2 - x3 ^ 2) + d(x2 - x3) + e(y2 - y3) = 0……5
4式即, e = ((x1 ^ 2 - x2 ^ 2) + d(x1 - x2)) / (y2 - y1)
5式即, e = ((x2 ^ 2 - x3 ^ 2) + d(x2 - x3)) / (y3 - y2)
4式-5式得,(x1 ^ 2 - x2 ^ 2) / (y2 - y1) - (x2 ^ 2 - x3 ^ 2) / (y3 - y2) + d((x1 - x2) / (y2 - y1) - (x2 - x3) / (y3 - y2)) = 0
即 d = ((x2 * x2- x3 * x3) * (y2 - y1) - (x1 * x1 - x2 * x2) * (y3 - y2)) / ((x1 - x2) * (y3 - y2) - (x2 - x3) * (y2 - y1))
e = ((x1 * x1 - x2 * x2 + d * (x1 - x2)) / (y2 - y1) */