46 #define M(row, col) m->v[(((row) - 1) * (m->n)) + (col) - 1]
50 #define MUNSOLVABLE -1
63 static int calccoef(
struct Control_Points *,
double *,
double *,
int);
64 static int calcls(
struct Control_Points *,
struct MATRIX *,
double *,
double *,
66 static int exactdet(
struct Control_Points *,
struct MATRIX *,
double *,
67 double *,
double *,
double *);
68 static int solvemat(
struct MATRIX *,
double *,
double *,
double *,
double *);
69 static double term(
int,
double,
double);
87 double e3, e2n, en2, n3, e2, en, n2;
91 *e = E[0] + E[1] * e1 + E[2] * n1;
92 *n =
N[0] +
N[1] * e1 +
N[2] * n1;
100 *e = E[0] + E[1] * e1 + E[2] * n1 + E[3] * e2 + E[4] * en + E[5] * n2;
101 *n =
N[0] +
N[1] * e1 +
N[2] * n1 +
N[3] * e2 +
N[4] * en +
N[5] * n2;
113 *e = E[0] + E[1] * e1 + E[2] * n1 + E[3] * e2 + E[4] * en + E[5] * n2 +
114 E[6] * e3 + E[7] * e2n + E[8] * en2 + E[9] * n3;
115 *n =
N[0] +
N[1] * e1 +
N[2] * n1 +
N[3] * e2 +
N[4] * en +
N[5] * n2 +
116 N[6] * e3 +
N[7] * e2n +
N[8] * en2 +
N[9] * n3;
134 double N12[],
double E21[],
double N21[],
145 status = calccoef(cp, E12, N12,
order);
161 status = calccoef(cp, E21, N21,
order);
193 for (i = numactive = 0; i < cp->
count; i++) {
208 m.v =
G_calloc(m.n * m.n,
sizeof(
double));
212 if (numactive == m.n)
213 status = exactdet(cp, &m, a,
b, E,
N);
215 status = calcls(cp, &m, a,
b, E,
N);
231 static int exactdet(
struct Control_Points *cp,
struct MATRIX *m,
double a[],
232 double b[],
double E[],
236 int pntnow, currow, j;
239 for (pntnow = 0; pntnow < cp->
count; pntnow++) {
240 if (cp->
status[pntnow] > 0) {
243 for (j = 1; j <= m->n; j++)
244 M(currow, j) = term(j, cp->
e1[pntnow], cp->
n1[pntnow]);
248 a[currow - 1] = cp->
e2[pntnow];
249 b[currow - 1] = cp->
n2[pntnow];
255 if (currow - 1 != m->n)
258 return solvemat(m, a,
b, E,
N);
269 static int calcls(
struct Control_Points *cp,
struct MATRIX *m,
double a[],
270 double b[],
double E[],
274 int i, j, n, numactive = 0;
278 for (i = 1; i <= m->n; i++) {
279 for (j = i; j <= m->n; j++)
281 a[i - 1] =
b[i - 1] = 0.0;
287 for (n = 0; n < cp->
count; n++) {
290 for (i = 1; i <= m->n; i++) {
291 for (j = i; j <= m->n; j++)
292 M(i, j) += term(i, cp->
e1[n], cp->
n1[n]) *
293 term(j, cp->
e1[n], cp->
n1[n]);
295 a[i - 1] += cp->
e2[n] * term(i, cp->
e1[n], cp->
n1[n]);
296 b[i - 1] += cp->
n2[n] * term(i, cp->
e1[n], cp->
n1[n]);
301 if (numactive <= m->n)
306 for (i = 2; i <= m->n; i++)
307 for (j = 1; j < i; j++)
310 return solvemat(m, a,
b, E,
N);
324 static double term(
int term,
double e,
double n)
371 static int solvemat(
struct MATRIX *m,
double a[],
double b[],
double E[],
374 int i, j, i2, j2, imark;
378 for (i = 1; i <= m->n; i++) {
385 for (i2 = i + 1; i2 <= m->n; i2++) {
386 temp = fabs(
M(i2, j));
387 if (temp > fabs(pivot)) {
403 for (j2 = 1; j2 <= m->n; j2++) {
405 M(imark, j2) =
M(i, j2);
410 a[imark - 1] = a[i - 1];
414 b[imark - 1] =
b[i - 1];
421 for (i2 = 1; i2 <= m->n; i2++) {
423 factor =
M(i2, j) / pivot;
424 for (j2 = j; j2 <= m->n; j2++)
425 M(i2, j2) -= factor *
M(i, j2);
426 a[i2 - 1] -= factor * a[i - 1];
427 b[i2 - 1] -= factor *
b[i - 1];
435 for (i = 1; i <= m->n; i++) {
436 E[i - 1] = a[i - 1] /
M(i, i);
437 N[i - 1] =
b[i - 1] /
M(i, i);
int order(int i_x, int i_y, int yNum)
void G_free(void *)
Free allocated memory.
int I_georef(double e1, double n1, double *e, double *n, double E[], double N[], int order)
int I_compute_georef_equations(struct Control_Points *cp, double E12[], double N12[], double E21[], double N21[], int order)