#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 float U[5]; /* * Biblioteca Matemática */ #define SWAP(a,b) {float temp=(a);(a)=(b);(b)=temp;} #define TOL 1e-10 static int Gauss (int n, /* [in] Número de equações */ float a[MAXDIM][MAXDIM], /* [in] Matriz dos coeficientes */ float *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 */ float amax, rmax; /* Auxiliares */ for (j=0; j amax) amax = (float)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 = (float)(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 = (float)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(float T[3], float r[9]) { r[0] = U[0] * T[1]; r[1] = U[1] * T[1]; r[2] = (float)sqrt(1.0f - SQR(r[0]) - SQR(r[1])); r[3] = U[3] * T[1]; r[4] = U[4] * T[1]; r[5] = (float)sqrt(1.0f - 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, float *xw, float *yw, float *xf, float *yf, float *f, float T[3], float r[9]) { float A[MAX_POINTS][5]; float B[MAX_POINTS]; int i; for (i=0; i