[Solved] finding equidistant point in triangle with vertices a, b and c. language is c


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

4

solved finding equidistant point in triangle with vertices a, b and c. language is c