/** Linear fitting of spheres to a set of 3D points Idea based in papers: V. Pratt. Direct least-squares fitting of algebraic surfaces ACM SIGGRAPH Computer Graphics, (21) 4, 1987, pp. 145 - 152 A. Fitzgibbon, M. Pilu, and R.B. Fisher, Direct least square fitting of ellipses IEEE Trans, of Pattern Anal. & Mach. Intell. (21) 5, 1999, pp. 476-480 And: SUHAIL A ISLAM - MATHS NOTES http://www.bmm.icnet.uk/people/suhail/plane.html Fraga, 3/03/2009 **/ #include #include #include "f2c.h" #include "clapack.h" /** Compiled with command line: gcc -O2 algeb_fit.c -o algeb_fit lapack_LINUX.a libF77.a blas_LINUX.a -lm gcc -O2 algeb_fit.c -o algeb_fit -L/opt/local/lib -lapack -lF77 -lblas -lm **/ #define M 4 #define MM 16 int main( int argc, char *argv[] ) { int i,j; char namein[64]; double px, py, pz; double a, b, c, d; double x0, y0, z0; FILE *file; //////////////////////////////////////// /** Parametros para la función dggev **/ char JOBVL = 'N'; char JOBVR = 'V'; int N = M; int LDA = M; int LDB = M; int LDVL = 1; int LDVR = M; int LWORK= 195; int INFO; double S[MM], Z[MM]; double alphar[M]; double alphai[M]; double beta[M]; double vl[LDVL*M]; double vr[LDVR*M]; double wk[LWORK]; double C[MM]={ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; //////////////////////////////////////////// if ( argc != 2 ) { fprintf( stderr, "Args: file_name\n" ); exit(1); } strncpy( namein, argv[1], 64 ); if ( (file = fopen (namein,"r") ) == NULL ) { fprintf( stderr, "Can't open %s file\n", file ); exit(1); } for (i=0; i