Changeset 78b73c
- Timestamp:
- Aug 20, 2009, 11:35:19 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:
- 89c8b2
- Parents:
- 34e0592
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/vector.cpp
r34e0592 r78b73c 467 467 }; 468 468 469 /** Rotates the vector around the axis given by \a *axis by an angle of \a alpha.469 /** Rotates the vector relative to the origin around the axis given by \a *axis by an angle of \a alpha. 470 470 * \param *axis rotation axis 471 471 * \param alpha rotation angle in radian … … 478 478 a.ProjectOntoPlane(axis); 479 479 // construct normal vector 480 y.MakeNormalVector(axis,this); 480 bool rotatable = y.MakeNormalVector(axis,&a); 481 // The normal vector cannot be created if there is linar dependency. 482 // Then the vector to rotate is on the axis and any rotation leads to the vector itself. 483 if (!rotatable) { 484 return; 485 } 481 486 y.Scale(Norm()); 482 487 // scale normal vector by sine and this vector by cosine 483 488 y.Scale(sin(alpha)); 484 Scale(cos(alpha)); 489 a.Scale(cos(alpha)); 490 CopyVector(Projection(axis)); 485 491 // add scaled normal vector onto this vector 486 492 AddVector(&y); -
src/vectorunittest.cpp
r34e0592 r78b73c 55 55 void VectorTest::SimpleAlgebraTest() 56 56 { 57 Vector helper;58 57 double factor; 58 // copy vector 59 fixture.Init(2.,3.,4.); 60 CPPUNIT_ASSERT_EQUAL( Vector(2.,3.,4.), fixture ); 59 61 // summation and scaling 60 helper.CopyVector(&zero);61 helper.AddVector(&unit);62 CPPUNIT_ASSERT_EQUAL( true, helper.IsOne() );63 helper.CopyVector(&zero);64 helper.SubtractVector(&unit);65 CPPUNIT_ASSERT_EQUAL( true, helper.IsOne() );66 CPPUNIT_ASSERT_EQUAL( false, helper.IsZero() );67 helper.CopyVector(&zero);68 helper.AddVector(&zero);69 CPPUNIT_ASSERT_EQUAL( true, helper.IsZero() );70 helper.CopyVector(¬unit);71 helper.SubtractVector(&otherunit);72 CPPUNIT_ASSERT_EQUAL( true, helper.IsOne() );73 helper.CopyVector(&unit);74 helper.AddVector(&otherunit);75 CPPUNIT_ASSERT_EQUAL( false, helper.IsOne() );76 helper.CopyVector(¬unit);77 helper.SubtractVector(&unit);78 helper.SubtractVector(&otherunit);79 CPPUNIT_ASSERT_EQUAL( false, helper.IsZero() );80 helper.CopyVector(&unit);81 helper.Scale(0.98);82 CPPUNIT_ASSERT_EQUAL( false, helper.IsOne() );83 helper.CopyVector(&unit);84 helper.Scale(1.);85 CPPUNIT_ASSERT_EQUAL( true, helper.IsOne() );86 helper.CopyVector(&unit);62 fixture.CopyVector(&zero); 63 fixture.AddVector(&unit); 64 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 65 fixture.CopyVector(&zero); 66 fixture.SubtractVector(&unit); 67 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 68 CPPUNIT_ASSERT_EQUAL( false, fixture.IsZero() ); 69 fixture.CopyVector(&zero); 70 fixture.AddVector(&zero); 71 CPPUNIT_ASSERT_EQUAL( true, fixture.IsZero() ); 72 fixture.CopyVector(¬unit); 73 fixture.SubtractVector(&otherunit); 74 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 75 fixture.CopyVector(&unit); 76 fixture.AddVector(&otherunit); 77 CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() ); 78 fixture.CopyVector(¬unit); 79 fixture.SubtractVector(&unit); 80 fixture.SubtractVector(&otherunit); 81 CPPUNIT_ASSERT_EQUAL( false, fixture.IsZero() ); 82 fixture.CopyVector(&unit); 83 fixture.Scale(0.98); 84 CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() ); 85 fixture.CopyVector(&unit); 86 fixture.Scale(1.); 87 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 88 fixture.CopyVector(&unit); 87 89 factor = 0.98; 88 helper.Scale(factor);89 CPPUNIT_ASSERT_EQUAL( false, helper.IsOne() );90 helper.CopyVector(&unit);90 fixture.Scale(factor); 91 CPPUNIT_ASSERT_EQUAL( false, fixture.IsOne() ); 92 fixture.CopyVector(&unit); 91 93 factor = 1.; 92 helper.Scale(factor);93 CPPUNIT_ASSERT_EQUAL( true, helper.IsOne() );94 fixture.Scale(factor); 95 CPPUNIT_ASSERT_EQUAL( true, fixture.IsOne() ); 94 96 }; 95 97 … … 183 185 void VectorTest::LineIntersectionTest() 184 186 { 185 Vector helper;186 187 // plane at (0,0,0) normal to (1,0,0) cuts line from (0,0,0) to (2,1,0) at ??? 187 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionWithPlane((ofstream *)&cout, &unit, &zero, &zero, &two) );188 CPPUNIT_ASSERT_EQUAL( zero, helper);188 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionWithPlane((ofstream *)&cout, &unit, &zero, &zero, &two) ); 189 CPPUNIT_ASSERT_EQUAL( zero, fixture ); 189 190 190 191 // plane at (2,1,0) normal to (0,1,0) cuts line from (1,0,0) to (0,1,1) at ??? 191 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionWithPlane((ofstream *)&cout, &otherunit, &two, &unit, ¬unit) );192 CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), helper);192 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionWithPlane((ofstream *)&cout, &otherunit, &two, &unit, ¬unit) ); 193 CPPUNIT_ASSERT_EQUAL( Vector(0., 1., 1.), fixture ); 193 194 194 195 // four vectors equal to zero 195 CPPUNIT_ASSERT_EQUAL( false, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &zero, &zero, &zero, &zero, NULL) );196 CPPUNIT_ASSERT_EQUAL( zero, helper);196 CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &zero, &zero, &zero, &zero, NULL) ); 197 CPPUNIT_ASSERT_EQUAL( zero, fixture ); 197 198 198 199 // four vectors equal to unit 199 CPPUNIT_ASSERT_EQUAL( false, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &unit, &unit, &unit, NULL) );200 CPPUNIT_ASSERT_EQUAL( zero, helper);200 CPPUNIT_ASSERT_EQUAL( false, fixture.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &unit, &unit, &unit, NULL) ); 201 CPPUNIT_ASSERT_EQUAL( zero, fixture ); 201 202 202 203 // two equal lines 203 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &unit, &two, NULL) );204 CPPUNIT_ASSERT_EQUAL( unit, helper);204 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &unit, &two, NULL) ); 205 CPPUNIT_ASSERT_EQUAL( unit, fixture ); 205 206 206 207 // line from (1,0,0) to (2,1,0) cuts line from (1,0,0) to (0,1,0) at ??? 207 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &unit, &otherunit, NULL) );208 CPPUNIT_ASSERT_EQUAL( unit, helper);208 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &unit, &otherunit, NULL) ); 209 CPPUNIT_ASSERT_EQUAL( unit, fixture ); 209 210 210 211 // line from (1,0,0) to (0,0,0) cuts line from (0,0,0) to (2,1,0) at ??? 211 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &zero, &zero, &two, NULL) );212 CPPUNIT_ASSERT_EQUAL( zero, helper);212 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &zero, &zero, &two, NULL) ); 213 CPPUNIT_ASSERT_EQUAL( zero, fixture ); 213 214 214 215 // line from (1,0,0) to (2,1,0) cuts line from (0,0,0) to (0,1,0) at ??? 215 CPPUNIT_ASSERT_EQUAL( true, helper.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &zero, &otherunit, NULL) ); 216 CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), helper ); 217 }; 216 CPPUNIT_ASSERT_EQUAL( true, fixture.GetIntersectionOfTwoLinesOnPlane((ofstream *)&cout, &unit, &two, &zero, &otherunit, NULL) ); 217 CPPUNIT_ASSERT_EQUAL( Vector(0., -1., 0.), fixture ); 218 }; 219 220 /** UnitTest for vector rotations. 221 */ 222 void VectorTest::VectorRotationTest() 223 { 224 fixture.Init(-1.,0.,0.); 225 226 // zero vector does not change 227 fixture.CopyVector(&zero); 228 fixture.RotateVector(&unit, 1.); 229 CPPUNIT_ASSERT_EQUAL( zero, fixture ); 230 231 fixture.RotateVector(&two, 1.); 232 CPPUNIT_ASSERT_EQUAL( zero, fixture); 233 234 // vector on axis does not change 235 fixture.CopyVector(&unit); 236 fixture.RotateVector(&unit, 1.); 237 CPPUNIT_ASSERT_EQUAL( unit, fixture ); 238 239 fixture.RotateVector(&unit, 1.); 240 CPPUNIT_ASSERT_EQUAL( unit, fixture ); 241 242 // rotations 243 fixture.CopyVector(&otherunit); 244 fixture.RotateVector(&unit, M_PI); 245 CPPUNIT_ASSERT_EQUAL( Vector(0.,-1.,0.), fixture ); 246 247 fixture.CopyVector(&otherunit); 248 fixture.RotateVector(&unit, 2. * M_PI); 249 CPPUNIT_ASSERT_EQUAL( otherunit, fixture ); 250 251 fixture.CopyVector(&otherunit); 252 fixture.RotateVector(&unit, 0); 253 CPPUNIT_ASSERT_EQUAL( otherunit, fixture ); 254 255 fixture.Init(0.,0.,1.); 256 fixture.RotateVector(¬unit, M_PI); 257 CPPUNIT_ASSERT_EQUAL( otherunit, fixture ); 258 } 259 218 260 219 261 /********************************************** Main routine **************************************/ -
src/vectorunittest.hpp
r34e0592 r78b73c 27 27 CPPUNIT_TEST ( ProjectionTest ); 28 28 CPPUNIT_TEST ( LineIntersectionTest ); 29 CPPUNIT_TEST ( VectorRotationTest ); 29 30 CPPUNIT_TEST_SUITE_END(); 30 31 31 32 public: 32 33 33 void setUp(); 34 void tearDown(); 34 35 35 void UnityTest(); 36 void OperatorAlgebraTest(); 37 void SimpleAlgebraTest(); 38 void EuclidianScalarProductTest(); 39 void EuclidianNormTest(); 40 void EuclidianDistancesTest(); 41 void EuclidianAnglesTest(); 42 void ProjectionTest(); 43 void LineIntersectionTest(); 36 void UnityTest(); 37 void OperatorAlgebraTest(); 38 void SimpleAlgebraTest(); 39 void EuclidianScalarProductTest(); 40 void EuclidianNormTest(); 41 void EuclidianDistancesTest(); 42 void EuclidianAnglesTest(); 43 void ProjectionTest(); 44 void LineIntersectionTest(); 45 void VectorRotationTest(); 44 46 45 47 private: 46 Vector zero; 47 Vector unit; 48 Vector otherunit; 49 Vector notunit; 50 Vector two; 48 // vector to execute tests on, may be modified during run 49 Vector fixture; 50 // never modify these during run, other tests might rely on them 51 Vector zero; 52 Vector unit; 53 Vector otherunit; 54 Vector notunit; 55 Vector two; 51 56 }; 52 57
Note:
See TracChangeset
for help on using the changeset viewer.