- Timestamp:
- May 27, 2010, 2:15:57 PM (15 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 643e76
- Parents:
- 47191b
- Location:
- src
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Line.cpp
r47191b r45ef76 11 11 12 12 #include "vector.hpp" 13 #include "log.hpp" 14 #include "verbose.hpp" 15 #include "gslmatrix.hpp" 16 #include "info.hpp" 17 #include "Exceptions/LinearDependenceException.hpp" 18 #include "Exceptions/SkewException.hpp" 13 19 14 Line::Line(Vector &_origin, Vector &_direction) : 15 origin(new Vector(_origin)), 20 using namespace std; 21 22 Line::Line(const Vector &_origin, const Vector &_direction) : 16 23 direction(new Vector(_direction)) 17 24 { 18 25 direction->Normalize(); 26 origin.reset(new Vector(_origin.partition(*direction).second)); 19 27 } 28 29 Line::Line(const Line &src) : 30 origin(new Vector(*src.origin)), 31 direction(new Vector(*src.direction)) 32 {} 20 33 21 34 Line::~Line() … … 24 37 25 38 double Line::distance(const Vector &point) const{ 26 return fabs(point.ScalarProduct(*direction) - origin->ScalarProduct(*direction)); 39 // get any vector from line to point 40 Vector helper = point - *origin; 41 // partition this vector along direction 42 // the residue points from the line to the point 43 return helper.partition(*direction).second.Norm(); 27 44 } 28 45 29 46 Vector Line::getClosestPoint(const Vector &point) const{ 30 double factor = point.ScalarProduct(*direction) - origin->ScalarProduct(*direction); 31 return (point - (factor * (*direction))); 47 // get any vector from line to point 48 Vector helper = point - *origin; 49 // partition this vector along direction 50 // add only the part along the direction 51 return *origin + helper.partition(*direction).first; 32 52 } 53 54 Vector Line::getDirection() const{ 55 return *direction; 56 } 57 58 Vector Line::getOrigin() const{ 59 return *origin; 60 } 61 62 vector<Vector> Line::getPointsOnLine() const{ 63 vector<Vector> res; 64 res.reserve(2); 65 res.push_back(*origin); 66 res.push_back(*origin+*direction); 67 return res; 68 } 69 70 Vector Line::getIntersection(const Line& otherLine) const{ 71 Info FunctionInfo(__func__); 72 73 pointset line1Points = getPointsOnLine(); 74 75 Vector Line1a = line1Points[0]; 76 Vector Line1b = line1Points[1]; 77 78 pointset line2Points = otherLine.getPointsOnLine(); 79 80 Vector Line2a = line2Points[0]; 81 Vector Line2b = line2Points[1]; 82 83 Vector res; 84 85 auto_ptr<GSLMatrix> M = auto_ptr<GSLMatrix>(new GSLMatrix(4,4)); 86 87 M->SetAll(1.); 88 for (int i=0;i<3;i++) { 89 M->Set(0, i, Line1a[i]); 90 M->Set(1, i, Line1b[i]); 91 M->Set(2, i, Line2a[i]); 92 M->Set(3, i, Line2b[i]); 93 } 94 95 //Log() << Verbose(1) << "Coefficent matrix is:" << endl; 96 //for (int i=0;i<4;i++) { 97 // for (int j=0;j<4;j++) 98 // cout << "\t" << M->Get(i,j); 99 // cout << endl; 100 //} 101 if (fabs(M->Determinant()) > MYEPSILON) { 102 Log() << Verbose(1) << "Determinant of coefficient matrix is NOT zero." << endl; 103 throw SkewException(__FILE__,__LINE__); 104 } 105 106 Log() << Verbose(1) << "INFO: Line1a = " << Line1a << ", Line1b = " << Line1b << ", Line2a = " << Line2a << ", Line2b = " << Line2b << "." << endl; 107 108 109 // constuct a,b,c 110 Vector a = Line1b - Line1a; 111 Vector b = Line2b - Line2a; 112 Vector c = Line2a - Line1a; 113 Vector d = Line2b - Line1b; 114 Log() << Verbose(1) << "INFO: a = " << a << ", b = " << b << ", c = " << c << "." << endl; 115 if ((a.NormSquared() < MYEPSILON) || (b.NormSquared() < MYEPSILON)) { 116 res.Zero(); 117 Log() << Verbose(1) << "At least one of the lines is ill-defined, i.e. offset equals second vector." << endl; 118 throw LinearDependenceException(__FILE__,__LINE__); 119 } 120 121 // check for parallelity 122 Vector parallel; 123 double factor = 0.; 124 if (fabs(a.ScalarProduct(b)*a.ScalarProduct(b)/a.NormSquared()/b.NormSquared() - 1.) < MYEPSILON) { 125 parallel = Line1a - Line2a; 126 factor = parallel.ScalarProduct(a)/a.Norm(); 127 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) { 128 res = Line2a; 129 Log() << Verbose(1) << "Lines conincide." << endl; 130 return res; 131 } else { 132 parallel = Line1a - Line2b; 133 factor = parallel.ScalarProduct(a)/a.Norm(); 134 if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) { 135 res = Line2b; 136 Log() << Verbose(1) << "Lines conincide." << endl; 137 return res; 138 } 139 } 140 Log() << Verbose(1) << "Lines are parallel." << endl; 141 res.Zero(); 142 throw LinearDependenceException(__FILE__,__LINE__); 143 } 144 145 // obtain s 146 double s; 147 Vector temp1, temp2; 148 temp1 = c; 149 temp1.VectorProduct(b); 150 temp2 = a; 151 temp2.VectorProduct(b); 152 Log() << Verbose(1) << "INFO: temp1 = " << temp1 << ", temp2 = " << temp2 << "." << endl; 153 if (fabs(temp2.NormSquared()) > MYEPSILON) 154 s = temp1.ScalarProduct(temp2)/temp2.NormSquared(); 155 else 156 s = 0.; 157 Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct(temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl; 158 159 // construct intersection 160 res = a; 161 res.Scale(s); 162 res += Line1a; 163 Log() << Verbose(1) << "Intersection is at " << res << "." << endl; 164 165 return res; 166 } 167 168 Line makeLineThrough(const Vector &x1, const Vector &x2){ 169 if(x1==x2){ 170 throw LinearDependenceException(__FILE__,__LINE__); 171 } 172 return Line(x1,x1-x2); 173 } -
src/Line.hpp
r47191b r45ef76 12 12 13 13 #include <memory> 14 #include <vector> 14 15 15 16 class Vector; … … 18 19 { 19 20 public: 20 Line(Vector &_origin, Vector &_direction); 21 Line(const Vector &_origin, const Vector &_direction); 22 Line(const Line& _src); 21 23 virtual ~Line(); 22 24 23 virtual double distance(const Vector &point) const=0; 24 virtual Vector getClosestPoint(const Vector &point) const=0; 25 virtual double distance(const Vector &point) const; 26 virtual Vector getClosestPoint(const Vector &point) const; 27 28 Vector getDirection() const; 29 Vector getOrigin() const; 30 31 std::vector<Vector> getPointsOnLine() const; 32 33 Vector getIntersection(const Line& otherLine) const; 25 34 26 35 private: … … 29 38 }; 30 39 40 /** 41 * Named constructor to make a line through two points 42 */ 43 Line makeLineThrough(const Vector &x1, const Vector &x2); 44 31 45 #endif /* LINE_HPP_ */ -
src/Plane.cpp
r47191b r45ef76 113 113 } 114 114 115 Vector Plane::getOffsetVector() {115 Vector Plane::getOffsetVector() const { 116 116 return getOffset()*getNormal(); 117 117 } 118 118 119 vector<Vector> Plane::getPointsOnPlane() {119 vector<Vector> Plane::getPointsOnPlane() const{ 120 120 std::vector<Vector> res; 121 121 res.reserve(3); … … 147 147 * \return true - \a this contains intersection point on return, false - line is parallel to plane (even if in-plane) 148 148 */ 149 Vector Plane::GetIntersection(const Vector &Origin, const Vector &LineVector) 149 Vector Plane::GetIntersection(const Vector &Origin, const Vector &LineVector) const 150 150 { 151 151 Info FunctionInfo(__func__); -
src/Plane.hpp
r47191b r45ef76 42 42 * Same as getOffset()*getNormal(); 43 43 */ 44 Vector getOffsetVector() ;44 Vector getOffsetVector() const; 45 45 46 46 /** 47 47 * returns three seperate points on this plane 48 48 */ 49 std::vector<Vector> getPointsOnPlane() ;49 std::vector<Vector> getPointsOnPlane() const; 50 50 51 51 // some calculations 52 Vector GetIntersection(const Vector &Origin, const Vector &LineVector) ;52 Vector GetIntersection(const Vector &Origin, const Vector &LineVector) const; 53 53 54 54 /****** Methods inherited from Space ***********/ -
src/unittests/Makefile.am
r47191b r45ef76 23 23 InfoUnitTest \ 24 24 LinearSystemOfEquationsUnitTest \ 25 LineUnittest \ 25 26 LinkedCellUnitTest \ 26 27 ListOfBondsUnitTest \ … … 64 65 infounittest.cpp \ 65 66 linearsystemofequationsunittest.cpp \ 67 LineUnittest.cpp \ 66 68 LinkedCellUnitTest.cpp \ 67 69 listofbondsunittest.cpp \ … … 97 99 infounittest.hpp \ 98 100 linearsystemofequationsunittest.hpp \ 101 LineUnittest.hpp \ 99 102 LinkedCellUnitTest.hpp \ 100 103 listofbondsunittest.hpp \ … … 153 156 LinearSystemOfEquationsUnitTest_LDADD = ${ALLLIBS} 154 157 158 LineUnittest_SOURCES = UnitTestMain.cpp LineUnittest.cpp LineUnittest.hpp 159 LineUnittest_LDADD = ${ALLLIBS} 160 155 161 LinkedCellUnitTest_SOURCES = UnitTestMain.cpp LinkedCellUnitTest.cpp LinkedCellUnitTest.hpp 156 162 LinkedCellUnitTest_LDADD = ${ALLLIBS} -
src/unittests/vectorunittest.cpp
r47191b r45ef76 228 228 CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture ); 229 229 230 // four vectors equal to zero231 CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(zero, zero, zero, zero), LinearDependenceException);232 //CPPUNIT_ASSERT_EQUAL( zero, fixture );233 234 // four vectors equal to unit235 CPPUNIT_ASSERT_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, unit, unit, unit), LinearDependenceException);236 //CPPUNIT_ASSERT_EQUAL( zero, fixture );237 238 // two equal lines239 CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, two));240 CPPUNIT_ASSERT_EQUAL( unit, fixture );241 242 // line from (1,0,0) to (2,1,0) cuts line from (1,0,0) to (0,1,0) at ???243 CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, unit, otherunit) );244 CPPUNIT_ASSERT_EQUAL( unit, fixture );245 246 // line from (1,0,0) to (0,0,0) cuts line from (0,0,0) to (2,1,0) at ???247 CPPUNIT_ASSERT_NO_THROW( fixture = GetIntersectionOfTwoLinesOnPlane(unit, zero, zero, two) );248 CPPUNIT_ASSERT_EQUAL( zero, fixture );249 250 // line from (1,0,0) to (2,1,0) cuts line from (0,0,0) to (0,1,0) at ???251 CPPUNIT_ASSERT_NO_THROW(fixture = GetIntersectionOfTwoLinesOnPlane(unit, two, zero, otherunit) );252 CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), fixture );253 230 }; 254 231 -
src/vector.cpp
r47191b r45ef76 552 552 }; 553 553 554 std::pair<Vector,Vector> Vector::partition(const Vector &rhs) const{ 555 double factor = ScalarProduct(rhs)/rhs.NormSquared(); 556 Vector res= factor * rhs; 557 return make_pair(res,(*this)-res); 558 } 559 560 std::pair<pointset,Vector> Vector::partition(const pointset &points) const{ 561 Vector helper = *this; 562 pointset res; 563 for(pointset::const_iterator iter=points.begin();iter!=points.end();++iter){ 564 pair<Vector,Vector> currPart = helper.partition(*iter); 565 res.push_back(currPart.first); 566 helper = currPart.second; 567 } 568 return make_pair(res,helper); 569 } 570 554 571 /** Do a matrix multiplication. 555 572 * \param *matrix NDIM_NDIM array … … 633 650 bool result = false; 634 651 double factor = y1.ScalarProduct(*this)/y1.NormSquared(); 635 Vector x1; 636 x1 = factor * y1; 652 Vector x1 = factor * y1; 637 653 SubtractVector(x1); 638 654 for (int i=NDIM;i--;) -
src/vector.hpp
r47191b r45ef76 16 16 17 17 #include <memory> 18 #include <vector> 18 19 19 20 #include "defs.hpp" … … 21 22 22 23 /********************************************** declarations *******************************/ 24 25 class Vector; 26 27 typedef std::vector<Vector> pointset; 23 28 24 29 /** Single vector. … … 66 71 bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const; 67 72 void WrapPeriodically(const double * const M, const double * const Minv); 73 std::pair<Vector,Vector> partition(const Vector&) const; 74 std::pair<pointset,Vector> partition(const pointset&) const; 68 75 69 76 // Accessors ussually come in pairs... and sometimes even more than that
Note:
See TracChangeset
for help on using the changeset viewer.