Changes in / [7c14ec:34e0592]
- Files:
-
- 4 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
configure.ac
r7c14ec r34e0592 11 11 12 12 # Checks for programs. 13 AM_PATH_CPPUNIT(1.9.6) 13 14 AC_PROG_CXX 14 15 AC_PROG_CC 16 AC_PROG_INSTALL 15 17 AC_CHECK_PROG([LATEX],[latex],[latex],[:]) 16 18 AC_CHECK_PROG([BIBTEX],[bibtex],[bibtex],[:]) -
src/Makefile.am
r7c14ec r34e0592 1 SOURCE = atom.cpp bond.cpp boundary.cpp builder.cpp config.cpp element.cpp ellipsoid.cpp helpers.cpp linkedcell.cpp moleculelist.cpp molecules.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp 2 HEADER = atom.hpp bond.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp helpers.hpp linkedcell.hpp molecules.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp 1 SOURCE = atom.cpp bond.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp helpers.cpp leastsquaremin.cpp linkedcell.cpp moleculelist.cpp molecules.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp 2 HEADER = atom.hpp bond.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp helpers.hpp leastsquaremin.hpp linkedcell.hpp molecules.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp 3 4 noinst_PROGRAMS = VectorUnitTest 3 5 4 6 bin_PROGRAMS = molecuilder joiner analyzer 5 7 molecuilderdir = ${bindir} 6 8 molecuilder_DATA = elements.db valence.db orbitals.db Hbonddistance.db Hbondangle.db 7 molecuilder_SOURCES = ${SOURCE} ${HEADER}9 molecuilder_SOURCES = ${SOURCE} builder.cpp ${HEADER} 8 10 joiner_SOURCES = joiner.cpp datacreator.cpp element.cpp helpers.cpp periodentafel.cpp parser.cpp verbose.cpp datacreator.hpp helpers.hpp parser.hpp periodentafel.hpp 9 11 analyzer_SOURCES = analyzer.cpp datacreator.cpp element.cpp helpers.cpp periodentafel.cpp parser.cpp verbose.cpp helpers.hpp periodentafel.hpp parser.hpp datacreator.hpp 10 12 13 TESTS = VectorUnitTest 14 check_PROGRAMS = $(TESTS) 15 VectorUnitTest_SOURCES = defs.hpp helpers.cpp helpers.hpp leastsquaremin.cpp leastsquaremin.hpp vectorunittest.cpp vectorunittest.hpp vector.cpp vector.hpp verbose.cpp verbose.hpp 16 VectorUnitTest_CXXFLAGS = $(CPPUNIT_CFLAGS) 17 VectorUnitTest_LDFLAGS = $(CPPUNIT_LIBS) -ldl 11 18 12 19 EXTRA_DIST = ${molecuilder_DATA} -
src/boundary.cpp
r7c14ec r34e0592 308 308 309 309 //*out << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl; 310 if (ProjectedVector. Projection(&AngleReferenceNormalVector) > 0) {310 if (ProjectedVector.ScalarProduct(&AngleReferenceNormalVector) > 0) { 311 311 angle = 2. * M_PI - angle; 312 312 } … … 620 620 } 621 621 622 //CalculateConcavityPerBoundaryPoint(out, TesselStruct); 623 StoreTrianglesinFile(out, mol, filename, "-first"); 624 622 625 // First step: RemovePointFromTesselatedSurface 623 PointRunner = TesselStruct->PointsOnBoundary.begin(); 624 PointAdvance = PointRunner; // we need an advanced point, as the PointRunner might get removed 625 while (PointRunner != TesselStruct->PointsOnBoundary.end()) { 626 PointAdvance++; 627 point = PointRunner->second; 628 *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl; 629 Concavity = true; 630 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) { 626 do { 627 Concavity = false; 628 PointRunner = TesselStruct->PointsOnBoundary.begin(); 629 PointAdvance = PointRunner; // we need an advanced point, as the PointRunner might get removed 630 while (PointRunner != TesselStruct->PointsOnBoundary.end()) { 631 PointAdvance++; 632 point = PointRunner->second; 633 *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl; 634 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) { 635 line = LineRunner->second; 636 *out << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl; 637 } 638 if (!line->CheckConvexityCriterion(out)) { 639 *out << Verbose(1) << "... point " << *point << " cannot be on convex envelope." << endl; 640 // remove the point 641 Concavity = true; 642 TesselStruct->RemovePointFromTesselatedSurface(out, point); 643 } 644 PointRunner = PointAdvance; 645 } 646 647 //CalculateConcavityPerBoundaryPoint(out, TesselStruct); 648 //StoreTrianglesinFile(out, mol, filename, "-second"); 649 650 // second step: PickFarthestofTwoBaselines 651 LineRunner = TesselStruct->LinesOnBoundary.begin(); 652 LineAdvance = LineRunner; // we need an advanced line, as the LineRunner might get removed 653 while (LineRunner != TesselStruct->LinesOnBoundary.end()) { 654 LineAdvance++; 631 655 line = LineRunner->second; 632 *out << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl; 633 Concavity = Concavity && (!line->CheckConvexityCriterion(out)); 634 } 635 if (Concavity) { 636 *out << Verbose(1) << "... point " << *point << " cannot be on convex envelope." << endl; 637 // remove the point 638 TesselStruct->RemovePointFromTesselatedSurface(out, point); 639 } 640 PointRunner = PointAdvance; 641 } 642 643 644 // // print all lines 645 // LineRunner = TesselStruct->LinesOnBoundary.begin(); 646 // LineAdvance = LineRunner; // we need an advanced line, as the LineRunner might get removed 647 // *out << Verbose(1) << "Printing all boundary lines for debugging." << endl; 648 // while (LineRunner != TesselStruct->LinesOnBoundary.end()) { 649 // LineAdvance++; 650 // line = LineRunner->second; 651 // *out << Verbose(2) << "INFO: Current line is " << *line << "." << endl; 652 // if (LineAdvance != TesselStruct->LinesOnBoundary.end()) 653 // *out << Verbose(2) << "INFO: Next line will be " << *(LineAdvance->second) << "." << endl; 654 // LineRunner = LineAdvance; 655 // } 656 // 657 // // print all triangles 658 // TriangleRunner = TesselStruct->TrianglesOnBoundary.begin(); 659 // TriangleAdvance = TriangleRunner; // we need an advanced line, as the LineRunner might get removed 660 // *out << Verbose(1) << "Printing all boundary triangles for debugging." << endl; 661 // while (TriangleRunner != TesselStruct->TrianglesOnBoundary.end()) { 662 // TriangleAdvance++; 663 // *out << Verbose(2) << "INFO: Current triangle is " << *(TriangleRunner->second) << "." << endl; 664 // if (TriangleAdvance != TesselStruct->TrianglesOnBoundary.end()) 665 // *out << Verbose(2) << "INFO: Next triangle will be " << *(TriangleAdvance->second) << "." << endl; 666 // TriangleRunner = TriangleAdvance; 667 // } 668 669 // second step: PickFarthestofTwoBaselines 656 *out << Verbose(1) << "INFO: Picking farthest baseline for line is " << *line << "." << endl; 657 // take highest of both lines 658 if (TesselStruct->IsConvexRectangle(out, line) == NULL) { 659 TesselStruct->PickFarthestofTwoBaselines(out, line); 660 Concavity = true; 661 } 662 LineRunner = LineAdvance; 663 } 664 } while (Concavity); 665 CalculateConcavityPerBoundaryPoint(out, TesselStruct); 666 StoreTrianglesinFile(out, mol, filename, "-third"); 667 668 // third step: IsConvexRectangle 670 669 LineRunner = TesselStruct->LinesOnBoundary.begin(); 671 670 LineAdvance = LineRunner; // we need an advanced line, as the LineRunner might get removed … … 673 672 LineAdvance++; 674 673 line = LineRunner->second; 675 *out << Verbose(1) << "INFO: Picking farthest baseline for line is " << *line << "." << endl; 676 if (LineAdvance != TesselStruct->LinesOnBoundary.end()) 677 // take highest of both lines 678 TesselStruct->PickFarthestofTwoBaselines(out, line); 674 *out << Verbose(1) << "INFO: Current line is " << *line << "." << endl; 675 //if (LineAdvance != TesselStruct->LinesOnBoundary.end()) 676 //*out << Verbose(1) << "INFO: Next line will be " << *(LineAdvance->second) << "." << endl; 677 if (!line->CheckConvexityCriterion(out)) { 678 *out << Verbose(1) << "... line " << *line << " is concave, flipping it." << endl; 679 680 // take highest of both lines 681 point = TesselStruct->IsConvexRectangle(out, line); 682 if (point != NULL) 683 TesselStruct->RemovePointFromTesselatedSurface(out, point); 684 } 679 685 LineRunner = LineAdvance; 680 686 } 681 687 688 CalculateConcavityPerBoundaryPoint(out, TesselStruct); 689 StoreTrianglesinFile(out, mol, filename, "-fourth"); 690 691 // end 692 *out << Verbose(0) << "End of ConvexizeNonconvexEnvelope" << endl; 693 return volume; 694 }; 695 696 /** Calculates the concavity for each of the BoundaryPointSet's in a Tesselation. 697 * Sets BoundaryPointSet::value equal to the number of connected lines that are not convex. 698 * \param *out output stream for debugging 699 * \param *TesselStruct pointer to Tesselation structure 700 */ 701 void CalculateConcavityPerBoundaryPoint(ofstream *out, class Tesselation *TesselStruct) 702 { 703 class BoundaryPointSet *point = NULL; 704 class BoundaryLineSet *line = NULL; 682 705 // calculate remaining concavity 683 for (Point Runner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {706 for (PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) { 684 707 point = PointRunner->second; 685 708 *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl; … … 692 715 } 693 716 } 694 717 }; 718 719 /** Stores triangles to file. 720 * \param *out output stream for debugging 721 * \param *mol molecule with atoms and bonds 722 * \param *filename prefix of filename 723 * \param *extraSuffix intermediate suffix 724 */ 725 void StoreTrianglesinFile(ofstream *out, molecule *mol, const char *filename, const char *extraSuffix) 726 { 695 727 // 4. Store triangles in tecplot file 696 728 if (filename != NULL) { 697 729 if (DoTecplotOutput) { 698 730 string OutputName(filename); 699 OutputName.append( "_intermed");731 OutputName.append(extraSuffix); 700 732 OutputName.append(TecplotSuffix); 701 733 ofstream *tecplot = new ofstream(OutputName.c_str()); … … 706 738 if (DoRaster3DOutput) { 707 739 string OutputName(filename); 708 OutputName.append( "_intermed");740 OutputName.append(extraSuffix); 709 741 OutputName.append(Raster3DSuffix); 710 742 ofstream *rasterplot = new ofstream(OutputName.c_str()); … … 714 746 } 715 747 } 716 717 // third step: IsConvexRectangle718 LineRunner = TesselStruct->LinesOnBoundary.begin();719 LineAdvance = LineRunner; // we need an advanced line, as the LineRunner might get removed720 while (LineRunner != TesselStruct->LinesOnBoundary.end()) {721 LineAdvance++;722 line = LineRunner->second;723 *out << Verbose(1) << "INFO: Current line is " << *line << "." << endl;724 if (LineAdvance != TesselStruct->LinesOnBoundary.end())725 *out << Verbose(1) << "INFO: Next line will be " << *(LineAdvance->second) << "." << endl;726 if (!line->CheckConvexityCriterion(out)) {727 *out << Verbose(1) << "... line " << *line << " is concave, flipping it." << endl;728 729 // take highest of both lines730 point = TesselStruct->IsConvexRectangle(out, line);731 if (point != NULL)732 TesselStruct->RemovePointFromTesselatedSurface(out, point);733 }734 LineRunner = LineAdvance;735 }736 737 // calculate remaining concavity738 for (PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {739 point = PointRunner->second;740 *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl;741 point->value = 0;742 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {743 line = LineRunner->second;744 *out << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl;745 if (!line->CheckConvexityCriterion(out))746 point->value += 1;747 }748 }749 750 // 4. Store triangles in tecplot file751 if (filename != NULL) {752 if (DoTecplotOutput) {753 string OutputName(filename);754 OutputName.append(TecplotSuffix);755 ofstream *tecplot = new ofstream(OutputName.c_str());756 WriteTecplotFile(out, tecplot, mol->TesselStruct, mol, 0);757 tecplot->close();758 delete(tecplot);759 }760 if (DoRaster3DOutput) {761 string OutputName(filename);762 OutputName.append(Raster3DSuffix);763 ofstream *rasterplot = new ofstream(OutputName.c_str());764 WriteRaster3dFile(out, rasterplot, mol->TesselStruct, mol);765 rasterplot->close();766 delete(rasterplot);767 }768 }769 770 // end771 *out << Verbose(0) << "End of ConvexizeNonconvexEnvelope" << endl;772 return volume;773 748 }; 774 749 … … 804 779 G = sqrt(((a + b + c) * (a + b + c) - 2 * (a * a + b * b + c * c)) / 16.); // area of tesselated triangle 805 780 x.MakeNormalVector(runner->second->endpoints[0]->node->node, runner->second->endpoints[1]->node->node, runner->second->endpoints[2]->node->node); 806 x.Scale(runner->second->endpoints[1]->node->node-> Projection(&x));781 x.Scale(runner->second->endpoints[1]->node->node->ScalarProduct(&x)); 807 782 h = x.Norm(); // distance of CoG to triangle 808 783 PyramidVolume = (1. / 3.) * G * h; // this formula holds for _all_ pyramids (independent of n-edge base or (not) centered peak) -
src/boundary.hpp
r7c14ec r34e0592 42 42 void FindNextSuitablePoint(class BoundaryTriangleSet *BaseTriangle, class BoundaryLineSet *BaseLine, atom*& OptCandidate, Vector *OptCandidateCenter, double *ShortestAngle, const double RADIUS, LinkedCell *LC); 43 43 Boundaries *GetBoundaryPoints(ofstream *out, molecule *mol); 44 void CalculateConcavityPerBoundaryPoint(ofstream *out, class Tesselation *TesselStruct); 45 void StoreTrianglesinFile(ofstream *out, molecule *mol, const char *filename, const char *extraSuffix); 46 44 47 45 48 #endif /*BOUNDARY_HPP_*/ -
src/builder.cpp
r7c14ec r34e0592 188 188 // remove the projection onto the rotation plane of the second angle 189 189 n.CopyVector(&y); 190 n.Scale(first->x. Projection(&y));190 n.Scale(first->x.ScalarProduct(&y)); 191 191 cout << "N1: ", 192 192 n.Output((ofstream *)&cout); … … 197 197 cout << endl; 198 198 n.CopyVector(&z); 199 n.Scale(first->x. Projection(&z));199 n.Scale(first->x.ScalarProduct(&z)); 200 200 cout << "N2: ", 201 201 n.Output((ofstream *)&cout); -
src/config.hpp
r7c14ec r34e0592 18 18 #include "molecules.hpp" 19 19 #include "periodentafel.hpp" 20 21 class ConfigFileBuffer { 22 public: 23 char **buffer; 24 int *LineMapping; 25 int CurrentLine; 26 int NoLines; 27 28 ConfigFileBuffer(); 29 ConfigFileBuffer(char *filename); 30 ~ConfigFileBuffer(); 31 32 void InitMapping(); 33 void MapIonTypesInBuffer(int NoAtoms); 34 }; 20 35 21 36 /** The config file. -
src/molecules.cpp
r7c14ec r34e0592 7 7 #include "config.hpp" 8 8 #include "molecules.hpp" 9 10 /************************************* Other Functions *************************************/11 12 /** Determines sum of squared distances of \a X to all \a **vectors.13 * \param *x reference vector14 * \param *params15 * \return sum of square distances16 */17 double LSQ (const gsl_vector * x, void * params)18 {19 double sum = 0.;20 struct LSQ_params *par = (struct LSQ_params *)params;21 Vector **vectors = par->vectors;22 int num = par->num;23 24 for (int i=num;i--;) {25 for(int j=NDIM;j--;)26 sum += (gsl_vector_get(x,j) - (vectors[i])->x[j])*(gsl_vector_get(x,j) - (vectors[i])->x[j]);27 }28 29 return sum;30 };31 9 32 10 /************************************* Functions for class molecule *********************************/ -
src/molecules.hpp
r7c14ec r34e0592 28 28 #include "bond.hpp" 29 29 #include "element.hpp" 30 #include "leastsquaremin.hpp" 30 31 #include "linkedcell.hpp" 31 32 #include "parser.hpp" … … 83 84 84 85 85 // some algebraic matrix stuff86 #define RDET3(a) ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3]) //!< hard-coded determinant of a 3x3 matrix87 #define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2)) //!< hard-coded determinant of a 2x2 matrix88 89 90 /** Parameter structure for least square minimsation.91 */92 struct LSQ_params {93 Vector **vectors;94 int num;95 };96 97 double LSQ(const gsl_vector * x, void * params);98 99 /** Parameter structure for least square minimsation.100 */101 struct lsq_params {102 gsl_vector *x;103 const molecule *mol;104 element *type;105 };106 86 107 87 #define MaxThermostats 6 //!< maximum number of thermostat entries in Ions#ThermostatNames and Ions#ThermostatImplemented … … 323 303 }; 324 304 325 class ConfigFileBuffer {326 public:327 char **buffer;328 int *LineMapping;329 int CurrentLine;330 int NoLines;331 332 ConfigFileBuffer();333 ConfigFileBuffer(char *filename);334 ~ConfigFileBuffer();335 336 void InitMapping();337 void MapIonTypesInBuffer(int NoAtoms);338 };339 340 305 341 306 #endif /*MOLECULES_HPP_*/ -
src/tesselation.cpp
r7c14ec r34e0592 16 16 LinesCount = 0; 17 17 Nr = -1; 18 value = 0.; 18 19 }; 19 20 … … 26 27 LinesCount = 0; 27 28 Nr = Walker->nr; 29 value = 0.; 28 30 }; 29 31 … … 148 150 void BoundaryLineSet::AddTriangle(class BoundaryTriangleSet *triangle) 149 151 { 150 cout << Verbose(6) << "Add " << triangle->Nr << " to line " << *this << "." 151 << endl; 152 cout << Verbose(6) << "Add " << triangle->Nr << " to line " << *this << "." << endl; 152 153 triangles.insert(TrianglePair(triangle->Nr, triangle)); 153 154 }; … … 177 178 if (triangles.size() != 2) { 178 179 *out << Verbose(1) << "ERROR: Baseline " << *this << " is connect to less than two triangles, Tesselation incomplete!" << endl; 179 return false;180 return true; 180 181 } 181 182 // check normal vectors 182 183 // have a normal vector on the base line pointing outwards 183 *out << Verbose(3) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;184 //*out << Verbose(3) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl; 184 185 BaseLineCenter.CopyVector(endpoints[0]->node->node); 185 186 BaseLineCenter.AddVector(endpoints[1]->node->node); … … 187 188 BaseLine.CopyVector(endpoints[0]->node->node); 188 189 BaseLine.SubtractVector(endpoints[1]->node->node); 189 *out << Verbose(3) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;190 //*out << Verbose(3) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl; 190 191 191 192 BaseLineNormal.Zero(); … … 195 196 class BoundaryPointSet *node = NULL; 196 197 for(TriangleMap::iterator runner = triangles.begin(); runner != triangles.end(); runner++) { 197 *out << Verbose(3) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;198 //*out << Verbose(3) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl; 198 199 NormalCheck.AddVector(&runner->second->NormalVector); 199 200 NormalCheck.Scale(sign); … … 202 203 node = runner->second->GetThirdEndpoint(this); 203 204 if (node != NULL) { 204 *out << Verbose(3) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;205 //*out << Verbose(3) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl; 205 206 helper[i].CopyVector(node->node->node); 206 207 helper[i].SubtractVector(&BaseLineCenter); 207 208 helper[i].MakeNormalVector(&BaseLine); // we want to compare the triangle's heights' angles! 208 *out << Verbose(4) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;209 //*out << Verbose(4) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl; 209 210 i++; 210 211 } else { 211 *out << Verbose(2) << "WARNING: I cannot find third node in triangle, something's wrong." << endl;212 //*out << Verbose(2) << "WARNING: I cannot find third node in triangle, something's wrong." << endl; 212 213 return true; 213 214 } 214 215 } 215 *out << Verbose(3) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;216 //*out << Verbose(3) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl; 216 217 if (NormalCheck.NormSquared() < MYEPSILON) { 217 *out << Verbose( 3) << "Normalvectors of both triangles are the same: convex." << endl;218 *out << Verbose(2) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl; 218 219 return true; 219 220 } 220 221 double angle = GetAngle(helper[0], helper[1], BaseLineNormal); 221 if ((angle - M_PI) > -MYEPSILON) 222 if ((angle - M_PI) > -MYEPSILON) { 223 *out << Verbose(2) << "ACCEPT: Angle is greater than pi: convex." << endl; 222 224 return true; 223 else 225 } else { 226 *out << Verbose(2) << "REJECT: Angle is less than pi: concave." << endl; 224 227 return false; 228 } 225 229 } 226 230 … … 349 353 350 354 // make it always point inward (any offset vector onto plane projected onto normal vector suffices) 351 if (NormalVector. Projection(&OtherVector) > 0)355 if (NormalVector.ScalarProduct(&OtherVector) > 0.) 352 356 NormalVector.Scale(-1.); 353 357 }; … … 737 741 TrialVector.CopyVector(checker->second->node->node); 738 742 TrialVector.SubtractVector(A->second->node->node); 739 distance = TrialVector. Projection(&PlaneVector);743 distance = TrialVector.ScalarProduct(&PlaneVector); 740 744 if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok 741 745 continue; … … 897 901 TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center! 898 902 //*out << Verbose(2) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl; 899 if (PropagationVector. Projection(&TempVector) > 0) // make sure normal propagation vector points outward from baseline903 if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline 900 904 PropagationVector.Scale(-1.); 901 905 *out << Verbose(4) << "PropagationVector of base triangle is " << PropagationVector << endl; … … 957 961 TempVector.SubtractVector(Center); 958 962 // make it always point outward 959 if (VirtualNormalVector. Projection(&TempVector) < 0)963 if (VirtualNormalVector.ScalarProduct(&TempVector) < 0) 960 964 VirtualNormalVector.Scale(-1.); 961 965 // calculate angle … … 1530 1534 AddTesselationLine(TPS[0], TPS[1], 0); 1531 1535 } 1532 cout << Verbose(2) << "Projection is " << BTS->NormalVector. Projection(&Oben) << "." << endl;1536 cout << Verbose(2) << "Projection is " << BTS->NormalVector.ScalarProduct(&Oben) << "." << endl; 1533 1537 } 1534 1538 if (BTS != NULL) // we have created one starting triangle … … 1751 1755 class BoundaryPointSet *Spot = NULL; 1752 1756 class BoundaryLineSet *OtherBase; 1753 Vector *ClosestPoint [2];1757 Vector *ClosestPoint; 1754 1758 1755 1759 int m=0; … … 1764 1768 1765 1769 // get the closest point on each line to the other line 1766 ClosestPoint[0] = GetClosestPointBetweenLine(out, Base, OtherBase); 1767 ClosestPoint[1] = GetClosestPointBetweenLine(out, OtherBase, Base); 1770 ClosestPoint = GetClosestPointBetweenLine(out, Base, OtherBase); 1768 1771 1769 1772 // delete the temporary other base line … … 1771 1774 1772 1775 // get the distance vector from Base line to OtherBase line 1773 Vector DistanceToIntersection, BaseLine; 1776 Vector DistanceToIntersection[2], BaseLine; 1777 double distance[2]; 1774 1778 BaseLine.CopyVector(Base->endpoints[1]->node->node); 1775 1779 BaseLine.SubtractVector(Base->endpoints[0]->node->node); 1776 DistanceToIntersection.CopyVector(ClosestPoint[0]); 1777 DistanceToIntersection.SubtractVector(Base->endpoints[0]->node->node); 1778 Spot = Base->endpoints[1]; 1779 if (BaseLine.ScalarProduct(&DistanceToIntersection) < -MYEPSILON) { 1780 DistanceToIntersection.CopyVector(ClosestPoint[0]); 1781 DistanceToIntersection.SubtractVector(Base->endpoints[1]->node->node); 1782 Spot = Base->endpoints[0]; 1783 if (BaseLine.ScalarProduct(&DistanceToIntersection) < -MYEPSILON) { 1784 *out << Verbose(3) << "ERROR: Something's very wrong here, both SKPs return negative?!" << endl; 1785 return NULL; 1786 } 1787 } 1788 if ((BaseLine.NormSquared() - DistanceToIntersection.NormSquared()) < -MYEPSILON) { // distance is smaller: concave 1789 *out << Verbose(3) << "INFO: Rectangle of triangles of base line " << *Base << " is concave: Base line squared length " << BaseLine.NormSquared() << " against Distance to intersection squared " << DistanceToIntersection.NormSquared() << "." << endl; 1780 for (int i=0;i<2;i++) { 1781 DistanceToIntersection[i].CopyVector(ClosestPoint); 1782 DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node); 1783 distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]); 1784 } 1785 delete(ClosestPoint); 1786 if ((distance[0] * distance[1]) > 0) { // have same sign? 1787 *out << Verbose(3) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << "' rectangle is concave." << endl; 1788 if (distance[0] < distance[1]) { 1789 Spot = Base->endpoints[0]; 1790 } else { 1791 Spot = Base->endpoints[1]; 1792 } 1790 1793 return Spot; 1791 } else { // base line is longer: convex1792 *out << Verbose(3) << " INFO: Rectangle of triangles of base line " << *Base << " is concave." << endl;1794 } else { // different sign, i.e. we are in between 1795 *out << Verbose(3) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl; 1793 1796 return NULL; 1794 1797 } … … 1796 1799 }; 1797 1800 1801 void Tesselation::PrintAllBoundaryPoints(ofstream *out) 1802 { 1803 // print all lines 1804 *out << Verbose(1) << "Printing all boundary points for debugging:" << endl; 1805 for (PointMap::iterator PointRunner = PointsOnBoundary.begin();PointRunner != PointsOnBoundary.end(); PointRunner++) 1806 *out << Verbose(2) << *(PointRunner->second) << endl; 1807 }; 1808 1809 void Tesselation::PrintAllBoundaryLines(ofstream *out) 1810 { 1811 // print all lines 1812 *out << Verbose(1) << "Printing all boundary lines for debugging:" << endl; 1813 for (LineMap::iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++) 1814 *out << Verbose(2) << *(LineRunner->second) << endl; 1815 }; 1816 1817 void Tesselation::PrintAllBoundaryTriangles(ofstream *out) 1818 { 1819 // print all triangles 1820 *out << Verbose(1) << "Printing all boundary triangles for debugging:" << endl; 1821 for (TriangleMap::iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++) 1822 *out << Verbose(2) << *(TriangleRunner->second) << endl; 1823 }; 1798 1824 1799 1825 /** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher". … … 1826 1852 Distance.SubtractVector(ClosestPoint[0]); 1827 1853 1828 // delete the temporary other base line 1854 // delete the temporary other base line and the closest points 1855 delete(ClosestPoint[0]); 1856 delete(ClosestPoint[1]); 1829 1857 delete(OtherBase); 1830 1858 … … 1843 1871 BaseLineNormal.AddVector(&(runner->second->NormalVector)); 1844 1872 } 1845 BaseLineNormal.Scale( -1./2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()1873 BaseLineNormal.Scale(1./2.); 1846 1874 1847 1875 if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip … … 1866 1894 // construct the plane of the two baselines (i.e. take both their directional vectors) 1867 1895 Vector Normal; 1868 Vector OtherBaseline;1869 Normal.CopyVector(Base->endpoints[1]->node->node);1870 Normal.SubtractVector(Base->endpoints[0]->node->node);1896 Vector Baseline, OtherBaseline; 1897 Baseline.CopyVector(Base->endpoints[1]->node->node); 1898 Baseline.SubtractVector(Base->endpoints[0]->node->node); 1871 1899 OtherBaseline.CopyVector(OtherBase->endpoints[1]->node->node); 1872 1900 OtherBaseline.SubtractVector(OtherBase->endpoints[0]->node->node); 1901 Normal.CopyVector(&Baseline); 1873 1902 Normal.VectorProduct(&OtherBaseline); 1874 1903 Normal.Normalize(); 1875 1876 // project one offset point of OtherBase onto this plane 1904 *out << Verbose(4) << "First direction is " << Baseline << ", second direction is " << OtherBaseline << ", normal of intersection plane is " << Normal << "." << endl; 1905 1906 // project one offset point of OtherBase onto this plane (and add plane offset vector) 1877 1907 Vector NewOffset; 1878 1908 NewOffset.CopyVector(OtherBase->endpoints[0]->node->node); 1909 NewOffset.SubtractVector(Base->endpoints[0]->node->node); 1879 1910 NewOffset.ProjectOntoPlane(&Normal); 1911 NewOffset.AddVector(Base->endpoints[0]->node->node); 1880 1912 Vector NewDirection; 1881 NewDirection.CopyVector( OtherBase->endpoints[1]->node->node);1882 NewDirection. ProjectOntoPlane(&Normal);1913 NewDirection.CopyVector(&NewOffset); 1914 NewDirection.AddVector(&OtherBaseline); 1883 1915 1884 1916 // calculate the intersection between this projected baseline and Base 1885 1917 Vector *Intersection = new Vector; 1886 1918 Intersection->GetIntersectionOfTwoLinesOnPlane(out, Base->endpoints[0]->node->node, Base->endpoints[1]->node->node, &NewOffset, &NewDirection, &Normal); 1919 Normal.CopyVector(Intersection); 1920 Normal.SubtractVector(Base->endpoints[0]->node->node); 1921 *out << Verbose(3) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(&Baseline)/Baseline.NormSquared()) << "." << endl; 1887 1922 1888 1923 return Intersection; … … 2595 2630 int i; 2596 2631 2632 if (point == NULL) { 2633 *out << Verbose(1) << "ERROR: Cannot remove the point " << point << ", it's NULL!" << endl; 2634 return 0.; 2635 } else 2636 *out << Verbose(2) << "Removing point " << *point << " from tesselated boundary ..." << endl; 2637 2597 2638 // copy old location for the volume 2598 2639 OldPoint.CopyVector(point->node->node); … … 2609 2650 count+=LineRunner->second->triangles.size(); 2610 2651 numbers = new int[count]; 2652 class BoundaryTriangleSet **Candidates = new BoundaryTriangleSet*[count]; 2611 2653 i=0; 2612 2654 for (LineMap::iterator LineRunner = point->lines.begin(); (point != NULL) && (LineRunner != point->lines.end()); LineRunner++) { … … 2614 2656 for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) { 2615 2657 triangle = TriangleRunner->second; 2616 *out << Verbose(2) << "Erasing triangle " << *triangle << "." << endl;2658 Candidates[i] = triangle; 2617 2659 numbers[i++] = triangle->Nr; 2618 RemoveTesselationTriangle(triangle); 2619 triangle = NULL; 2620 } 2621 } 2660 } 2661 } 2662 for (int j=0;j<i;j++) { 2663 RemoveTesselationTriangle(Candidates[j]); 2664 } 2665 delete[](Candidates); 2622 2666 *out << Verbose(1) << i << " triangles were removed." << endl; 2623 2667 … … 3023 3067 double GetAngle(const Vector &point, const Vector &reference, const Vector OrthogonalVector) 3024 3068 { 3025 if (reference.Is Null())3069 if (reference.IsZero()) 3026 3070 return M_PI; 3027 3071 3028 3072 // calculate both angles and correct with in-plane vector 3029 if (point.Is Null())3073 if (point.IsZero()) 3030 3074 return M_PI; 3031 3075 double phi = point.Angle(&reference); -
src/tesselation.hpp
r7c14ec r34e0592 230 230 bool AddBoundaryPoint(TesselPoint *Walker, int n); 231 231 232 // print for debugging 233 void PrintAllBoundaryPoints(ofstream *out); 234 void PrintAllBoundaryLines(ofstream *out); 235 void PrintAllBoundaryTriangles(ofstream *out); 236 237 232 238 PointMap PointsOnBoundary; 233 239 LineMap LinesOnBoundary; -
src/tesselationhelpers.cpp
r7c14ec r34e0592 359 359 HeightA.SubtractVector(&par.x1); 360 360 361 t1 = HeightA. Projection(&SideA)/SideA.ScalarProduct(&SideA);361 t1 = HeightA.ScalarProduct(&SideA)/SideA.ScalarProduct(&SideA); 362 362 363 363 SideB.CopyVector(&par.x4); … … 366 366 HeightB.SubtractVector(&par.x3); 367 367 368 t2 = HeightB. Projection(&SideB)/SideB.ScalarProduct(&SideB);368 t2 = HeightB.ScalarProduct(&SideB)/SideB.ScalarProduct(&SideB); 369 369 370 370 cout << Verbose(2) << "Intersection " << intersection << " is at " -
src/vector.cpp
r7c14ec r34e0592 6 6 7 7 8 #include "molecules.hpp" 9 8 #include "defs.hpp" 9 #include "helpers.hpp" 10 #include "leastsquaremin.hpp" 11 #include "vector.hpp" 12 #include "verbose.hpp" 10 13 11 14 /************************************ Functions for class vector ************************************/ … … 209 212 * \param *PlaneNormal Plane's normal vector 210 213 * \param *PlaneOffset Plane's offset vector 211 * \param * LineVectorfirst vector of line212 * \param *LineVector 2second vector of line214 * \param *Origin first vector of line 215 * \param *LineVector second vector of line 213 216 * \return true - \a this contains intersection point on return, false - line is parallel to plane 214 217 */ … … 221 224 Direction.CopyVector(LineVector); 222 225 Direction.SubtractVector(Origin); 226 //*out << Verbose(4) << "INFO: Direction is " << Direction << "." << endl; 223 227 factor = Direction.ScalarProduct(PlaneNormal); 224 228 if (factor < MYEPSILON) { // Uniqueness: line parallel to plane? … … 227 231 } 228 232 helper.CopyVector(PlaneOffset); 229 helper.SubtractVector( LineVector);233 helper.SubtractVector(Origin); 230 234 factor = helper.ScalarProduct(PlaneNormal)/factor; 231 235 //factor = Origin->ScalarProduct(PlaneNormal)*(-PlaneOffset->ScalarProduct(PlaneNormal))/(Direction.ScalarProduct(PlaneNormal)); 232 236 Direction.Scale(factor); 233 CopyVector(LineVector); 237 CopyVector(Origin); 238 //*out << Verbose(4) << "INFO: Scaled direction is " << Direction << "." << endl; 234 239 AddVector(&Direction); 235 240 … … 238 243 helper.SubtractVector(PlaneOffset); 239 244 if (helper.ScalarProduct(PlaneNormal) < MYEPSILON) { 240 *out << Verbose(2) << "INFO: Intersection at " << *this << " is good." << endl;245 //*out << Verbose(2) << "INFO: Intersection at " << *this << " is good." << endl; 241 246 return true; 242 247 } else { … … 247 252 248 253 /** Calculates the intersection of the two lines that are both on the same plane. 249 * Note that we do not check whether they are on the same plane. 254 * We construct auxiliary plane with its vector normal to one line direction and the PlaneNormal, then a vector 255 * from the first line's offset onto the plane. Finally, scale by factor is 1/cos(angle(line1,line2..)) = 1/SP(...), and 256 * project onto the first line's direction and add its offset. 250 257 * \param *out output stream for debugging 251 258 * \param *Line1a first vector of first line … … 258 265 bool Vector::GetIntersectionOfTwoLinesOnPlane(ofstream *out, Vector *Line1a, Vector *Line1b, Vector *Line2a, Vector *Line2b, const Vector *PlaneNormal) 259 266 { 260 double factor1, factor2; 261 Vector helper, Line, LineNormal, *OtherNormal = NULL; 262 const Vector *Normal; 263 bool result = false; 264 265 // create Plane normal vector 266 if (PlaneNormal == NULL) { 267 OtherNormal = new Vector(0.,0.,0.); 268 if (!OtherNormal->MakeNormalVector(Line1a, Line1b, Line2a)) 269 if (!OtherNormal->MakeNormalVector(Line1a, Line1b, Line2b)) { 270 *out << Verbose(1) << "ERROR: GetIntersectionOfTwoLinesOnPlane() cannot create a normal of the plane, everything is linear dependent." << endl; 271 return false; 272 } 273 Normal = OtherNormal; 274 } else 275 Normal = PlaneNormal; 276 *out << Verbose(3) << "INFO: Normal of plane is " << *Normal << "." << endl; 277 278 // create normal vector to one line 279 Line.CopyVector(Line1b); 280 Line.SubtractVector(Line1a); 281 LineNormal.MakeNormalVector(&Line, Normal); 282 *out << Verbose(3) << "INFO: Normal of first line is " << LineNormal << "." << endl; 283 284 // check if lines are parallel 285 helper.CopyVector(Line2b); 286 helper.SubtractVector(Line2a); 287 if (fabs(helper.ScalarProduct(&LineNormal)) < MYEPSILON) { 288 *out << Verbose(1) << "Lines " << helper << " and " << Line << " are parallel, no cross point!" << endl; 289 result = false; 290 } else { 291 helper.CopyVector(Line2a); 292 helper.SubtractVector(Line1a); 293 factor1 = helper.ScalarProduct(&LineNormal); 294 helper.CopyVector(Line2b); 295 helper.SubtractVector(Line1a); 296 factor2 = helper.ScalarProduct(&LineNormal); 297 if (fabs(factor2) > MYEPSILON) { 298 CopyVector(Line2a); 299 helper.Scale(factor1/factor2); 300 AddVector(&helper); 267 bool result = true; 268 Vector Direction, OtherDirection; 269 Vector AuxiliaryNormal; 270 Vector Distance; 271 const Vector *Normal = NULL; 272 Vector *ConstructedNormal = NULL; 273 bool FreeNormal = false; 274 275 // construct both direction vectors 276 Zero(); 277 Direction.CopyVector(Line1b); 278 Direction.SubtractVector(Line1a); 279 if (Direction.IsZero()) 280 return false; 281 OtherDirection.CopyVector(Line2b); 282 OtherDirection.SubtractVector(Line2a); 283 if (OtherDirection.IsZero()) 284 return false; 285 286 Direction.Normalize(); 287 OtherDirection.Normalize(); 288 289 //*out << Verbose(4) << "INFO: Normalized Direction " << Direction << " and OtherDirection " << OtherDirection << "." << endl; 290 291 if (fabs(OtherDirection.ScalarProduct(&Direction) - 1.) < MYEPSILON) { // lines are parallel 292 if ((Line1a == Line2a) || (Line1a == Line2b)) 293 CopyVector(Line1a); 294 else if ((Line1b == Line2b) || (Line1b == Line2b)) 295 CopyVector(Line1b); 296 else 297 return false; 298 *out << Verbose(4) << "INFO: Intersection is " << *this << "." << endl; 299 return true; 300 } else { 301 // check whether we have a plane normal vector 302 if (PlaneNormal == NULL) { 303 ConstructedNormal = new Vector; 304 ConstructedNormal->MakeNormalVector(&Direction, &OtherDirection); 305 Normal = ConstructedNormal; 306 FreeNormal = true; 307 } else 308 Normal = PlaneNormal; 309 310 AuxiliaryNormal.MakeNormalVector(&OtherDirection, Normal); 311 //*out << Verbose(4) << "INFO: PlaneNormal is " << *Normal << " and AuxiliaryNormal " << AuxiliaryNormal << "." << endl; 312 313 Distance.CopyVector(Line2a); 314 Distance.SubtractVector(Line1a); 315 //*out << Verbose(4) << "INFO: Distance is " << Distance << "." << endl; 316 if (Distance.IsZero()) { 317 // offsets are equal, match found 318 CopyVector(Line1a); 301 319 result = true; 302 320 } else { 303 Zero(); 304 result = false; 321 CopyVector(Distance.Projection(&AuxiliaryNormal)); 322 //*out << Verbose(4) << "INFO: Projected Distance is " << *this << "." << endl; 323 double factor = Direction.ScalarProduct(&AuxiliaryNormal); 324 //*out << Verbose(4) << "INFO: Scaling factor is " << factor << "." << endl; 325 Scale(1./(factor*factor)); 326 //*out << Verbose(4) << "INFO: Scaled Distance is " << *this << "." << endl; 327 CopyVector(Projection(&Direction)); 328 //*out << Verbose(4) << "INFO: Distance, projected into Direction, is " << *this << "." << endl; 329 if (this->IsZero()) 330 result = false; 331 else 332 result = true; 333 AddVector(Line1a); 305 334 } 306 } 307 308 if (OtherNormal != NULL) 309 delete(OtherNormal); 335 336 if (FreeNormal) 337 delete(ConstructedNormal); 338 } 339 if (result) 340 *out << Verbose(4) << "INFO: Intersection is " << *this << "." << endl; 310 341 311 342 return result; … … 314 345 /** Calculates the projection of a vector onto another \a *y. 315 346 * \param *y array to second vector 316 * \return \f$\langle x, y \rangle\f$ 317 */ 318 double Vector::Projection(const Vector *y) const 319 { 320 return (ScalarProduct(y)); 347 */ 348 void Vector::ProjectIt(const Vector *y) 349 { 350 Vector helper(*y); 351 helper.Scale(-(ScalarProduct(y))); 352 AddVector(&helper); 353 }; 354 355 /** Calculates the projection of a vector onto another \a *y. 356 * \param *y array to second vector 357 * \return Vector 358 */ 359 Vector Vector::Projection(const Vector *y) const 360 { 361 Vector helper(*y); 362 helper.Scale((ScalarProduct(y)/y->NormSquared())); 363 364 return helper; 321 365 }; 322 366 … … 380 424 * @return true - vector is zero, false - vector is not 381 425 */ 382 bool Vector::IsNull() const 383 { 384 return (fabs(x[0]+x[1]+x[2]) < MYEPSILON); 426 bool Vector::IsZero() const 427 { 428 return (fabs(x[0])+fabs(x[1])+fabs(x[2]) < MYEPSILON); 429 }; 430 431 /** Checks whether vector has length of 1. 432 * @return true - vector is normalized, false - vector is not 433 */ 434 bool Vector::IsOne() const 435 { 436 return (fabs(Norm() - 1.) < MYEPSILON); 437 }; 438 439 /** Checks whether vector is normal to \a *normal. 440 * @return true - vector is normalized, false - vector is not 441 */ 442 bool Vector::IsNormalTo(const Vector *normal) const 443 { 444 if (ScalarProduct(normal) < MYEPSILON) 445 return true; 446 else 447 return false; 385 448 }; 386 449 … … 392 455 { 393 456 double norm1 = Norm(), norm2 = y->Norm(); 394 double angle = 1;457 double angle = -1; 395 458 if ((fabs(norm1) > MYEPSILON) && (fabs(norm2) > MYEPSILON)) 396 459 angle = this->ScalarProduct(y)/norm1/norm2; … … 413 476 // normalise this vector with respect to axis 414 477 a.CopyVector(this); 415 a.Scale(Projection(axis)); 416 SubtractVector(&a); 478 a.ProjectOntoPlane(axis); 417 479 // construct normal vector 418 480 y.MakeNormalVector(axis,this); … … 427 489 }; 428 490 491 /** Compares vector \a to vector \a b component-wise. 492 * \param a base vector 493 * \param b vector components to add 494 * \return a == b 495 */ 496 bool operator==(const Vector& a, const Vector& b) 497 { 498 bool status = true; 499 for (int i=0;i<NDIM;i++) 500 status = status && (fabs(a.x[i] - b.x[i]) < MYEPSILON); 501 return status; 502 }; 503 429 504 /** Sums vector \a to this lhs component-wise. 430 505 * \param a base vector … … 437 512 return a; 438 513 }; 514 515 /** Subtracts vector \a from this lhs component-wise. 516 * \param a base vector 517 * \param b vector components to add 518 * \return lhs - a 519 */ 520 Vector& operator-=(Vector& a, const Vector& b) 521 { 522 a.SubtractVector(&b); 523 return a; 524 }; 525 439 526 /** factor each component of \a a times a double \a m. 440 527 * \param a base vector … … 461 548 }; 462 549 550 /** Subtracts vector \a from \b component-wise. 551 * \param a first vector 552 * \param b second vector 553 * \return a - b 554 */ 555 Vector& operator-(const Vector& a, const Vector& b) 556 { 557 Vector *x = new Vector; 558 x->CopyVector(&a); 559 x->SubtractVector(&b); 560 return *x; 561 }; 562 463 563 /** Factors given vector \a a times \a m. 464 564 * \param a vector 465 565 * \param m factor 466 * \return a + b566 * \return m * a 467 567 */ 468 568 Vector& operator*(const Vector& a, const double m) 569 { 570 Vector *x = new Vector; 571 x->CopyVector(&a); 572 x->Scale(m); 573 return *x; 574 }; 575 576 /** Factors given vector \a a times \a m. 577 * \param m factor 578 * \param a vector 579 * \return m * a 580 */ 581 Vector& operator*(const double m, const Vector& a ) 469 582 { 470 583 Vector *x = new Vector; … … 660 773 x2.SubtractVector(y2); 661 774 if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) { 662 cout << Verbose(4) << " Given vectors are linear dependent." << endl;775 cout << Verbose(4) << "WARNING: Given vectors are linear dependent." << endl; 663 776 return false; 664 777 } … … 694 807 Zero(); 695 808 if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) { 696 cout << Verbose(4) << " Given vectors are linear dependent." << endl;809 cout << Verbose(4) << "WARNING: Given vectors are linear dependent." << endl; 697 810 return false; 698 811 } … … 714 827 /** Calculates orthonormal vector to one given vectors. 715 828 * Just subtracts the projection onto the given vector from this vector. 829 * The removed part of the vector is Vector::Projection() 716 830 * \param *x1 vector 717 831 * \return true - success, false - vector is zero … … 720 834 { 721 835 bool result = false; 722 double factor = y1-> Projection(this)/y1->Norm()/y1->Norm();836 double factor = y1->ScalarProduct(this)/y1->NormSquared(); 723 837 Vector x1; 724 838 x1.CopyVector(y1); … … 777 891 }; 778 892 779 /** Determines param ter needed to multiply this vector to obtain intersection point with plane defined by \a *A, \a *B and \a *C.893 /** Determines parameter needed to multiply this vector to obtain intersection point with plane defined by \a *A, \a *B and \a *C. 780 894 * \param *A first plane vector 781 895 * \param *B second plane vector … … 790 904 // cout << "C " << C->Projection(this) << "\t"; 791 905 // cout << endl; 792 return A-> Projection(this);906 return A->ScalarProduct(this); 793 907 }; 794 908 … … 902 1016 for (int i=NDIM;i--;) 903 1017 this->x[i] = y->x[i]; 1018 } 1019 1020 /** Copy vector \a y componentwise. 1021 * \param y vector 1022 */ 1023 void Vector::CopyVector(const Vector y) 1024 { 1025 for (int i=NDIM;i--;) 1026 this->x[i] = y.x[i]; 904 1027 } 905 1028 -
src/vector.hpp
r7c14ec r34e0592 5 5 6 6 #include "helpers.hpp" 7 8 #include <gsl/gsl_vector.h> 9 #include <gsl/gsl_multimin.h> 7 10 8 11 class Vector; … … 24 27 double PeriodicDistanceSquared(const Vector *y, const double *cell_size) const; 25 28 double ScalarProduct(const Vector *y) const; 26 double Projection(const Vector *y) const;27 29 double Norm() const; 28 30 double NormSquared() const; 29 31 double Angle(const Vector *y) const; 30 bool IsNull() const; 32 bool IsZero() const; 33 bool IsOne() const; 34 bool IsNormalTo(const Vector *normal) const; 31 35 32 36 void AddVector(const Vector *y); 33 37 void SubtractVector(const Vector *y); 34 38 void CopyVector(const Vector *y); 39 void CopyVector(const Vector y); 35 40 void RotateVector(const Vector *y, const double alpha); 36 41 void VectorProduct(const Vector *y); 37 42 void ProjectOntoPlane(const Vector *y); 43 void ProjectIt(const Vector *y); 44 Vector Projection(const Vector *y) const; 38 45 void Zero(); 39 46 void One(double one); … … 64 71 65 72 ostream & operator << (ostream& ost, const Vector &m); 66 //Vector& operator+=(Vector& a, const Vector& b); 67 //Vector& operator*=(Vector& a, const double m); 68 //Vector& operator*(const Vector& a, const double m); 69 //Vector& operator+(const Vector& a, const Vector& b); 73 bool operator==(const Vector& a, const Vector& b); 74 Vector& operator+=(Vector& a, const Vector& b); 75 Vector& operator-=(Vector& a, const Vector& b); 76 Vector& operator*=(Vector& a, const double m); 77 Vector& operator*(const Vector& a, const double m); 78 Vector& operator*(const double m, const Vector& a); 79 Vector& operator+(const Vector& a, const Vector& b); 80 Vector& operator-(const Vector& a, const Vector& b); 81 82 // some algebraic matrix stuff 83 #define RDET3(a) ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3]) //!< hard-coded determinant of a 3x3 matrix 84 #define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2)) //!< hard-coded determinant of a 2x2 matrix 85 86 70 87 71 88 #endif /*VECTOR_HPP_*/
Note:
See TracChangeset
for help on using the changeset viewer.