Changes in src/vector.cpp [c4d4df:7ea9e6]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/vector.cpp
-
Property mode
changed from
100755
to100644
rc4d4df r7ea9e6 21 21 /** Constructor of class vector. 22 22 */ 23 Vector::Vector( double x1, double x2,double x3) { x[0] = x1; x[1] = x2; x[2] = x3; };23 Vector::Vector(const double x1, const double x2, const double x3) { x[0] = x1; x[1] = x2; x[2] = x3; }; 24 24 25 25 /** Desctructor of class vector. … … 31 31 * \return \f$| x - y |^2\f$ 32 32 */ 33 double Vector::DistanceSquared(const Vector * y) const33 double Vector::DistanceSquared(const Vector * const y) const 34 34 { 35 35 double res = 0.; … … 43 43 * \return \f$| x - y |\f$ 44 44 */ 45 double Vector::Distance(const Vector * y) const45 double Vector::Distance(const Vector * const y) const 46 46 { 47 47 double res = 0.; … … 56 56 * \return \f$| x - y |\f$ 57 57 */ 58 double Vector::PeriodicDistance(const Vector * y, const double *cell_size) const58 double Vector::PeriodicDistance(const Vector * const y, const double * const cell_size) const 59 59 { 60 60 double res = Distance(y), tmp, matrix[NDIM*NDIM]; … … 94 94 * \return \f$| x - y |^2\f$ 95 95 */ 96 double Vector::PeriodicDistanceSquared(const Vector * y, const double *cell_size) const96 double Vector::PeriodicDistanceSquared(const Vector * const y, const double * const cell_size) const 97 97 { 98 98 double res = DistanceSquared(y), tmp, matrix[NDIM*NDIM]; … … 131 131 * Tries to translate a vector into each adjacent neighbouring cell. 132 132 */ 133 void Vector::KeepPeriodic(ofstream *out, double *matrix)133 void Vector::KeepPeriodic(ofstream *out, const double * const matrix) 134 134 { 135 135 // int N[NDIM]; … … 162 162 * \return \f$\langle x, y \rangle\f$ 163 163 */ 164 double Vector::ScalarProduct(const Vector * y) const164 double Vector::ScalarProduct(const Vector * const y) const 165 165 { 166 166 double res = 0.; … … 177 177 * \return \f$ x \times y \f& 178 178 */ 179 void Vector::VectorProduct(const Vector * y)179 void Vector::VectorProduct(const Vector * const y) 180 180 { 181 181 Vector tmp; … … 184 184 tmp.x[2] = x[0]* (y->x[1]) - x[1]* (y->x[0]); 185 185 this->CopyVector(&tmp); 186 187 186 }; 188 187 … … 192 191 * \return \f$\langle x, y \rangle\f$ 193 192 */ 194 void Vector::ProjectOntoPlane(const Vector * y)193 void Vector::ProjectOntoPlane(const Vector * const y) 195 194 { 196 195 Vector tmp; … … 217 216 * \return true - \a this contains intersection point on return, false - line is parallel to plane 218 217 */ 219 bool Vector::GetIntersectionWithPlane(ofstream *out, Vector *PlaneNormal, Vector *PlaneOffset, Vector *Origin, Vector *LineVector)218 bool Vector::GetIntersectionWithPlane(ofstream *out, const Vector * const PlaneNormal, const Vector * const PlaneOffset, const Vector * const Origin, const Vector * const LineVector) 220 219 { 221 220 double factor; … … 264 263 * \return distance to plane 265 264 */ 266 double Vector::DistanceToPlane(ofstream *out, Vector *PlaneNormal, Vector *PlaneOffset)265 double Vector::DistanceToPlane(ofstream *out, const Vector * const PlaneNormal, const Vector * const PlaneOffset) const 267 266 { 268 267 Vector temp; … … 276 275 temp.AddVector(this); 277 276 temp.SubtractVector(PlaneOffset); 278 279 return temp.Norm(); 277 double sign = temp.ScalarProduct(PlaneNormal); 278 if (fabs(sign) > MYEPSILON) 279 sign /= fabs(sign); 280 else 281 sign = 0.; 282 283 return (temp.Norm()*sign); 280 284 }; 281 285 … … 292 296 * \return true - \a this will contain the intersection on return, false - lines are parallel 293 297 */ 294 bool Vector::GetIntersectionOfTwoLinesOnPlane(ofstream *out, Vector *Line1a, Vector *Line1b, Vector *Line2a, Vector *Line2b, const Vector *PlaneNormal)298 bool Vector::GetIntersectionOfTwoLinesOnPlane(ofstream *out, const Vector * const Line1a, const Vector * const Line1b, const Vector * const Line2a, const Vector * const Line2b, const Vector *PlaneNormal) 295 299 { 296 300 bool result = true; … … 375 379 * \param *y array to second vector 376 380 */ 377 void Vector::ProjectIt(const Vector * y)381 void Vector::ProjectIt(const Vector * const y) 378 382 { 379 383 Vector helper(*y); … … 386 390 * \return Vector 387 391 */ 388 Vector Vector::Projection(const Vector * y) const392 Vector Vector::Projection(const Vector * const y) const 389 393 { 390 394 Vector helper(*y); … … 435 439 /** Zeros all components of this vector. 436 440 */ 437 void Vector::One( double one)441 void Vector::One(const double one) 438 442 { 439 443 for (int i=NDIM;i--;) … … 443 447 /** Initialises all components of this vector. 444 448 */ 445 void Vector::Init( double x1, double x2,double x3)449 void Vector::Init(const double x1, const double x2, const double x3) 446 450 { 447 451 x[0] = x1; … … 469 473 * @return true - vector is normalized, false - vector is not 470 474 */ 471 bool Vector::IsNormalTo(const Vector * normal) const475 bool Vector::IsNormalTo(const Vector * const normal) const 472 476 { 473 477 if (ScalarProduct(normal) < MYEPSILON) … … 481 485 * \return \f$\acos\bigl(frac{\langle x, y \rangle}{|x||y|}\bigr)\f$ 482 486 */ 483 double Vector::Angle(const Vector * y) const487 double Vector::Angle(const Vector * const y) const 484 488 { 485 489 double norm1 = Norm(), norm2 = y->Norm(); … … 500 504 * \param alpha rotation angle in radian 501 505 */ 502 void Vector::RotateVector(const Vector * axis, const double alpha)506 void Vector::RotateVector(const Vector * const axis, const double alpha) 503 507 { 504 508 Vector a,y; … … 656 660 * \param *factor pointer to scaling factor 657 661 */ 658 void Vector::Scale( double **factor)662 void Vector::Scale(const double ** const factor) 659 663 { 660 664 for (int i=NDIM;i--;) … … 662 666 }; 663 667 664 void Vector::Scale( double *factor)668 void Vector::Scale(const double * const factor) 665 669 { 666 670 for (int i=NDIM;i--;) … … 668 672 }; 669 673 670 void Vector::Scale( double factor)674 void Vector::Scale(const double factor) 671 675 { 672 676 for (int i=NDIM;i--;) … … 677 681 * \param trans[] translation vector. 678 682 */ 679 void Vector::Translate(const Vector * trans)683 void Vector::Translate(const Vector * const trans) 680 684 { 681 685 for (int i=NDIM;i--;) … … 687 691 * \param *Minv inverse matrix 688 692 */ 689 void Vector::WrapPeriodically(const double * M, const double *Minv)693 void Vector::WrapPeriodically(const double * const M, const double * const Minv) 690 694 { 691 695 MatrixMultiplication(Minv); … … 704 708 * \param *matrix NDIM_NDIM array 705 709 */ 706 void Vector::MatrixMultiplication(const double * M)710 void Vector::MatrixMultiplication(const double * const M) 707 711 { 708 712 Vector C; … … 716 720 }; 717 721 718 /** Calculate the inverse of a 3x3 matrix.722 /** Do a matrix multiplication with the \a *A' inverse. 719 723 * \param *matrix NDIM_NDIM array 720 724 */ 721 double * Vector::InverseMatrix(double *A) 722 { 723 double *B = Malloc<double>(NDIM * NDIM, "Vector::InverseMatrix: *B"); 725 void Vector::InverseMatrixMultiplication(const double * const A) 726 { 727 Vector C; 728 double B[NDIM*NDIM]; 724 729 double detA = RDET3(A); 725 730 double detAReci; 726 731 727 for (int i=0;i<NDIM*NDIM;++i)728 B[i] = 0.;729 732 // calculate the inverse B 730 733 if (fabs(detA) > MYEPSILON) {; // RDET3(A) yields precisely zero if A irregular … … 739 742 B[7] = -detAReci*RDET2(A[0],A[1],A[6],A[7]); // A_32 740 743 B[8] = detAReci*RDET2(A[0],A[1],A[3],A[4]); // A_33 741 }742 return B;743 };744 745 /** Do a matrix multiplication with the \a *A' inverse.746 * \param *matrix NDIM_NDIM array747 */748 void Vector::InverseMatrixMultiplication(const double *A)749 {750 Vector C;751 double B[NDIM*NDIM];752 double detA = RDET3(A);753 double detAReci;754 755 // calculate the inverse B756 if (fabs(detA) > MYEPSILON) {; // RDET3(A) yields precisely zero if A irregular757 detAReci = 1./detA;758 B[0] = detAReci*RDET2(A[4],A[5],A[7],A[8]); // A_11759 B[1] = -detAReci*RDET2(A[1],A[2],A[7],A[8]); // A_12760 B[2] = detAReci*RDET2(A[1],A[2],A[4],A[5]); // A_13761 B[3] = -detAReci*RDET2(A[3],A[5],A[6],A[8]); // A_21762 B[4] = detAReci*RDET2(A[0],A[2],A[6],A[8]); // A_22763 B[5] = -detAReci*RDET2(A[0],A[2],A[3],A[5]); // A_23764 B[6] = detAReci*RDET2(A[3],A[4],A[6],A[7]); // A_31765 B[7] = -detAReci*RDET2(A[0],A[1],A[6],A[7]); // A_32766 B[8] = detAReci*RDET2(A[0],A[1],A[3],A[4]); // A_33767 744 768 745 // do the matrix multiplication … … 786 763 * \param *factors three-component vector with the factor for each given vector 787 764 */ 788 void Vector::LinearCombinationOfVectors(const Vector * x1, const Vector *x2, const Vector *x3, double *factors)765 void Vector::LinearCombinationOfVectors(const Vector * const x1, const Vector * const x2, const Vector * const x3, const double * const factors) 789 766 { 790 767 for(int i=NDIM;i--;) … … 795 772 * \param n[] normal vector of mirror plane. 796 773 */ 797 void Vector::Mirror(const Vector * n)774 void Vector::Mirror(const Vector * const n) 798 775 { 799 776 double projection; … … 817 794 * \return true - success, vectors are linear independent, false - failure due to linear dependency 818 795 */ 819 bool Vector::MakeNormalVector(const Vector * y1, const Vector *y2, const Vector *y3)796 bool Vector::MakeNormalVector(const Vector * const y1, const Vector * const y2, const Vector * const y3) 820 797 { 821 798 Vector x1, x2; … … 853 830 * \return true - success, vectors are linear independent, false - failure due to linear dependency 854 831 */ 855 bool Vector::MakeNormalVector(const Vector * y1, const Vector *y2)832 bool Vector::MakeNormalVector(const Vector * const y1, const Vector * const y2) 856 833 { 857 834 Vector x1,x2; … … 884 861 * \return true - success, false - vector is zero 885 862 */ 886 bool Vector::MakeNormalVector(const Vector * y1)863 bool Vector::MakeNormalVector(const Vector * const y1) 887 864 { 888 865 bool result = false; … … 904 881 * \return true - success, false - failure (null vector given) 905 882 */ 906 bool Vector::GetOneNormalVector(const Vector * GivenVector)883 bool Vector::GetOneNormalVector(const Vector * const GivenVector) 907 884 { 908 885 int Components[NDIM]; // contains indices of non-zero components … … 950 927 * \return scaling parameter for this vector 951 928 */ 952 double Vector::CutsPlaneAt( Vector *A, Vector *B, Vector *C)929 double Vector::CutsPlaneAt(const Vector * const A, const Vector * const B, const Vector * const C) const 953 930 { 954 931 // cout << Verbose(3) << "For comparison: "; … … 965 942 * \return true if success, false if failed due to linear dependency 966 943 */ 967 bool Vector::LSQdistance( Vector **vectors, int num)944 bool Vector::LSQdistance(const Vector **vectors, int num) 968 945 { 969 946 int j; … … 1047 1024 * \param *y vector 1048 1025 */ 1049 void Vector::AddVector(const Vector * y)1026 void Vector::AddVector(const Vector * const y) 1050 1027 { 1051 1028 for (int i=NDIM;i--;) … … 1056 1033 * \param *y vector 1057 1034 */ 1058 void Vector::SubtractVector(const Vector * y)1035 void Vector::SubtractVector(const Vector * const y) 1059 1036 { 1060 1037 for (int i=NDIM;i--;) … … 1065 1042 * \param *y vector 1066 1043 */ 1067 void Vector::CopyVector(const Vector * y)1044 void Vector::CopyVector(const Vector * const y) 1068 1045 { 1069 1046 for (int i=NDIM;i--;) … … 1074 1051 * \param y vector 1075 1052 */ 1076 void Vector::CopyVector(const Vector y)1053 void Vector::CopyVector(const Vector &y) 1077 1054 { 1078 1055 for (int i=NDIM;i--;) … … 1085 1062 * \param check whether bounds shall be checked (true) or not (false) 1086 1063 */ 1087 void Vector::AskPosition( double *cell_size,bool check)1064 void Vector::AskPosition(const double * const cell_size, const bool check) 1088 1065 { 1089 1066 char coords[3] = {'x','y','z'}; … … 1113 1090 * \bug this is not yet working properly 1114 1091 */ 1115 bool Vector::SolveSystem(Vector * x1, Vector *x2, Vector *y, double alpha, double beta,double c)1092 bool Vector::SolveSystem(Vector * x1, Vector * x2, Vector * y, const double alpha, const double beta, const double c) 1116 1093 { 1117 1094 double D1,D2,D3,E1,E2,F1,F2,F3,p,q=0., A, B1, B2, C; … … 1139 1116 break; 1140 1117 case 2: 1141 flip( &x1->x[0],&x1->x[1]);1142 flip( &x2->x[0],&x2->x[1]);1143 flip( &y->x[0],&y->x[1]);1144 //flip( &x[0],&x[1]);1145 flip( &x1->x[1],&x1->x[2]);1146 flip( &x2->x[1],&x2->x[2]);1147 flip( &y->x[1],&y->x[2]);1148 //flip( &x[1],&x[2]);1118 flip(x1->x[0],x1->x[1]); 1119 flip(x2->x[0],x2->x[1]); 1120 flip(y->x[0],y->x[1]); 1121 //flip(x[0],x[1]); 1122 flip(x1->x[1],x1->x[2]); 1123 flip(x2->x[1],x2->x[2]); 1124 flip(y->x[1],y->x[2]); 1125 //flip(x[1],x[2]); 1149 1126 case 1: 1150 flip( &x1->x[0],&x1->x[1]);1151 flip( &x2->x[0],&x2->x[1]);1152 flip( &y->x[0],&y->x[1]);1153 //flip( &x[0],&x[1]);1154 flip( &x1->x[1],&x1->x[2]);1155 flip( &x2->x[1],&x2->x[2]);1156 flip( &y->x[1],&y->x[2]);1157 //flip( &x[1],&x[2]);1127 flip(x1->x[0],x1->x[1]); 1128 flip(x2->x[0],x2->x[1]); 1129 flip(y->x[0],y->x[1]); 1130 //flip(x[0],x[1]); 1131 flip(x1->x[1],x1->x[2]); 1132 flip(x2->x[1],x2->x[2]); 1133 flip(y->x[1],y->x[2]); 1134 //flip(x[1],x[2]); 1158 1135 break; 1159 1136 } … … 1224 1201 break; 1225 1202 case 2: 1226 flip( &x1->x[0],&x1->x[1]);1227 flip( &x2->x[0],&x2->x[1]);1228 flip( &y->x[0],&y->x[1]);1229 flip( &x[0],&x[1]);1230 flip( &x1->x[1],&x1->x[2]);1231 flip( &x2->x[1],&x2->x[2]);1232 flip( &y->x[1],&y->x[2]);1233 flip( &x[1],&x[2]);1203 flip(x1->x[0],x1->x[1]); 1204 flip(x2->x[0],x2->x[1]); 1205 flip(y->x[0],y->x[1]); 1206 flip(x[0],x[1]); 1207 flip(x1->x[1],x1->x[2]); 1208 flip(x2->x[1],x2->x[2]); 1209 flip(y->x[1],y->x[2]); 1210 flip(x[1],x[2]); 1234 1211 case 1: 1235 flip( &x1->x[0],&x1->x[1]);1236 flip( &x2->x[0],&x2->x[1]);1237 flip( &y->x[0],&y->x[1]);1238 //flip( &x[0],&x[1]);1239 flip( &x1->x[1],&x1->x[2]);1240 flip( &x2->x[1],&x2->x[2]);1241 flip( &y->x[1],&y->x[2]);1242 flip( &x[1],&x[2]);1212 flip(x1->x[0],x1->x[1]); 1213 flip(x2->x[0],x2->x[1]); 1214 flip(y->x[0],y->x[1]); 1215 //flip(x[0],x[1]); 1216 flip(x1->x[1],x1->x[2]); 1217 flip(x2->x[1],x2->x[2]); 1218 flip(y->x[1],y->x[2]); 1219 flip(x[1],x[2]); 1243 1220 break; 1244 1221 } … … 1276 1253 * @param three vectors forming the matrix that defines the shape of the parallelpiped 1277 1254 */ 1278 bool Vector::IsInParallelepiped( Vector offset, double *parallelepiped)1255 bool Vector::IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const 1279 1256 { 1280 1257 Vector a; -
Property mode
changed from
Note:
See TracChangeset
for help on using the changeset viewer.