gpt4 book ai didi

c - 求三角形中顶点a、b、c的等距点。语言是c

转载 作者:行者123 更新时间:2023-11-30 21:29:32 26 4
gpt4 key购买 nike

我知道计算三角形外心的步骤,但我不明白如何在我的程序中实现它。请帮忙。顶点为 a(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/米步骤 4. 求方程。使用中点和垂直平分线斜率(Y-Y1)=m(x-x1)。步骤 5. 求解并找到 x 和 y。

最佳答案

#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;
}

关于c - 求三角形中顶点a、b、c的等距点。语言是c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30601507/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com