Changeset 4628 in orxonox.OLD for orxonox/trunk/src/lib/collision_detection
- Timestamp:
- Jun 14, 2005, 2:02:35 AM (19 years ago)
- Location:
- orxonox/trunk/src/lib/collision_detection
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/collision_detection/lin_alg.h
r4627 r4628 5 5 compute the eigenpairs (eigenvalues and eigenvectors) of a real symmetric matrix "A" by the Jacobi method 6 6 */ 7 8 9 /************************************************************ 10 * This subroutine computes all eigenvalues and eigenvectors * 11 * of a real symmetric square matrix A(N,N). On output, ele- * 12 * ments of A above the diagonal are destroyed. D(N) returns * 13 * the eigenvalues of matrix A. V(N,N) contains, on output, * 14 * the eigenvectors of A by columns. THe normalization to * 15 * unity is made by main program before printing results. * 16 * NROT returns the number of Jacobi matrix rotations which * 17 * were required. * 18 * --------------------------------------------------------- * 19 * Ref.:"NUMERICAL RECIPES IN FORTRAN, Cambridge University * 20 * Press, 1986, chap. 11, pages 346-348". * 21 * * 22 * C++ version by J-P Moreau, Paris. * 23 ************************************************************/ 24 void JacobI(float **A,int N,float *D, float **V, int *NROT) { 25 float *B, *Z; 26 double c,g,h,s,sm,t,tau,theta,tresh; 27 int i,j,ip,iq; 28 29 void *vmblock1 = NULL; 30 31 //allocate vectors B, Z 32 //vmblock1 = vminit(); 33 B = (float *) calloc(100, 32); 34 Z = (float *) calloc(100, 32); 35 36 for (ip=1; ip<=N; ip++) { //initialize V to identity matrix 37 for (iq=1; iq<=N; iq++) V[ip][iq]=0; 38 V[ip][ip]=1; 39 } 40 for (ip=1; ip<=N; ip++) { 41 B[ip]=A[ip][ip]; 42 D[ip]=B[ip]; 43 Z[ip]=0; 44 } 45 *NROT=0; 46 for (i=1; i<=50; i++) { 47 sm=0; 48 for (ip=1; ip<N; ip++) //sum off-diagonal elements 49 for (iq=ip+1; iq<=N; iq++) 50 sm=sm+fabs(A[ip][iq]); 51 if (sm==0) { 52 return; //normal return 53 } 54 if (i < 4) 55 tresh=0.2*sm*sm; 56 else 57 tresh=0; 58 for (ip=1; ip<N; ip++) { 59 for (iq=ip+1; iq<=N; iq++) { 60 g=100*fabs(A[ip][iq]); 61 // after 4 sweeps, skip the rotation if the off-diagonal element is small 62 if ((i > 4) && (fabs(D[ip])+g == fabs(D[ip])) && (fabs(D[iq])+g == fabs(D[iq]))) 63 A[ip][iq]=0; 64 else if (fabs(A[ip][iq]) > tresh) { 65 h=D[iq]-D[ip]; 66 if (fabs(h)+g == fabs(h)) 67 t=A[ip][iq]/h; 68 else { 69 theta=0.5*h/A[ip][iq]; 70 t=1/(fabs(theta)+sqrt(1.0+theta*theta)); 71 if (theta < 0) t=-t; 72 } 73 c=1.0/sqrt(1.0+t*t); 74 s=t*c; 75 tau=s/(1.0+c); 76 h=t*A[ip][iq]; 77 Z[ip] -= h; 78 Z[iq] += h; 79 D[ip] -= h; 80 D[iq] += h; 81 A[ip][iq]=0; 82 for (j=1; j<ip; j++) { 83 g=A[j][ip]; 84 h=A[j][iq]; 85 A[j][ip] = g-s*(h+g*tau); 86 A[j][iq] = h+s*(g-h*tau); 87 } 88 for (j=ip+1; j<iq; j++) { 89 g=A[ip][j]; 90 h=A[j][iq]; 91 A[ip][j] = g-s*(h+g*tau); 92 A[j][iq] = h+s*(g-h*tau); 93 } 94 for (j=iq+1; j<=N; j++) { 95 g=A[ip][j]; 96 h=A[iq][j]; 97 A[ip][j] = g-s*(h+g*tau); 98 A[iq][j] = h+s*(g-h*tau); 99 } 100 for (j=1; j<=N; j++) { 101 g=V[j][ip]; 102 h=V[j][iq]; 103 V[j][ip] = g-s*(h+g*tau); 104 V[j][iq] = h+s*(g-h*tau); 105 } 106 *NROT=*NROT+1; 107 } //end ((i.gt.4)...else if 108 } // main iq loop 109 } // main ip loop 110 for (ip=1; ip<=N; ip++) { 111 B[ip] += Z[ip]; 112 D[ip]=B[ip]; 113 Z[ip]=0; 114 } 115 } //end of main i loop 116 printf("\n 50 iterations !\n"); 117 return; //too many iterations 118 } 119 120 121 122 7 123 8 124 #include "abstract_model.h" … … 341 457 // //allocate vectors B, Z 342 458 // vmblock1 = vminit(); 343 // //B = ( REAL*) vmalloc(vmblock1, VEKTOR, 100, 0);344 // //Z = ( REAL*) vmalloc(vmblock1, VEKTOR, 100, 0);459 // //B = (float *) vmalloc(vmblock1, VEKTOR, 100, 0); 460 // //Z = (float *) vmalloc(vmblock1, VEKTOR, 100, 0); 345 461 // 346 462 // //initialize V to identity matrix -
orxonox/trunk/src/lib/collision_detection/obb_tree_node.cc
r4627 r4628 103 103 Vector p, q, r; //!< holder of the polygon data, much more conveniant to work with Vector than sVec3d 104 104 Vector t1, t2; //!< temporary values 105 doublecovariance[3][3]; //!< the covariance matrix105 float covariance[3][3]; //!< the covariance matrix 106 106 107 107 this->numOfVertices = length; … … 194 194 195 195 196 double a[4][4]; 197 198 a[0][0] = C(1,1) = covariance[0][0]; 199 a[0][1] = C(1,2) = covariance[0][1]; 200 a[0][2] = C(1,3) = covariance[0][2]; 201 a[1][0] = C(2,1) = covariance[1][0]; 202 a[1][1] = C(2,2) = covariance[1][1]; 203 a[1][2] = C(2,3) = covariance[1][2]; 204 a[2][0] = C(3,1) = covariance[2][0]; 205 a[2][1] = C(3,2) = covariance[2][1]; 206 a[2][2] = C(3,3) = covariance[2][2]; 196 C(1,1) = covariance[0][0]; 197 C(1,2) = covariance[0][1]; 198 C(1,3) = covariance[0][2]; 199 C(2,1) = covariance[1][0]; 200 C(2,2) = covariance[1][1]; 201 C(2,3) = covariance[1][2]; 202 C(3,1) = covariance[2][0]; 203 C(3,2) = covariance[2][1]; 204 C(3,3) = covariance[2][2]; 207 205 208 206 Jacobi(C, D, V); /* do the jacobi decomposition */ … … 211 209 212 210 /* new jacobi tests */ 213 double eigenvectors[3][3]; 214 double eigval[3]; 215 216 EVJacobi jac; 217 jac.setMatrix(2, covariance, 0, 0); 218 jac.getEigenVector(eigenvectors); 219 211 float** a = new float*[4]; 212 a[0] = new float[4]; a[1] = new float[4]; a[2] = new float[4]; a[3] = new float[4]; 213 214 float** b = new float*[4]; 215 b[0] = new float[4]; b[1] = new float[4]; b[2] = new float[4]; b[3] = new float[4]; 216 217 float eigval[3]; 218 219 int* rot = new int; 220 221 222 a[1][1] = covariance[0][0]; 223 a[1][2] = covariance[0][1]; 224 a[1][3] = covariance[0][2]; 225 a[2][1] = covariance[1][0]; 226 a[2][2] = covariance[1][1]; 227 a[2][3] = covariance[1][2]; 228 a[3][1] = covariance[2][0]; 229 a[3][2] = covariance[2][1]; 230 a[3][3] = covariance[2][2]; 231 232 233 // EVJacobi jac; 234 // jac.setMatrix(2, covariance, 0, 0); 235 // jac.getEigenVector(eigenvectors); 236 // 237 238 JacobI(a, 3, eigval, b, rot); 220 239 221 240 printf("Old Jacobi\n"); … … 231 250 232 251 printf("New Jacobi\n"); 233 for(int j = 0; j < 3; ++j)252 for(int j = 1; j < 4; ++j) 234 253 { 235 254 printf(" |"); 236 for(int k = 0; k < 3; ++k)255 for(int k = 1; k < 4; ++k) 237 256 { 238 printf(" \b%f ", eigenvectors[j][k]);257 printf(" \b%f ", b[j][k]); 239 258 } 240 259 printf(" |\n");
Note: See TracChangeset
for help on using the changeset viewer.