- Timestamp:
- Jun 2, 2010, 9:05:47 AM (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:
- 190326, 76c0d6, a7c344, cb16fe, d466f0
- Parents:
- 5589858
- git-author:
- Tillmann Crueger <crueger@…> (05/28/10 12:44:09)
- git-committer:
- Tillmann Crueger <crueger@…> (06/02/10 09:05:47)
- Location:
- src
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Plane.cpp
r5589858 r27ac00 15 15 #include <cmath> 16 16 #include "Line.hpp" 17 #include "Exceptions/MultipleSolutionsException.hpp" 17 18 18 19 /** … … 147 148 * \return true - \a this contains intersection point on return, false - line is parallel to plane (even if in-plane) 148 149 */ 149 Vector Plane::GetIntersection(const Vector &Origin, const Vector &LineVector) const150 Vector Plane::GetIntersection(const Line& line) const 150 151 { 151 152 Info FunctionInfo(__func__); 152 153 Vector res; 153 154 154 // find intersection of a line defined by Offset and Direction with a plane defined by triangle 155 Vector Direction = LineVector - Origin; 156 Direction.Normalize(); 157 Log() << Verbose(1) << "INFO: Direction is " << Direction << "." << endl; 158 //Log() << Verbose(1) << "INFO: PlaneNormal is " << *PlaneNormal << " and PlaneOffset is " << *PlaneOffset << "." << endl; 159 double factor1 = Direction.ScalarProduct(*normalVector.get()); 160 if (fabs(factor1) < MYEPSILON) { // Uniqueness: line parallel to plane? 161 Log() << Verbose(1) << "BAD: Line is parallel to plane, no intersection." << endl; 162 throw LinearDependenceException(__FILE__,__LINE__); 163 } 164 165 double factor2 = Origin.ScalarProduct(*normalVector.get()); 166 if (fabs(factor2-offset) < MYEPSILON) { // Origin is in-plane 167 Log() << Verbose(1) << "GOOD: Origin of line is in-plane." << endl; 168 res = Origin; 169 return res; 170 } 171 155 double factor1 = getNormal().ScalarProduct(line.getDirection()); 156 if(fabs(factor1)<MYEPSILON){ 157 // the plane is parallel... under all circumstances this is bad luck 158 // we no have either no or infinite solutions 159 if(isContained(line.getOrigin())){ 160 throw MultipleSolutionsException<Vector>(__FILE__,__LINE__,line.getOrigin()); 161 } 162 else{ 163 throw LinearDependenceException(__FILE__,__LINE__); 164 } 165 } 166 167 double factor2 = getNormal().ScalarProduct(line.getOrigin()); 172 168 double scaleFactor = (offset-factor2)/factor1; 173 169 174 //factor = Origin->ScalarProduct(PlaneNormal)*(-PlaneOffset->ScalarProduct(PlaneNormal))/(Direction.ScalarProduct(PlaneNormal)); 175 Direction.Scale(scaleFactor); 176 res = Origin + Direction; 177 Log() << Verbose(1) << "INFO: Scaled direction is " << Direction << "." << endl; 178 179 // test whether resulting vector really is on plane 180 ASSERT(fabs(res.ScalarProduct(*normalVector) - offset) < MYEPSILON, 181 "Calculated line-Plane intersection does not lie on plane."); 170 res = line.getOrigin() + scaleFactor * line.getDirection(); 171 172 // tests to make sure the resulting vector really is on plane and line 173 ASSERT(isContained(res),"Calculated line-Plane intersection does not lie on plane."); 174 ASSERT(line.isContained(res),"Calculated line-Plane intersection does not lie on line."); 182 175 return res; 183 176 }; -
src/Plane.hpp
r5589858 r27ac00 51 51 52 52 // some calculations 53 Vector GetIntersection(const Vector &Origin, const Vector &LineVector) const;53 Vector GetIntersection(const Line &Line) const; 54 54 55 55 Vector mirrorVector(const Vector &rhs) const; -
src/tesselation.cpp
r5589858 r27ac00 442 442 443 443 try { 444 *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*MolCenter, *x); 444 Line centerLine = makeLineThrough(*MolCenter, *x); 445 *Intersection = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(centerLine); 445 446 446 447 DoLog(1) && (Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl); … … 482 483 return false; 483 484 } 484 485 486 485 } 487 486 ; … … 508 507 GetCenter(&Direction); 509 508 try { 510 *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(*x, Direction); 511 } 512 catch (LinearDependenceException &excp) { 509 Line l = makeLineThrough(*x, Direction); 510 *ClosestPoint = Plane(NormalVector, *(endpoints[0]->node->node)).GetIntersection(l); 511 } 512 catch (MathException &excp) { 513 513 (*ClosestPoint) = (*x); 514 514 } … … 533 533 Direction = (*endpoints[(i+1)%3]->node->node) - (*endpoints[i%3]->node->node); 534 534 // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal); 535 CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node)); 535 Line l = makeLineThrough(*(endpoints[i%3]->node->node), *(endpoints[(i+1)%3]->node->node)); 536 CrossPoint[i] = Plane(Direction, InPlane).GetIntersection(l); 536 537 CrossDirection[i] = CrossPoint[i] - InPlane; 537 538 CrossPoint[i] -= (*endpoints[i%3]->node->node); // cross point was returned as absolute vector -
src/unittests/PlaneUnittest.cpp
r5589858 r27ac00 17 17 18 18 #include "vector.hpp" 19 #include "Line.hpp" 19 20 20 21 CPPUNIT_TEST_SUITE_REGISTRATION( PlaneUnittest ); … … 201 202 CPPUNIT_ASSERT_EQUAL(fixture,-1*e1); 202 203 } 204 205 void PlaneUnittest::LineIntersectionTest(){ 206 Vector fixture; 207 // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ??? 208 Line l1 = makeLineThrough(zeroVec,Vector(2,1,0)); 209 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(e1, zeroVec).GetIntersection(l1) ); 210 CPPUNIT_ASSERT_EQUAL( zeroVec, fixture ); 211 212 // plane at (2,1,0) normal to (0,1,0) cuts line from (1,0,0) to (0,1,1) at ??? 213 Line l2 = makeLineThrough(e1,Vector(0,1,1)); 214 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(e2, Vector(2,1,0)).GetIntersection(l2) ); 215 CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture ); 216 } -
src/unittests/PlaneUnittest.hpp
r5589858 r27ac00 21 21 CPPUNIT_TEST ( operationsTest ); 22 22 CPPUNIT_TEST ( mirrorTest ); 23 CPPUNIT_TEST ( LineIntersectionTest ); 23 24 CPPUNIT_TEST_SUITE_END(); 24 25 … … 32 33 void operationsTest(); 33 34 void mirrorTest(); 35 void LineIntersectionTest(); 34 36 35 37 private: -
src/unittests/vectorunittest.cpp
r5589858 r27ac00 216 216 } 217 217 218 /** UnitTest for line intersections.219 */220 void VectorTest::LineIntersectionTest()221 {222 // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ???223 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(unit, zero).GetIntersection(zero, two) );224 CPPUNIT_ASSERT_EQUAL( zero, fixture );225 226 // plane at (2,1,0) normal to (0,1,0) cuts line from (1,0,0) to (0,1,1) at ???227 CPPUNIT_ASSERT_NO_THROW(fixture = Plane(otherunit, two).GetIntersection( unit, notunit) );228 CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture );229 230 };231 218 232 219 /** -
src/unittests/vectorunittest.hpp
r5589858 r27ac00 27 27 CPPUNIT_TEST ( ProjectionTest ); 28 28 CPPUNIT_TEST ( NormalsTest ); 29 CPPUNIT_TEST ( LineIntersectionTest );30 29 CPPUNIT_TEST ( IsInParallelepipedTest ); 31 30 CPPUNIT_TEST_SUITE_END();
Note:
See TracChangeset
for help on using the changeset viewer.