87 #define SMALSN 1.0e-10
96 static void qikfit(
REAL umat[3][3],
REAL rm[3][3],
BOOL column);
148 for(j=0;j<3;j++) umat[i][j] = 0.0;
155 umat[i][0] += wt1[j] * x1[j].
x * x2[j].
x;
156 umat[i][1] += wt1[j] * x1[j].
x * x2[j].
y;
157 umat[i][2] += wt1[j] * x1[j].
x * x2[j].
z;
160 umat[i][0] += wt1[j] * x1[j].
y * x2[j].
x;
161 umat[i][1] += wt1[j] * x1[j].
y * x2[j].
y;
162 umat[i][2] += wt1[j] * x1[j].
y * x2[j].
z;
165 umat[i][0] += wt1[j] * x1[j].
z * x2[j].
x;
166 umat[i][1] += wt1[j] * x1[j].
z * x2[j].
y;
167 umat[i][2] += wt1[j] * x1[j].
z * x2[j].
z;
177 for(j=0;j<3;j++) umat[i][j] = 0.0;
184 umat[i][0] += x1[j].
x * x2[j].
x;
185 umat[i][1] += x1[j].
x * x2[j].
y;
186 umat[i][2] += x1[j].
x * x2[j].
z;
189 umat[i][0] += x1[j].
y * x2[j].
x;
190 umat[i][1] += x1[j].
y * x2[j].
y;
191 umat[i][2] += x1[j].
y * x2[j].
z;
194 umat[i][0] += x1[j].
z * x2[j].
x;
195 umat[i][1] += x1[j].
z * x2[j].
y;
196 umat[i][2] += x1[j].
z * x2[j].
z;
202 qikfit(umat,rm,column);
224 static void qikfit(
REAL umat[3][3],
261 rtsum = umat[0][0] + umat[1][1] + umat[2][2];
264 for(ncyc=0;ncyc<jmax;ncyc++)
270 nrem = ncyc-nsteep*(int)(ncyc/nsteep);
274 for(i=0;i<3;i++) step[i]=0.0;
279 coup[0] = umat[1][2]-umat[2][1];
280 coup[1] = umat[2][0]-umat[0][2];
281 coup[2] = umat[0][1]-umat[1][0];
282 cle = sqrt(coup[0]*coup[0] + coup[1]*coup[1] + coup[2]*coup[2]);
285 gfac = (cle/clep)*(cle/clep);
290 if(cle <
SMALL)
break;
296 step[i]=coup[i]+step[i]*gfac;
297 stp += (step[i] * step[i]);
302 for(i=0;i<3;i++) dir[i] = stp*step[i];
305 stcoup = coup[0]*dir[0] + coup[1]*dir[1] + coup[2]*dir[2];
311 ud += umat[l][m]*dir[l]*dir[m];
314 tr = umat[0][0]+umat[1][1]+umat[2][2]-ud;
315 ta = sqrt(tr*tr + stcoup*stcoup);
331 turmat[l][m] = v[l]*dir[m];
337 turmat[0][1] -= v[2];
338 turmat[1][2] -= v[0];
339 turmat[2][0] -= v[1];
340 turmat[1][0] += v[2];
341 turmat[2][1] += v[0];
342 turmat[0][2] += v[1];
351 c[l][m] += turmat[l][k]*rot[k][m];
365 c[l][m] += turmat[l][k]*umat[k][m];
370 umat[l][m] = c[l][m];
372 rtsum = umat[0][0] + umat[1][1] + umat[2][2];
373 delta = rtsum - rtsump;
386 rm[j][i] = rot[i][j];
392 rm[i][j] = rot[i][j];
BOOL blMatfit(COOR *x1, COOR *x2, REAL rm[3][3], int n, REAL *wt1, BOOL column)
Include file for least squares fitting.
Type definitions for maths.