53 #include <grass/libtrans.h>
56 static double A0, A1, A2, A3, A4, A5;
57 static double B0, B1, B2, B3, B4, B5;
60 static int resid(
double *,
double *,
double *,
double *,
int *,
int,
double *,
91 double by[],
int *use,
int n)
105 for (i = 0; i <
n; i++)
111 for (i = 0; i < 3; i++) {
114 for (j = 0; j < 3; j++)
118 for (i = 0; i <
n; i++) {
125 cc[1][1] += bx[i] * bx[i];
126 cc[1][2] += bx[i] * by[i];
127 cc[2][2] += by[i] * by[i];
130 aa[1] += ay[i] * bx[i];
131 aa[2] += ay[i] * by[i];
134 bb[1] += ax[i] * bx[i];
135 bb[2] += ax[i] * by[i];
158 x = B2 * B4 - B1 * B5;
163 A0 = (B1 * B3 - B0 * B4) / x;
166 A3 = (B0 * B5 - B2 * B3) / x;
176 *by = A0 + A1 * ax + A2 * ay;
177 *bx = A3 + A4 * ax + A5 * ay;
185 *ay = B0 + B1 * bx + B2 * by;
186 *ax = B3 + B4 * bx + B5 * by;
206 int use[],
int n,
double residuals[],
double *rms)
208 resid(ax, ay, bx, by, use, n, residuals, rms, 1);
215 int use[],
int n,
double residuals[],
double *rms)
217 resid(ax, ay, bx, by, use, n, residuals, rms, 0);
233 fprintf(stdout,
"\nTransformation Matrix\n");
234 fprintf(stdout,
"| xoff a b |\n");
235 fprintf(stdout,
"| yoff d e |\n");
236 fprintf(stdout,
"-------------------------------------------\n");
237 fprintf(stdout,
"%f %f %f \n", -B3, B2, -B5);
238 fprintf(stdout,
"%f %f %f \n", -B0, -B1, B4);
239 fprintf(stdout,
"-------------------------------------------\n");
245 static int resid(
double ax[],
double ay[],
double bx[],
double by[],
246 int use[],
int n,
double residuals[],
double *rms,
int atob)
257 for (i = 0; i <
n; i++) {
273 delta = dx * dx + dy * dy;
274 residuals[i] = sqrt(delta);
277 *rms = sqrt(sum / count);
int inverse(double m[N][N])
int m_mult(double a[N][N], double b[N], double c[N])