49 #define M(row,col) m->v[(((row)-1)*(m->n))+(col)-1] 53 #define MUNSOLVABLE -1 66 static int calccoef(
struct Control_Points *,
double *,
double *,
int);
67 static int calcls(
struct Control_Points *,
struct MATRIX *,
double *,
68 double *,
double *,
double *);
69 static int exactdet(
struct Control_Points *,
struct MATRIX *,
double *,
70 double *,
double *,
double *);
71 static int solvemat(
struct MATRIX *,
double *,
double *,
double *,
double *);
72 static double term(
int,
double,
double);
90 double e3, e2n, en2, n3, e2, en, n2;
94 *e = E[0] + E[1] * e1 + E[2] * n1;
95 *n = N[0] + N[1] * e1 + N[2] * n1;
103 *e = E[0] + E[1] * e1 + E[2] * n1 + E[3] * e2 + E[4] * en + E[5] * n2;
104 *n = N[0] + N[1] * e1 + N[2] * n1 + N[3] * e2 + N[4] * en + N[5] * n2;
117 E[1] * e1 + E[2] * n1 +
118 E[3] * e2 + E[4] * en + E[5] * n2 +
119 E[6] * e3 + E[7] * e2n + E[8] * en2 + E[9] * n3;
121 N[1] * e1 + N[2] * n1 +
122 N[3] * e2 + N[4] * en + N[5] * n2 +
123 N[6] * e3 + N[7] * e2n + N[8] * en2 + N[9] * n3;
141 double N12[],
double E21[],
double N21[],
152 status = calccoef(cp, E12, N12, order);
168 status = calccoef(cp, E21, N21, order);
200 for (i = numactive = 0; i < cp->
count; i++) {
208 m.n = ((order + 1) * (order + 2)) / 2;
215 m.v =
G_calloc(m.n * m.n,
sizeof(
double));
219 if (numactive == m.n)
220 status = exactdet(cp, &m, a, b, E,
N);
222 status = calcls(cp, &m, a, b, E,
N);
239 double a[],
double b[],
244 int pntnow, currow, j;
247 for (pntnow = 0; pntnow < cp->
count; pntnow++) {
248 if (cp->
status[pntnow] > 0) {
251 for (j = 1; j <= m->n; j++)
252 M(currow, j) = term(j, cp->
e1[pntnow], cp->
n1[pntnow]);
256 a[currow - 1] = cp->
e2[pntnow];
257 b[currow - 1] = cp->
n2[pntnow];
263 if (currow - 1 != m->n)
266 return solvemat(m, a,
b, E, N);
278 double a[],
double b[],
283 int i, j, n, numactive = 0;
287 for (i = 1; i <= m->n; i++) {
288 for (j = i; j <= m->n; j++)
290 a[i - 1] =
b[i - 1] = 0.0;
296 for (n = 0; n < cp->
count; n++) {
299 for (i = 1; i <= m->n; i++) {
300 for (j = i; j <= m->n; j++)
302 term(i, cp->
e1[n], cp->
n1[n]) * term(j, cp->
e1[n],
305 a[i - 1] += cp->
e2[n] * term(i, cp->
e1[n], cp->
n1[n]);
306 b[i - 1] += cp->
n2[n] * term(i, cp->
e1[n], cp->
n1[n]);
311 if (numactive <= m->n)
316 for (i = 2; i <= m->n; i++)
317 for (j = 1; j < i; j++)
320 return solvemat(m, a,
b, E, N);
334 static double term(
int term,
double e,
double n)
381 static int solvemat(
struct MATRIX *m,
double a[],
double b[],
double E[],
384 int i, j, i2, j2, imark;
388 for (i = 1; i <= m->n; i++) {
395 for (i2 = i + 1; i2 <= m->n; i2++) {
396 temp = fabs(
M(i2, j));
397 if (temp > fabs(pivot)) {
413 for (j2 = 1; j2 <= m->n; j2++) {
415 M(imark, j2) =
M(i, j2);
420 a[imark - 1] = a[i - 1];
424 b[imark - 1] =
b[i - 1];
431 for (i2 = 1; i2 <= m->n; i2++) {
433 factor =
M(i2, j) / pivot;
434 for (j2 = j; j2 <= m->n; j2++)
435 M(i2, j2) -= factor *
M(i, j2);
436 a[i2 - 1] -= factor * a[i - 1];
437 b[i2 - 1] -= factor *
b[i - 1];
445 for (i = 1; i <= m->n; i++) {
446 E[i - 1] = a[i - 1] /
M(i, i);
447 N[i - 1] =
b[i - 1] /
M(i, i);
int I_compute_georef_equations(struct Control_Points *cp, double E12[], double N12[], double E21[], double N21[], int order)
void G_free(void *)
Free allocated memory.
int order(int i_x, int i_y, int yNum)
int I_georef(double e1, double n1, double *e, double *n, double E[], double N[], int order)