#include #include "tsai.h" #define EPSILON 1.0E-8 #define MAX_POINTS 128 #define MAXDIM 9+MAX_POINTS #define ABS(a) (((a) > 0) ? (a) : -(a)) #define SIGNBIT(a) (((a) > 0) ? 0 : 1) #define SQR(a) ((a) * (a)) static double U[5]; /* * Biblioteca Matemática */ #define SWAP(a,b) {double temp=(a);(a)=(b);(b)=temp;} #define TOL 1e-10 static int Gauss (int n, /* [in] Número de equações */ double a[MAXDIM][MAXDIM], /* [in] Matriz dos coeficientes */ double *b) /* [in] Vetor das constantes */ /* [out] Vetor solução */ /* Valor de retorno : (-1) => sem solução */ /* ( 0) => solução unica */ /* ( 1) => infinitas soluções */ { int i, j, k; int imax; /* Linha pivot */ double amax, rmax; /* Auxiliares */ for (j=0; j amax) amax = fabs(a[i][k]); if (amax < TOL) /* Verifica se os elementos da linha são nulos */ return -1; /* Finaliza subrotina pois o sistema não tem solução */ else if ((fabs(a[i][j]) > (rmax*amax)) && (fabs(a[i][j]) >= TOL)) { /* Testa relação da linha corrente */ rmax = fabs(a[i][j]) / amax; imax = i; /* Encontra linha de maior relação - linha pivot */ } } if (fabs(a[imax][j])=0; i--) { /* Inicia retro-substituição */ for (j=i+1; j far_distance) { far_point = i; far_distance = distance; } Ty = sqrt (Ty_squared); r1 = U[0] * Ty; r2 = U[1] * Ty; Tx = U[2] * Ty; r4 = U[3] * Ty; r5 = U[4] * Ty; x = r1 * xw[far_point] + r2 * yw[far_point] + Tx; y = r4 * xw[far_point] + r5 * yw[far_point] + Ty; if ((SIGNBIT (x) != SIGNBIT (xf[far_point])) || (SIGNBIT (y) != SIGNBIT (yf[far_point]))) Ty = -Ty; T[0] = U[2] * Ty; T[1] = Ty; } static void cc_compute_R(double T[3], double r[9]) { r[0] = U[0] * T[1]; r[1] = U[1] * T[1]; r[2] = sqrt (1 - SQR(r[0]) - SQR(r[1])); r[3] = U[3] * T[1]; r[4] = U[4] * T[1]; r[5] = sqrt (1 - SQR(r[3]) - SQR(r[4])); if (!SIGNBIT (r[0] * r[3] + r[1] * r[4])) r[5] = -r[5]; r[6] = r[1] * r[5] - r[2] * r[4]; r[7] = r[2] * r[3] - r[0] * r[5]; r[8] = r[0] * r[4] - r[1] * r[3]; } static int cc_compute_f_and_Tz(int np, double *xw, double *yw, double *xf, double *yf, double *f, double T[3], double r[9]) { double A[MAX_POINTS][5]; double B[MAX_POINTS]; int i; for (i=0; i maxx) maxx = xw[i]; else if (xw[i] < minx) minx = xw[i]; if (yw[i] > maxy) maxy = yw[i]; else if (yw[i] < miny) miny = yw[i]; } dx = (maxx - minx)/(npnx - 1); dy = (maxy - miny)/(npny - 1); x = minx; for (i=0, k=0; i