比较显然的模拟退火。
如果我们知道了点的坐标,那么其与其他三个圆的角度就可以得到了。我们需要最大化角度,这点不是很清楚,大概是因为这个点唯一?
#include <bits/stdc++.h>
using namespace std;
struct Circle {
double x, y, r;
void in() {
scanf("%lf%lf%lf", &x, &y, &r);
}
} cir[3];
double Length(double x1, double y1, double x2, double y2) {
return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}
struct SimulatedAnnealing {
const double eps = 1e-6;
double x, y, dis, t, r, delta;
int best;
double walk[4][2] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}};
double check(double x, double y) {
double cta[3];
double tmp = 0, tmp1 = 0;
for(int i = 0; i < 3; i++)
cta[i] = Length(cir[i].x, cir[i].y, x, y)/cir[i].r, tmp += cta[i];
tmp /= 3.0;
for(int i = 0; i< 3; i++) tmp1 += (tmp-cta[i])*(tmp-cta[i]);
return tmp1;
}
pair<double, double> gao() {
delta = 1;
x = y = 0;
for(int i = 0; i < 3; i++) cir[i].in(), x += cir[i].x, y += cir[i].y;
x /= 3.0, y /= 3.0;
while(delta > eps) {
r = check(x, y), best = -1;
for(int i = 0; i < 4; i++) {
t = check(x+walk[i][0]*delta, y+walk[i][1]*delta);
if(t < r) {
r = t;
best = i;
}
}
if(best == -1) delta *= 0.7;
else x += walk[best][0]*delta, y += walk[best][1]*delta;
}
// cout<<x<<" "<<y<<endl;
return {x, y};
}
} solver;
int main(){
pair<double, double> p = solver.gao();
if(solver.check(p.first, p.second) < 1e-6) printf("%.10f %.10f", p.first, p.second);
return 0;
}