Changes in src/vector.cpp [7b36fe:a67d19]
- File:
-
- 1 edited
-
src/vector.cpp (modified) (28 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/vector.cpp
r7b36fe ra67d19 15 15 #include "vector.hpp" 16 16 #include "verbose.hpp" 17 #include "World.hpp" 17 18 18 19 #include <gsl/gsl_linalg.h> … … 26 27 */ 27 28 Vector::Vector() { x[0] = x[1] = x[2] = 0.; }; 29 30 /** Constructor of class vector. 31 */ 32 Vector::Vector(const Vector * const a) 33 { 34 x[0] = a->x[0]; 35 x[1] = a->x[1]; 36 x[2] = a->x[2]; 37 }; 38 39 /** Constructor of class vector. 40 */ 41 Vector::Vector(const Vector &a) 42 { 43 x[0] = a.x[0]; 44 x[1] = a.x[1]; 45 x[2] = a.x[2]; 46 }; 28 47 29 48 /** Constructor of class vector. … … 234 253 Direction.SubtractVector(Origin); 235 254 Direction.Normalize(); 236 Log() << Verbose(1) << "INFO: Direction is " << Direction << "." << endl;255 DoLog(1) && (Log() << Verbose(1) << "INFO: Direction is " << Direction << "." << endl); 237 256 //Log() << Verbose(1) << "INFO: PlaneNormal is " << *PlaneNormal << " and PlaneOffset is " << *PlaneOffset << "." << endl; 238 257 factor = Direction.ScalarProduct(PlaneNormal); 239 258 if (fabs(factor) < MYEPSILON) { // Uniqueness: line parallel to plane? 240 Log() << Verbose(1) << "BAD: Line is parallel to plane, no intersection." << endl;259 DoLog(1) && (Log() << Verbose(1) << "BAD: Line is parallel to plane, no intersection." << endl); 241 260 return false; 242 261 } … … 245 264 factor = helper.ScalarProduct(PlaneNormal)/factor; 246 265 if (fabs(factor) < MYEPSILON) { // Origin is in-plane 247 Log() << Verbose(1) << "GOOD: Origin of line is in-plane." << endl;266 DoLog(1) && (Log() << Verbose(1) << "GOOD: Origin of line is in-plane." << endl); 248 267 CopyVector(Origin); 249 268 return true; … … 252 271 Direction.Scale(factor); 253 272 CopyVector(Origin); 254 Log() << Verbose(1) << "INFO: Scaled direction is " << Direction << "." << endl;273 DoLog(1) && (Log() << Verbose(1) << "INFO: Scaled direction is " << Direction << "." << endl); 255 274 AddVector(&Direction); 256 275 … … 259 278 helper.SubtractVector(PlaneOffset); 260 279 if (helper.ScalarProduct(PlaneNormal) < MYEPSILON) { 261 Log() << Verbose(1) << "GOOD: Intersection is " << *this << "." << endl;280 DoLog(1) && (Log() << Verbose(1) << "GOOD: Intersection is " << *this << "." << endl); 262 281 return true; 263 282 } else { 264 eLog() << Verbose(2) << "Intersection point " << *this << " is not on plane." << endl;283 DoeLog(2) && (eLog()<< Verbose(2) << "Intersection point " << *this << " is not on plane." << endl); 265 284 return false; 266 285 } 267 286 }; 268 287 269 /** Calculates the minimum distance of this vector to the plane.288 /** Calculates the minimum distance vector of this vector to the plane. 270 289 * \param *out output stream for debugging 271 290 * \param *PlaneNormal normal of plane 272 291 * \param *PlaneOffset offset of plane 273 * \return distance to plane274 */ 275 double Vector::DistanceToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const292 * \return distance vector onto to plane 293 */ 294 Vector Vector::GetDistanceVectorToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const 276 295 { 277 296 Vector temp; … … 291 310 sign = 0.; 292 311 293 return (temp.Norm()*sign); 312 temp.Normalize(); 313 temp.Scale(sign); 314 return temp; 315 }; 316 317 /** Calculates the minimum distance of this vector to the plane. 318 * \sa Vector::GetDistanceVectorToPlane() 319 * \param *out output stream for debugging 320 * \param *PlaneNormal normal of plane 321 * \param *PlaneOffset offset of plane 322 * \return distance to plane 323 */ 324 double Vector::DistanceToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const 325 { 326 return GetDistanceVectorToPlane(PlaneNormal,PlaneOffset).Norm(); 294 327 }; 295 328 … … 319 352 320 353 //Log() << Verbose(1) << "Coefficent matrix is:" << endl; 354 //ostream &output = Log() << Verbose(1); 321 355 //for (int i=0;i<4;i++) { 322 356 // for (int j=0;j<4;j++) 323 // cout << "\t" << M->Get(i,j);324 // cout << endl;357 // output << "\t" << M->Get(i,j); 358 // output << endl; 325 359 //} 326 360 if (fabs(M->Determinant()) > MYEPSILON) { 327 Log() << Verbose(1) << "Determinant of coefficient matrix is NOT zero." << endl;361 DoLog(1) && (Log() << Verbose(1) << "Determinant of coefficient matrix is NOT zero." << endl); 328 362 return false; 329 363 } 330 Log() << Verbose(1) << "INFO: Line1a = " << *Line1a << ", Line1b = " << *Line1b << ", Line2a = " << *Line2a << ", Line2b = " << *Line2b << "." << endl;364 DoLog(1) && (Log() << Verbose(1) << "INFO: Line1a = " << *Line1a << ", Line1b = " << *Line1b << ", Line2a = " << *Line2a << ", Line2b = " << *Line2b << "." << endl); 331 365 332 366 … … 344 378 d.CopyVector(Line2b); 345 379 d.SubtractVector(Line1b); 346 Log() << Verbose(1) << "INFO: a = " << a << ", b = " << b << ", c = " << c << "." << endl;380 DoLog(1) && (Log() << Verbose(1) << "INFO: a = " << a << ", b = " << b << ", c = " << c << "." << endl); 347 381 if ((a.NormSquared() < MYEPSILON) || (b.NormSquared() < MYEPSILON)) { 348 382 Zero(); 349 Log() << Verbose(1) << "At least one of the lines is ill-defined, i.e. offset equals second vector." << endl;383 DoLog(1) && (Log() << Verbose(1) << "At least one of the lines is ill-defined, i.e. offset equals second vector." << endl); 350 384 return false; 351 385 } … … 360 394 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) { 361 395 CopyVector(Line2a); 362 Log() << Verbose(1) << "Lines conincide." << endl;396 DoLog(1) && (Log() << Verbose(1) << "Lines conincide." << endl); 363 397 return true; 364 398 } else { … … 368 402 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) { 369 403 CopyVector(Line2b); 370 Log() << Verbose(1) << "Lines conincide." << endl;404 DoLog(1) && (Log() << Verbose(1) << "Lines conincide." << endl); 371 405 return true; 372 406 } 373 407 } 374 Log() << Verbose(1) << "Lines are parallel." << endl;408 DoLog(1) && (Log() << Verbose(1) << "Lines are parallel." << endl); 375 409 Zero(); 376 410 return false; … … 384 418 temp2.CopyVector(&a); 385 419 temp2.VectorProduct(&b); 386 Log() << Verbose(1) << "INFO: temp1 = " << temp1 << ", temp2 = " << temp2 << "." << endl;420 DoLog(1) && (Log() << Verbose(1) << "INFO: temp1 = " << temp1 << ", temp2 = " << temp2 << "." << endl); 387 421 if (fabs(temp2.NormSquared()) > MYEPSILON) 388 422 s = temp1.ScalarProduct(&temp2)/temp2.NormSquared(); 389 423 else 390 424 s = 0.; 391 Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct(&temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl;425 DoLog(1) && (Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct(&temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl); 392 426 393 427 // construct intersection … … 395 429 Scale(s); 396 430 AddVector(Line1a); 397 Log() << Verbose(1) << "Intersection is at " << *this << "." << endl;431 DoLog(1) && (Log() << Verbose(1) << "Intersection is at " << *this << "." << endl); 398 432 399 433 return true; … … 668 702 void Vector::Output() const 669 703 { 670 Log() << Verbose(0) << "(";704 DoLog(0) && (Log() << Verbose(0) << "("); 671 705 for (int i=0;i<NDIM;i++) { 672 Log() << Verbose(0) << x[i];706 DoLog(0) && (Log() << Verbose(0) << x[i]); 673 707 if (i != 2) 674 Log() << Verbose(0) << ",";675 } 676 Log() << Verbose(0) << ")";708 DoLog(0) && (Log() << Verbose(0) << ","); 709 } 710 DoLog(0) && (Log() << Verbose(0) << ")"); 677 711 }; 678 712 … … 783 817 x[i] = C.x[i]; 784 818 } else { 785 eLog() << Verbose(1) << "inverse of matrix does not exists: det A = " << detA << "." << endl;819 DoeLog(1) && (eLog()<< Verbose(1) << "inverse of matrix does not exists: det A = " << detA << "." << endl); 786 820 } 787 821 }; … … 809 843 projection = ScalarProduct(n)/n->ScalarProduct(n); // remove constancy from n (keep as logical one) 810 844 // withdraw projected vector twice from original one 811 Log() << Verbose(1) << "Vector: ";845 DoLog(1) && (Log() << Verbose(1) << "Vector: "); 812 846 Output(); 813 Log() << Verbose(0) << "\t";847 DoLog(0) && (Log() << Verbose(0) << "\t"); 814 848 for (int i=NDIM;i--;) 815 849 x[i] -= 2.*projection*n->x[i]; 816 Log() << Verbose(0) << "Projected vector: ";850 DoLog(0) && (Log() << Verbose(0) << "Projected vector: "); 817 851 Output(); 818 Log() << Verbose(0) << endl;852 DoLog(0) && (Log() << Verbose(0) << endl); 819 853 }; 820 854 … … 835 869 x2.SubtractVector(y2); 836 870 if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) { 837 eLog() << Verbose(2) << "Given vectors are linear dependent." << endl;871 DoeLog(2) && (eLog()<< Verbose(2) << "Given vectors are linear dependent." << endl); 838 872 return false; 839 873 } … … 869 903 Zero(); 870 904 if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) { 871 eLog() << Verbose(2) << "Given vectors are linear dependent." << endl;905 DoeLog(2) && (eLog()<< Verbose(2) << "Given vectors are linear dependent." << endl); 872 906 return false; 873 907 } … … 920 954 double norm; 921 955 922 Log() << Verbose(4);956 DoLog(4) && (Log() << Verbose(4)); 923 957 GivenVector->Output(); 924 Log() << Verbose(0) << endl;958 DoLog(0) && (Log() << Verbose(0) << endl); 925 959 for (j=NDIM;j--;) 926 960 Components[j] = -1; … … 929 963 if (fabs(GivenVector->x[j]) > MYEPSILON) 930 964 Components[Last++] = j; 931 Log() << Verbose(4) << Last << " Components != 0: (" << Components[0] << "," << Components[1] << "," << Components[2] << ")" << endl;965 DoLog(4) && (Log() << Verbose(4) << Last << " Components != 0: (" << Components[0] << "," << Components[1] << "," << Components[2] << ")" << endl); 932 966 933 967 switch(Last) { … … 979 1013 980 1014 for (j=0;j<num;j++) { 981 Log() << Verbose(1) << j << "th atom's vector: ";1015 DoLog(1) && (Log() << Verbose(1) << j << "th atom's vector: "); 982 1016 (vectors[j])->Output(); 983 Log() << Verbose(0) << endl;1017 DoLog(0) && (Log() << Verbose(0) << endl); 984 1018 } 985 1019 … … 1101 1135 j += i+1; 1102 1136 do { 1103 Log() << Verbose(0) << coords[i] << "[0.." << cell_size[j] << "]: ";1137 DoLog(0) && (Log() << Verbose(0) << coords[i] << "[0.." << cell_size[j] << "]: "); 1104 1138 cin >> x[i]; 1105 1139 } while (((x[i] < 0) || (x[i] >= cell_size[j])) && (check)); … … 1132 1166 B2 = cos(beta) * x2->Norm() * c; 1133 1167 C = c * c; 1134 Log() << Verbose(2) << "A " << A << "\tB " << B1 << "\tC " << C << endl;1168 DoLog(2) && (Log() << Verbose(2) << "A " << A << "\tB " << B1 << "\tC " << C << endl); 1135 1169 int flag = 0; 1136 1170 if (fabs(x1->x[0]) < MYEPSILON) { // check for zero components for the later flipping and back-flipping … … 1171 1205 D2 = -y->x[0]/x1->x[0]*x1->x[2]+y->x[2]; 1172 1206 D3 = y->x[0]/x1->x[0]*A-B1; 1173 Log() << Verbose(2) << "D1 " << D1 << "\tD2 " << D2 << "\tD3 " << D3 << "\n";1207 DoLog(2) && (Log() << Verbose(2) << "D1 " << D1 << "\tD2 " << D2 << "\tD3 " << D3 << "\n"); 1174 1208 if (fabs(D1) < MYEPSILON) { 1175 Log() << Verbose(2) << "D1 == 0!\n";1209 DoLog(2) && (Log() << Verbose(2) << "D1 == 0!\n"); 1176 1210 if (fabs(D2) > MYEPSILON) { 1177 Log() << Verbose(3) << "D2 != 0!\n";1211 DoLog(3) && (Log() << Verbose(3) << "D2 != 0!\n"); 1178 1212 x[2] = -D3/D2; 1179 1213 E1 = A/x1->x[0] + x1->x[2]/x1->x[0]*D3/D2; 1180 1214 E2 = -x1->x[1]/x1->x[0]; 1181 Log() << Verbose(3) << "E1 " << E1 << "\tE2 " << E2 << "\n";1215 DoLog(3) && (Log() << Verbose(3) << "E1 " << E1 << "\tE2 " << E2 << "\n"); 1182 1216 F1 = E1*E1 + 1.; 1183 1217 F2 = -E1*E2; 1184 1218 F3 = E1*E1 + D3*D3/(D2*D2) - C; 1185 Log() << Verbose(3) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n";1219 DoLog(3) && (Log() << Verbose(3) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n"); 1186 1220 if (fabs(F1) < MYEPSILON) { 1187 Log() << Verbose(4) << "F1 == 0!\n";1188 Log() << Verbose(4) << "Gleichungssystem linear\n";1221 DoLog(4) && (Log() << Verbose(4) << "F1 == 0!\n"); 1222 DoLog(4) && (Log() << Verbose(4) << "Gleichungssystem linear\n"); 1189 1223 x[1] = F3/(2.*F2); 1190 1224 } else { 1191 1225 p = F2/F1; 1192 1226 q = p*p - F3/F1; 1193 Log() << Verbose(4) << "p " << p << "\tq " << q << endl;1227 DoLog(4) && (Log() << Verbose(4) << "p " << p << "\tq " << q << endl); 1194 1228 if (q < 0) { 1195 Log() << Verbose(4) << "q < 0" << endl;1229 DoLog(4) && (Log() << Verbose(4) << "q < 0" << endl); 1196 1230 return false; 1197 1231 } … … 1200 1234 x[0] = A/x1->x[0] - x1->x[1]/x1->x[0]*x[1] + x1->x[2]/x1->x[0]*x[2]; 1201 1235 } else { 1202 Log() << Verbose(2) << "Gleichungssystem unterbestimmt\n";1236 DoLog(2) && (Log() << Verbose(2) << "Gleichungssystem unterbestimmt\n"); 1203 1237 return false; 1204 1238 } … … 1206 1240 E1 = A/x1->x[0]+x1->x[1]/x1->x[0]*D3/D1; 1207 1241 E2 = x1->x[1]/x1->x[0]*D2/D1 - x1->x[2]; 1208 Log() << Verbose(2) << "E1 " << E1 << "\tE2 " << E2 << "\n";1242 DoLog(2) && (Log() << Verbose(2) << "E1 " << E1 << "\tE2 " << E2 << "\n"); 1209 1243 F1 = E2*E2 + D2*D2/(D1*D1) + 1.; 1210 1244 F2 = -(E1*E2 + D2*D3/(D1*D1)); 1211 1245 F3 = E1*E1 + D3*D3/(D1*D1) - C; 1212 Log() << Verbose(2) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n";1246 DoLog(2) && (Log() << Verbose(2) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n"); 1213 1247 if (fabs(F1) < MYEPSILON) { 1214 Log() << Verbose(3) << "F1 == 0!\n";1215 Log() << Verbose(3) << "Gleichungssystem linear\n";1248 DoLog(3) && (Log() << Verbose(3) << "F1 == 0!\n"); 1249 DoLog(3) && (Log() << Verbose(3) << "Gleichungssystem linear\n"); 1216 1250 x[2] = F3/(2.*F2); 1217 1251 } else { 1218 1252 p = F2/F1; 1219 1253 q = p*p - F3/F1; 1220 Log() << Verbose(3) << "p " << p << "\tq " << q << endl;1254 DoLog(3) && (Log() << Verbose(3) << "p " << p << "\tq " << q << endl); 1221 1255 if (q < 0) { 1222 Log() << Verbose(3) << "q < 0" << endl;1256 DoLog(3) && (Log() << Verbose(3) << "q < 0" << endl); 1223 1257 return false; 1224 1258 } … … 1258 1292 for (j=2;j>=0;j--) { 1259 1293 k = (i & pot(2,j)) << j; 1260 Log() << Verbose(2) << "k " << k << "\tpot(2,j) " << pot(2,j) << endl;1294 DoLog(2) && (Log() << Verbose(2) << "k " << k << "\tpot(2,j) " << pot(2,j) << endl); 1261 1295 sign[j] = (k == 0) ? 1. : -1.; 1262 1296 } 1263 Log() << Verbose(2) << i << ": sign matrix is " << sign[0] << "\t" << sign[1] << "\t" << sign[2] << "\n";1297 DoLog(2) && (Log() << Verbose(2) << i << ": sign matrix is " << sign[0] << "\t" << sign[1] << "\t" << sign[2] << "\n"); 1264 1298 // apply sign matrix 1265 1299 for (j=NDIM;j--;) … … 1267 1301 // calculate angle and check 1268 1302 ang = x2->Angle (this); 1269 Log() << Verbose(1) << i << "th angle " << ang << "\tbeta " << cos(beta) << " :\t";1303 DoLog(1) && (Log() << Verbose(1) << i << "th angle " << ang << "\tbeta " << cos(beta) << " :\t"); 1270 1304 if (fabs(ang - cos(beta)) < MYEPSILON) { 1271 1305 break;
Note:
See TracChangeset
for help on using the changeset viewer.
