00001
00002 #include "../header/Matrix.h"
00003
00004
00005
00006
00007 Matrix::Matrix()
00008 {
00009 set_identity();
00010 }
00011
00012 Matrix::~Matrix()
00013 {
00014 }
00015 Matrix::Matrix(const Matrix& _M)
00016 {
00017 for(int k_x=0;k_x<4;k_x++)
00018 for(int k_y=0;k_y<4;k_y++)
00019 this->set_value(_M.M[k_x+4*k_y],k_x,k_y);
00020 }
00021
00022 Matrix Matrix::multiply(Matrix M2)
00023 {
00024
00025 double temp_M[16];
00026
00027 int k_x=0,k_y=0,k_m=0;
00028 double temp=0;
00029
00030
00031 for(k_x=0;k_x<4;k_x++)
00032 for(k_y=0;k_y<4;k_y++)
00033 {
00034
00035 for(k_m=0,temp=0;k_m<4;k_m++)
00036 {
00037 temp += M[k_m+4*k_y] * (M2.value(k_x,k_m));
00038 }
00039 temp_M[k_x+4*k_y] = temp;
00040 }
00041
00042
00043 for(int k=0;k<16;k++)
00044 M[k]=temp_M[k];
00045
00046 return *this;
00047 }
00048
00049 double *Matrix::multiply(double *x)
00050 {
00051 double x_homogeneous[4]={x[0],x[1],x[2],1};
00052 double temp[4]={0,0,0,0};
00053 int k_x=0,k_y=0;
00054 for(k_x=0;k_x<4;k_x++)
00055 for(k_y=0;k_y<4;k_y++)
00056 temp[k_y] += M[k_x+4*k_y]*x_homogeneous[k_x];
00057
00058
00059
00060 double *output = new double[3];
00061 for(int k=0;k<3;k++)
00062 output[k]=temp[k];
00063 return output;
00064
00065 }
00066
00067 int Matrix::multiply_internally(double *x)
00068 {
00069 int ok=0;
00070
00071 double temp[4]={0,0,0,0};
00072 double x_homogeneous[4]={x[0],x[1],x[2],1};
00073 int k_x=0,k_y=0;
00074
00075 for(k_y=0;k_y<4;k_y++)
00076 for(k_x=0;k_x<4;k_x++)
00077 temp[k_y] += M[k_x+4*k_y]*x_homogeneous[k_x];
00078 for(int k=0;k<3;k++)
00079 x[k]=temp[k];
00080
00081 return ok;
00082 }
00083
00084
00085 int Matrix::set_identity()
00086 {
00087 for(int k_x=0;k_x<4;k_x++)
00088 for(int k_y=0;k_y<4;k_y++)
00089 {
00090 if(k_x==k_y)
00091 M[k_x+4*k_y]=1;
00092 else
00093 M[k_x+4*k_y]=0;
00094 }
00095
00096 return 0;
00097 }
00098
00099 int Matrix::set_zero()
00100 {
00101 for(int k=0;k<16;k++)
00102 M[k]=0;
00103 return 0;
00104 }
00105
00106
00107 int Matrix::set_translation(double *t)
00108 {
00109 M[3] = t[0];
00110 M[7] = t[1];
00111 M[11] = t[2];
00112
00113 return 0;
00114 }
00115
00116 int Matrix::set_translation(double tx,double ty,double tz)
00117 {
00118 double t[3]={tx,ty,tz};
00119 return set_translation(t);
00120 }
00121
00122 ostream& operator << (ostream& flux, Matrix M)
00123 {
00124 for(int k=0;k<4;k++)
00125 flux<<"("<<M.value(0,k)<<","<<M.value(1,k)<<","<<M.value(2,k)<<","<<M.value(3,k)<<")\n";
00126 return flux;
00127 }
00128
00129
00130 double Matrix::value(int k_x,int k_y) const
00131 {
00132 if(k_x<0 || k_x>=4 || k_y<0 || k_y>=4)
00133 {printf("Error (%d,%d) is not correct in v(k_x,k_y) in Matrix\n",k_x,k_y);exit(-1);}
00134 return M[k_x+4*k_y];
00135 }
00136
00137 double& Matrix::value(int k_x,int k_y)
00138 {
00139 if(k_x<0 || k_x>=4 || k_y<0 || k_y>=4)
00140 {printf("Error (%d,%d) is not correct in v(k_x,k_y) in Matrix\n",k_x,k_y);exit(-1);}
00141 return M[k_x+4*k_y];
00142 }
00143 double Matrix::v(int k_x,int k_y) const
00144 {
00145 if(k_x<0 || k_x>=4 || k_y<0 || k_y>=4)
00146 {printf("Error (%d,%d) is not correct in v(k_x,k_y) in Matrix\n",k_x,k_y);exit(-1);}
00147 return M[k_x+4*k_y];
00148 }
00149
00150 double& Matrix::v(int k_x,int k_y)
00151 {
00152 if(k_x<0 || k_x>=4 || k_y<0 || k_y>=4)
00153 {printf("Error (%d,%d) is not correct in v(k_x,k_y) in Matrix\n",k_x,k_y);exit(-1);}
00154 return M[k_x+4*k_y];
00155 }
00156
00157 double& Matrix::operator [](int k_dim)
00158 {
00159 if(k_dim<0 || k_dim>9)
00160 {printf("Error k_dim too large [%d] in operator [] in matrix\n",k_dim);exit(-1);}
00161 return M[k_dim];
00162 }
00163 double Matrix::operator [](int k_dim) const
00164 {
00165 if(k_dim<0 || k_dim>=4)
00166 {printf("Error k_dim too large [%d] in operator [] in matrix\n",k_dim);exit(-1);}
00167 return M[k_dim];
00168 }
00169
00170
00171
00172 Matrix& Matrix::operator/=(const double& alpha)
00173 {
00174 for(int k_x=0;k_x<4;k_x++)
00175 for(int k_y=0;k_y<4;k_y++)
00176 this->set_value(M[k_x+4*k_y]/alpha,k_x,k_y);
00177
00178 return *this;
00179 }
00180
00181
00182
00183
00184 Matrix& Matrix::operator=(const Matrix& _M)
00185 {
00186 for(int k_x=0;k_x<4;k_x++)
00187 for(int k_y=0;k_y<4;k_y++)
00188 this->set_value(_M.M[k_x+4*k_y],k_x,k_y);
00189
00190 return *this;
00191 }
00192
00193 Matrix& Matrix::operator+=(const Matrix& _M)
00194 {
00195 for(int k_x=0;k_x<4;k_x++)
00196 for(int k_y=0;k_y<4;k_y++)
00197 this->set_value(M[k_x+4*k_y]+_M.M[k_x+4*k_y],k_x,k_y);
00198
00199 return *this;
00200 }
00201
00202 int Matrix::set_value(double val,int k_x,int k_y)
00203 {
00204 M[k_x+4*k_y] = val;
00205 return 0;
00206 }
00207
00208 int Matrix::set_value(double x00,double x01,double x02,double x03,double x10,double x11,double x12, double x13,double x20,double x21,double x22,double x23,double x30,double x31,double x32,double x33)
00209 {
00210 M[0] = x00; M[4] = x10; M[8] = x20; M[12] = x30;
00211 M[1] = x01; M[5] = x11; M[9] = x21; M[13] = x31;
00212 M[2] = x02; M[6] = x12; M[10]= x22; M[14] = x32;
00213 M[3] = x03; M[7] = x13; M[11]= x23; M[15] = x33;
00214
00215 return 0;
00216 }
00217
00218 int Matrix::set_euler_angle(double theta_1,double theta_2,double theta_3)
00219 {
00220 double theta[3]={theta_1,theta_2,theta_3};
00221 return set_euler_angle(theta);
00222 }
00223
00224 int Matrix::set_euler_angle(double *r)
00225 {
00226 double cos_theta = cos(r[0]);
00227 double sin_theta = sin(r[0]);
00228
00229 double cos_phi = cos(r[1]);
00230 double sin_phi = sin(r[1]);
00231
00232 double cos_psi = cos(r[2]);
00233 double sin_psi = sin(r[2]);
00234
00235
00236 Matrix RX;
00237 RX.set_value( cos_theta,0,0);
00238 RX.set_value( cos_theta,1,1);
00239 RX.set_value( sin_theta,1,0);
00240 RX.set_value(-sin_theta,0,1);
00241
00242 Matrix RY;
00243 RY.set_value( cos_phi,1,1);
00244 RY.set_value( cos_phi,2,2);
00245 RY.set_value( sin_phi,2,1);
00246 RY.set_value(-sin_phi,1,2);
00247
00248 Matrix RZ;
00249 RZ.set_value( cos_psi,0,0);
00250 RZ.set_value( cos_psi,1,1);
00251 RZ.set_value( sin_psi,1,0);
00252 RZ.set_value(-sin_psi,0,1);
00253
00254
00255 multiply(RX);
00256 multiply(RY);
00257 multiply(RZ);
00258
00259
00260 return 0;
00261 }
00262
00263 int Matrix::get_position(double *p)
00264 {
00265 p[0]=M[3];
00266 p[1]=M[7];
00267 p[2]=M[11];
00268
00269 return 0;
00270 }
00271
00272 Matrix operator*(const Matrix& M1,const Matrix& M2)
00273 {
00274 double temp_M[16];
00275
00276 int k_x=0,k_y=0,k_m=0;
00277 double temp=0;
00278
00279
00280 for(k_x=0;k_x<4;k_x++)
00281 for(k_y=0;k_y<4;k_y++)
00282 {
00283
00284 for(k_m=0,temp=0;k_m<4;k_m++)
00285 {
00286 temp += M1.M[k_m+4*k_y] * (M2.M[k_x+4*k_m]);
00287 }
00288 temp_M[k_x+4*k_y] = temp;
00289 }
00290
00291 Matrix Z;
00292
00293 for(int k=0;k<16;k++)
00294 Z.set_value(temp_M[k],k,0);
00295
00296 return Z;
00297 }
00298
00299 Matrix operator*(const Matrix& M1,const double& alpha)
00300 {
00301 Matrix Z;
00302 int k_x=0,k_y=0;
00303 for(k_x=0;k_x<4;k_x++)
00304 for(k_y=0;k_y<4;k_y++)
00305 Z.set_value(alpha*M1.M[k_x+4*k_y],k_x,k_y);
00306 return Z;
00307 }
00308
00309
00310 Matrix operator*(const double& alpha,const Matrix& M1)
00311 {
00312 Matrix Z;
00313 int k_x=0,k_y=0;
00314 for(k_x=0;k_x<4;k_x++)
00315 for(k_y=0;k_y<4;k_y++)
00316 Z.set_value(alpha*M1.M[k_x+4*k_y],k_x,k_y);
00317 return Z;
00318 }
00319
00320 V_3D operator*(const Matrix& _M,const V_3D& _V)
00321 {
00322 V_3D result;
00323 V_3D copy = _V;
00324 int k_x=0;
00325 for(k_x=0;k_x<3;k_x++)
00326 result.set(k_x,_M.M[0+4*k_x]*copy.get(0)+_M.M[1+4*k_x]*copy.get(1)+_M.M[2+4*k_x]*copy.get(2)+_M.M[3+4*k_x]);
00327
00328 return result;
00329 }
00330
00331
00332 V_3D operator*(const V_3D& _V,const Matrix& _M)
00333 {
00334 V_3D result;
00335 int k_y=0;
00336 for(k_y=0;k_y<3;k_y++)
00337 result.set(k_y,_V[0]*_M.M[k_y+4*0]+_V[1]*_M.M[k_y+4*1]+_V[2]*_M.M[k_y+4*2]);
00338
00339 return result;
00340 }
00341
00342 Matrix operator+(const Matrix& M1,const Matrix& M2)
00343 {
00344 Matrix Z;
00345
00346 int k_x=0,k_y=0;
00347 for(k_x=0;k_x<4;k_x++)
00348 for(k_y=0;k_y<4;k_y++)
00349 {
00350 Z.set_value(M1.M[k_x+4*k_y]+M2.M[k_x+4*k_y],k_x,k_y);
00351 }
00352
00353 return Z;
00354 }
00355
00356
00357 Matrix operator-(const Matrix& M1,const Matrix& M2)
00358 {
00359 Matrix Z;
00360
00361 int k_x=0,k_y=0;
00362 for(k_x=0;k_x<4;k_x++)
00363 for(k_y=0;k_y<4;k_y++)
00364 {
00365 Z.set_value(M1.M[k_x+4*k_y]-M2.M[k_x+4*k_y],k_x,k_y);
00366 }
00367
00368 return Z;
00369 }
00370
00371 int Matrix::add_translation(double *t)
00372 {
00373 for(int k_dim=0;k_dim<3; M[3+4*k_dim]+=t[k_dim],k_dim++);
00374 return 0;
00375 }
00376
00377 int Matrix::add_translation(double tx,double ty,double tz)
00378 {
00379 double t[3]={tx,ty,tz};
00380 return add_translation(t);
00381 }
00382
00383
00384 int Matrix::set_vector_rotation(double *_v,double theta)
00385 {
00386 int ok=0;
00387
00388 double cos_theta = cos(theta);
00389 double sin_theta = sin(theta);
00390
00391
00392 int k_dim=0;
00393 double n=0;
00394 for(k_dim=0;k_dim<3;n+=_v[k_dim]*_v[k_dim],k_dim++);
00395 n=powf(n,0.5);
00396 for(k_dim=0;k_dim<3;_v[k_dim]/=n,k_dim++);
00397
00398 M[0] = cos_theta+(1-cos_theta)*_v[0]*_v[0];
00399 M[1] = (1-cos_theta)*_v[0]*_v[1]-sin_theta*_v[2];
00400 M[2] = (1-cos_theta)*_v[0]*_v[2]+sin_theta*_v[1];
00401
00402 M[4] = (1-cos_theta)*_v[1]*_v[0]+sin_theta*_v[2];
00403 M[5] = cos_theta + (1-cos_theta)*_v[1]*_v[1];
00404 M[6] = (1-cos_theta)*_v[1]*_v[2]-sin_theta*_v[0];
00405
00406 M[8] = (1-cos_theta)*_v[2]*_v[0]-sin_theta*_v[1];
00407 M[9] = (1-cos_theta)*_v[2]*_v[1]+sin_theta*_v[0];
00408 M[10] = cos_theta+(1-cos_theta)*_v[2]*_v[2];
00409
00410 return ok;
00411 }
00412
00413
00414 int Matrix::multiply_vector_rotation(double *_v,double theta)
00415 {
00416 int ok=0;
00417
00418 Matrix R;
00419 R.set_vector_rotation(_v,theta);
00420 multiply(R);
00421
00422 return ok;
00423 }
00424
00425 int Matrix::scale(double *s)
00426 {
00427 int k=0,k_dim=0;
00428 for(k=0;k<4;k++)
00429 for(k_dim=0;k_dim<3;k_dim++)
00430 M[k+4*k_dim] *= s[k_dim];
00431 return 0;
00432 }
00433
00434
00435 int Matrix::set_vector_rotation(double v_x,double v_y,double v_z,double theta)
00436 {
00437 double _v[3]={v_x,v_y,v_z};
00438 return set_vector_rotation(_v,theta);
00439 }
00440
00441 Matrix Matrix::get_rotation_part()
00442 {
00443 Matrix R;
00444
00445 int k_1=0,k_2=0;
00446 for(k_1=0;k_1<3;k_1++)
00447 for(k_2=0;k_2<3;k_2++)
00448 R.set_value(M[k_1+4*k_2],k_1,k_2);
00449
00450 return R;
00451 }
00452
00453 int Matrix::multiply_rotation_internally(double *n)
00454 {
00455 int ok=0;
00456
00457 double temp[4]={0,0,0,0};
00458 double n_homogeneous[4]={n[0],n[1],n[2],1};
00459 int k_x=0,k_y=0;
00460
00461 for(k_x=0;k_x<3;k_x++)
00462 for(k_y=0;k_y<3;k_y++)
00463 temp[k_y] += M[k_x+4*k_y]*n_homogeneous[k_x];
00464 for(int k=0;k<3;k++)
00465 n[k]=temp[k];
00466
00467 return ok;
00468 }
00469
00470 V_3D Matrix::get_position()
00471 {
00472 V_3D position;
00473 position.set(M[3+4*0],M[3+4*1],M[3+4*2]);
00474 return position;
00475 }
00476
00477 int Matrix::set_rotation_matrix(double *axis,double angle)
00478 {
00479 int k_dim=0;
00480
00481 double norm=0.0;
00482 for(k_dim=0;k_dim<3;k_dim++)
00483 norm += axis[k_dim]*axis[k_dim];
00484 norm = powf(norm,0.5);
00485 for(k_dim=0;k_dim<3;k_dim++)
00486 axis[k_dim] /= norm;
00487
00488
00489
00490 double cos_phi = cos(angle);
00491 double sin_phi = sin(angle);
00492 M[0] = cos_phi + (1-cos_phi)*axis[0]*axis[0];
00493 M[1] = (1-cos_phi)*axis[0]*axis[1]-sin_phi*axis[2];
00494 M[2] = (1-cos_phi)*axis[0]*axis[2]+sin_phi*axis[1];
00495 M[3] = 0.0;
00496 M[4] = (1-cos_phi)*axis[0]*axis[1]+sin_phi*axis[2];
00497 M[5] = cos_phi + (1-cos_phi)*axis[1]*axis[1];
00498 M[6] = (1-cos_phi)*axis[1]*axis[2]-sin_phi*axis[0];
00499 M[7] = 0.0;
00500 M[8] = (1-cos_phi)*axis[0]*axis[2]-sin_phi*axis[1];
00501 M[9] = (1-cos_phi)*axis[1]*axis[2]+sin_phi*axis[0];
00502 M[10]= cos_phi+(1-cos_phi)*axis[2]*axis[2];
00503 M[11]= 0.0;
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519 return 0;
00520
00521 }
00522
00523 int Matrix::set_rotation_matrix(double x_axis,double y_axis,double z_axis,double angle)
00524 {
00525 double axis[3]={x_axis,y_axis,z_axis};
00526 return set_rotation_matrix(axis,angle);
00527 }
00528
00529
00530 Matrix Matrix::multiply_rotation(double *axis,double angle)
00531 {
00532 Matrix R;
00533 R.set_rotation_matrix(axis,angle);
00534 *this = *this*R;
00535 return *this;
00536 }
00537
00538 Matrix Matrix::multiply_rotation(double x_axis,double y_axis,double z_axis,double angle)
00539 {
00540 Matrix R;
00541 R.set_rotation_matrix(x_axis,y_axis,z_axis,angle);
00542 *this = *this*R;
00543 return *this;
00544 }
00545
00546
00547 int operator==(const Matrix& M1,const Matrix& M2)
00548 {
00549 double epsilon=0.000001;
00550 int k=0;
00551 for(k=0;k<16;k++)
00552 if(fabs(M1.M[k]-M2.M[k])>epsilon)
00553 return 0;
00554 return 1;
00555 }
00556
00557 int operator!=(const Matrix& M1,const Matrix& M2)
00558 {
00559 return 1-(M1==M2);
00560 }
00561
00562
00563 int Matrix::set_rotation_part(Matrix R)
00564 {
00565 int k1=0,k2=0;
00566 for(k1=0;k1<3;k1++)
00567 for(k2=0;k2<3;k2++)
00568 M[4*k1+k2] = R.value(k1,k2);
00569 return 0;
00570 }
00571
00572 int Matrix::set_translation_part(Matrix T)
00573 {
00574 int k1=0;
00575 for(k1=0;k1<3;k1++)
00576 M[4*k1+3] = T.value(k1,3);
00577 return 0;
00578 }
00579
00580 double Matrix::det() const
00581 {
00582 return
00583 v(0,0)*
00584 (
00585 +v(1,1)*(v(2,2)*v(3,3)-v(2,3)*v(3,2))
00586 -v(1,2)*(v(2,1)*v(3,3)-v(2,3)*v(3,1))
00587 +v(1,3)*(v(2,1)*v(3,2)-v(2,2)*v(3,1))
00588 )
00589 -
00590 v(0,1)*
00591 (
00592 +v(1,0)*(v(2,2)*v(3,3)-v(2,3)*v(3,2))
00593 -v(1,2)*(v(2,0)*v(3,3)-v(2,3)*v(3,0))
00594 +v(1,3)*(v(2,0)*v(3,2)-v(2,2)*v(3,0))
00595 )
00596 +v(0,2)*
00597 (
00598 +v(1,0)*(v(2,1)*v(3,3)-v(2,3)*v(3,1))
00599 -v(1,1)*(v(2,0)*v(3,3)-v(2,3)*v(3,0))
00600 +v(1,3)*(v(2,0)*v(3,1)-v(2,1)*v(3,0))
00601 )
00602 -v(0,3)*
00603 (
00604 +v(1,0)*(v(2,1)*v(3,2)-v(2,2)*v(3,1))
00605 -v(1,1)*(v(2,0)*v(3,2)-v(2,2)*v(3,0))
00606 +v(1,2)*(v(2,0)*v(3,1)-v(2,1)*v(3,0))
00607 )
00608 ;
00609
00610 }
00611
00612 Matrix Matrix::invert() const
00613 {
00614 Matrix A;
00615 double d=det();
00616
00617 A.set_value(+v(1,1)*(v(2,2)*v(3,3)-v(2,3)*v(3,2))
00618 -v(1,2)*(v(2,1)*v(3,3)-v(2,3)*v(3,1))
00619 +v(1,3)*(v(2,1)*v(3,2)-v(2,2)*v(3,1))
00620 ,0,0);
00621
00622 A.set_value(-v(0,1)*(v(2,2)*v(3,3)-v(2,3)*v(3,2))
00623 +v(0,2)*(v(2,1)*v(3,3)-v(2,3)*v(3,1))
00624 -v(0,3)*(v(2,1)*v(3,2)-v(2,2)*v(3,1))
00625 ,0,1);
00626
00627 A.set_value(+v(0,1)*(v(1,2)*v(3,3)-v(1,3)*v(3,2))
00628 -v(0,2)*(v(1,1)*v(3,3)-v(1,3)*v(3,1))
00629 +v(0,3)*(v(1,1)*v(3,2)-v(1,2)*v(3,1))
00630 ,0,2);
00631
00632 A.set_value(-v(0,1)*(v(1,2)*v(2,3)-v(1,3)*v(2,2))
00633 +v(0,2)*(v(1,1)*v(2,3)-v(1,3)*v(2,1))
00634 -v(0,3)*(v(1,1)*v(2,2)-v(1,2)*v(2,1))
00635 ,0,3);
00636
00637
00638
00639 A.set_value(-v(1,0)*(v(2,2)*v(3,3)-v(2,3)*v(3,2))
00640 +v(1,2)*(v(2,0)*v(3,3)-v(2,3)*v(3,0))
00641 -v(1,3)*(v(2,0)*v(3,2)-v(2,2)*v(3,0))
00642 ,1,0);
00643
00644 A.set_value(+v(0,0)*(v(2,2)*v(3,3)-v(2,3)*v(3,2))
00645 -v(0,2)*(v(2,0)*v(3,3)-v(2,3)*v(3,0))
00646 +v(0,3)*(v(2,0)*v(3,2)-v(2,2)*v(3,0))
00647 ,1,1);
00648
00649 A.set_value(-v(0,0)*(v(1,2)*v(3,3)-v(1,3)*v(3,2))
00650 +v(0,2)*(v(1,0)*v(3,3)-v(1,3)*v(3,0))
00651 -v(0,3)*(v(1,0)*v(3,2)-v(1,2)*v(3,0))
00652 ,1,2);
00653
00654 A.set_value(+v(0,0)*(v(1,2)*v(2,3)-v(1,3)*v(2,2))
00655 -v(0,2)*(v(1,0)*v(2,3)-v(1,3)*v(2,0))
00656 +v(0,3)*(v(1,0)*v(2,2)-v(1,2)*v(2,0))
00657 ,1,3);
00658
00659
00660
00661
00662 A.set_value(+v(1,0)*(v(2,1)*v(3,3)-v(2,3)*v(3,1))
00663 -v(1,1)*(v(2,0)*v(3,3)-v(2,3)*v(3,0))
00664 +v(1,3)*(v(2,0)*v(3,1)-v(2,1)*v(3,0))
00665 ,2,0);
00666
00667 A.set_value(-v(0,0)*(v(2,1)*v(3,3)-v(2,3)*v(3,1))
00668 +v(0,1)*(v(2,0)*v(3,3)-v(2,3)*v(3,0))
00669 -v(0,3)*(v(2,0)*v(3,1)-v(2,1)*v(3,0))
00670 ,2,1);
00671
00672 A.set_value(+v(0,0)*(v(1,1)*v(3,3)-v(1,3)*v(3,1))
00673 -v(0,1)*(v(1,0)*v(3,3)-v(1,3)*v(3,0))
00674 +v(0,3)*(v(1,0)*v(3,1)-v(1,1)*v(3,0))
00675 ,2,2);
00676
00677 A.set_value(-v(0,0)*(v(1,1)*v(2,3)-v(1,3)*v(2,1))
00678 +v(0,1)*(v(1,0)*v(2,3)-v(1,3)*v(2,0))
00679 -v(0,3)*(v(1,0)*v(2,1)-v(1,1)*v(2,0))
00680 ,2,3);
00681
00682
00683
00684
00685
00686 A.set_value(-v(1,0)*(v(2,1)*v(3,2)-v(2,2)*v(3,1))
00687 +v(1,1)*(v(2,0)*v(3,2)-v(2,2)*v(3,0))
00688 -v(1,2)*(v(2,0)*v(3,1)-v(2,1)*v(3,0))
00689 ,3,0);
00690
00691 A.set_value(+v(0,0)*(v(2,1)*v(3,2)-v(2,2)*v(3,1))
00692 -v(0,1)*(v(2,0)*v(3,2)-v(2,2)*v(3,0))
00693 +v(0,2)*(v(2,0)*v(3,1)-v(2,1)*v(3,0))
00694 ,3,1);
00695
00696 A.set_value(-v(0,0)*(v(1,1)*v(3,2)-v(1,2)*v(3,1))
00697 +v(0,1)*(v(1,0)*v(3,2)-v(1,2)*v(3,0))
00698 -v(0,2)*(v(1,0)*v(3,1)-v(1,1)*v(3,0))
00699 ,3,2);
00700
00701 A.set_value(+v(0,0)*(v(1,1)*v(2,2)-v(1,2)*v(2,1))
00702 -v(0,1)*(v(1,0)*v(2,2)-v(1,2)*v(2,0))
00703 +v(0,2)*(v(1,0)*v(2,1)-v(1,1)*v(2,0))
00704 ,3,3);
00705
00706 A/=d;
00707
00708 return A;
00709 }
00710
00711
00712 int Matrix::build_rotation_matrix_to_vector(const V_3D u,const V_3D w)
00713 {
00714 V_3D v0,v1;
00715 v0 = u.normalized();
00716 v1 = w.normalized();
00717
00718 V_3D n = (v0.vector_prod(v1)).normalized();
00719 double cos_t=v0.dot(v1);
00720 double sin_t=powf(1.0-cos_t*cos_t,0.5);
00721
00722 (*this)(0,0)=cos_t+n[0]*n[0]*(1-cos_t);
00723 (*this)(1,0)=n[2]*sin_t+n[0]*n[1]*(1-cos_t);
00724 (*this)(2,0)=-n[1]*sin_t+n[0]*n[2]*(1-cos_t);
00725 (*this)(3,0)=0.0;
00726
00727 (*this)(0,1)=n[0]*n[1]*(1-cos_t)-n[2]*sin_t;
00728 (*this)(1,1)=cos_t+n[1]*n[1]*(1.0-cos_t);
00729 (*this)(2,1)=n[0]*sin_t+n[1]*n[2]*(1-cos_t);
00730 (*this)(3,1)=0.0;
00731
00732 (*this)(0,2)=n[1]*sin_t+n[0]*n[2]*(1-cos_t);
00733 (*this)(1,2)=-n[0]*sin_t+n[1]*n[2]*(1-cos_t);
00734 (*this)(2,2)=cos_t+n[2]*n[2]*(1-cos_t);
00735 (*this)(3,2)=0.0+90;
00736
00737 (*this)(0,3)=0.0;
00738 (*this)(1,3)=0.0;
00739 (*this)(2,3)=0.0;
00740 (*this)(3,3)=1.0;
00741
00742 return 0;
00743 }
00744
00745 double Matrix::operator ()(int k_1,int k_2) const
00746 {return value(k_2,k_1);}
00747
00748 double& Matrix::operator()(int k_1,int k_2)
00749 {return value(k_2,k_1);}