我知道计算三角形的圆周的步骤,但我无法理解如何在我的程序中实现它。请帮忙。顶点是(2,4)b(10,15)c(5,8) 程序 步骤1.找到a,bc,ca。的中点 (X1 + X2)/ 2 (Y1 + Y2)/ 2 第2步。找到ab,bc,ca的斜率 M =(Y1-Y2)/(X2-X1) 步骤3.找到垂直平分线斜率 -1 / M 第4步。找到方程式。 使用中点和垂直平分线斜率 (Y-Y1)= M(X-X1)。 步骤5.解决并找到x和y。
答案 0 :(得分:0)
#include <stdio.h>
#include <math.h>
typedef struct point {
double x, y;
} Point;
#if 0
ax + by = c
Ax + By = C
x = (c - by)/a = (C - By)/A
Ac - Aby = aC - aBy
(aB - Ab)y = aC - Ac
y = (aC - Ac) / (aB - Ab)
x = (Bc - bC) / (aB - Ab)
#endif
Point ans(double a, double b, double c, double A, double B, double C){
Point ret = {FP_NAN, FP_NAN};
double D = a*B -A*b;
if(D == 0)
return ret;
ret.x = (B*c - b*C) / D;
ret.y = (a*C - A*c) / D;
return ret;
}
#if 0
(x-Ox)^2+(y-Oy)^2=r^2
(Xa-Ox)^2+(Ya-Oy)^2=(Xb-Ox)^2+(Yb-Oy)^2
(Xa-Ox)^2+(Ya-Oy)^2=(Xc-Ox)^2+(Yc-Oy)^2
2(Xb-Xa)Ox + 2(Yb-Ya)Oy + Xa^2-Xb^2+Ya^2-Yb^2 = 0
2(Xc-Xa)Ox + 2(Yc-Ya)Oy + Xa^2-Xc^2+Ya^2-Yc^2 = 0
#endif
Point center(Point a, Point b, Point c){
return ans(2*(b.x-a.x), 2*(b.y-a.y), b.y*b.y - a.y*a.y + b.x*b.x - a.x*a.x,
2*(c.x-a.x), 2*(c.y-a.y), c.y*c.y - a.y*a.y + c.x*c.x - a.x*a.x);
}
int main(void){
Point a = { 2, 4}, b = {10, 15}, c = {5, 8};
Point o = center(a, b, c);
printf("(%f, %f)\n", o.x, o.y);
return 0;
}