1
/////////////////////////////////////////////////////////////
3
// Copyright (c) 2007-2011 by The University of Queensland //
4
// Earth Systems Science Computational Centre (ESSCC) //
5
// http://www.uq.edu.au/esscc //
7
// Primary Business: Brisbane, Queensland, Australia //
8
// Licensed under the Open Software License version 3.0 //
9
// http://www.opensource.org/licenses/osl-3.0.php //
11
/////////////////////////////////////////////////////////////
13
#include "Sphere2DFitter.h"
15
// --- project includes ---
17
#include "nfunction.h"
19
#include "fit_2d_sphere.h"
21
// --- IO includes ---
24
Sphere FitSphere2D(const AGeometricObject* GO1,
25
const AGeometricObject* GO2,
26
const AGeometricObject* GO3,
28
int max_iter,double prec)
32
simplex_method<double,2> *simplex;
33
nvector<double,2> start,sol;
34
fit_2d_sphere_fn* sfn;
36
// set initial position to barycenter of input spheres
40
// set fitting function
41
sfn=new fit_2d_sphere_fn(GO1,GO2,GO3);
44
simplex=new simplex_method<double,2>(sfn);
45
sol=simplex->solve(prec,start,max_iter);
47
// calc radius : min radius relative to 3 spheres - tol
48
Vector3 center=Vector3(sol[0],sol[1],0.0);
49
double r1=GO1->getDist(center);
50
double r2=GO2->getDist(center);
51
double r3=GO3->getDist(center);
53
double r=(r1<r2) ? r1 : r2;
56
res=Sphere(center,r-0.1*prec);