Changeset 50c35d
- Timestamp:
- Apr 6, 2012, 11:44:09 AM (13 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:
- 93eae36
- Parents:
- 2db053
- git-author:
- Frederik Heber <heber@…> (04/03/12 13:32:46)
- git-committer:
- Frederik Heber <heber@…> (04/06/12 11:44:09)
- Location:
- LinearAlgebra/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
LinearAlgebra/src/LinearAlgebra/Line.cpp
r2db053 r50c35d 34 34 #include "MatrixContent.hpp" 35 35 #include "Plane.hpp" 36 #include "RealSpaceMatrix.hpp" 36 37 #include "Vector.hpp" 37 38 … … 261 262 } 262 263 264 RealSpaceMatrix Line::getRotationMatrix(double alpha) const 265 { 266 RealSpaceMatrix M; 267 M.setRotation(getDirection(), alpha); 268 269 return M; 270 } 271 263 272 Plane Line::getOrthogonalPlane(const Vector &origin) const{ 264 273 return Plane(getDirection(),origin); -
LinearAlgebra/src/LinearAlgebra/Line.hpp
r2db053 r50c35d 24 24 class Plane; 25 25 class LinePoint; 26 class RealSpaceMatrix; 26 27 27 28 /** This class represents a line in space stretching to infinity. … … 55 56 Line rotateLine(const Line &rhs, double alpha) const; 56 57 Plane rotatePlane(const Plane &rhs, double alpha) const; 58 RealSpaceMatrix getRotationMatrix(double alpha) const; 57 59 58 60 Plane getOrthogonalPlane(const Vector &origin) const; -
LinearAlgebra/src/LinearAlgebra/RealSpaceMatrix.cpp
r2db053 r50c35d 142 142 } 143 143 144 void RealSpaceMatrix::setRotation(const Vector &axis, const double alpha) 145 { 146 ASSERT( fabs(axis.Norm() - 1.) < LINALG_MYEPSILON(), 147 "RealSpaceMatrix::setRotation() - axis is not normalized."); 148 149 // this is taken from http://inside.mines.edu/~gmurray/ArbitraryAxisRotation/, section 5. 150 const double u = axis[0]; 151 const double v = axis[1]; 152 const double w = axis[2]; 153 const double u_squared = u*u; 154 const double v_squared = v*v; 155 const double w_squared = w*w; 156 const double cos_alpha = cos(alpha); 157 const double cos_alpha_inv = 1.-cos(alpha); 158 const double sin_alpha = sin(alpha); 159 set(0,0, u_squared + (v_squared + w_squared)*cos_alpha ); 160 set(1,1, v_squared + (u_squared + w_squared)*cos_alpha ); 161 set(2,2, w_squared + (u_squared + v_squared)*cos_alpha ); 162 set(0,1, u*v*cos_alpha_inv - w*sin_alpha ); 163 set(0,2, u*w*cos_alpha_inv + v*sin_alpha ); 164 set(1,0, u*v*cos_alpha_inv + w*sin_alpha ); 165 set(1,2, v*w*cos_alpha_inv - u*sin_alpha ); 166 set(2,0, u*w*cos_alpha_inv - v*sin_alpha ); 167 set(2,1, v*w*cos_alpha_inv + u*sin_alpha ); 168 } 169 144 170 RealSpaceMatrix &RealSpaceMatrix::operator=(const RealSpaceMatrix &src) 145 171 { -
LinearAlgebra/src/LinearAlgebra/RealSpaceMatrix.hpp
r2db053 r50c35d 84 84 */ 85 85 void setRotation(const double phi[NDIM]); 86 87 /** 88 * Sets all matrix corresponding to a rotation matrix, 89 * around the given \a axis by angle \a phi. 90 * 91 * @param axis \b normalized rotation axis 92 * @param alpha rotation angle 93 */ 94 void setRotation(const Vector &axis, const double alpha); 95 86 96 /** 87 97 * Access the matrix at index (i,j) -
LinearAlgebra/src/unittests/LineUnitTest.cpp
r2db053 r50c35d 30 30 31 31 #include "LineUnitTest.hpp" 32 33 #include "RealSpaceMatrix.hpp" 32 34 33 35 #ifdef HAVE_TESTRUNNER … … 297 299 298 300 299 300 301 // now the real rotations 301 302 // unitVec[1] around unitVec[0] … … 364 365 } 365 366 367 void LineUnittest::getRotationMatrixTest() 368 { 369 RealSpaceMatrix M; 370 Vector fixture; 371 372 // check getRotationMatrix; 373 M = la1->getRotationMatrix(1.); 374 fixture = M * unitVec[0]; 375 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]); 376 M = la2->getRotationMatrix(1.); 377 fixture = M * unitVec[1]; 378 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]); 379 M = la3->getRotationMatrix(1.); 380 fixture = M * unitVec[2]; 381 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]); 382 383 // unitVec[1] around unitVec[0] 384 fixture = la1->rotateVector(unitVec[1],0); 385 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]); 386 fixture = la1->rotateVector(unitVec[1],1./2.*M_PI); 387 CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]); 388 fixture = la1->rotateVector(unitVec[1],M_PI); 389 CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]); 390 fixture = la1->rotateVector(unitVec[1],2*M_PI); 391 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[1]); 392 393 // unitVec[2] around unitVec[1] 394 fixture = la2->rotateVector(unitVec[2],0); 395 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]); 396 fixture = la2->rotateVector(unitVec[2],1./2.*M_PI); 397 CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]); 398 fixture = la2->rotateVector(unitVec[2],M_PI); 399 CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[2]); 400 fixture = la2->rotateVector(unitVec[2],2*M_PI); 401 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[2]); 402 403 // unitVec[0] around unitVec[2] 404 fixture = la3->rotateVector(unitVec[0],0); 405 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]); 406 fixture = la3->rotateVector(unitVec[0],1./2.*M_PI); 407 CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[1]); 408 fixture = la3->rotateVector(unitVec[0],M_PI); 409 CPPUNIT_ASSERT_EQUAL(fixture,-1*unitVec[0]); 410 fixture = la3->rotateVector(unitVec[0],2*M_PI); 411 CPPUNIT_ASSERT_EQUAL(fixture,unitVec[0]); 412 } 413 366 414 void LineUnittest::sphereIntersectionTest(){ 367 415 { -
LinearAlgebra/src/unittests/LineUnitTest.hpp
r2db053 r50c35d 23 23 24 24 CPPUNIT_TEST_SUITE( LineUnittest) ; 25 CPPUNIT_TEST ( constructionErrorTest ); 26 CPPUNIT_TEST ( constructionResultTest ); 27 CPPUNIT_TEST ( isContainedTest ); 28 CPPUNIT_TEST ( intersectionTest ); 29 CPPUNIT_TEST ( rotationTest ); 30 CPPUNIT_TEST ( sphereIntersectionTest ); 25 // CPPUNIT_TEST ( constructionErrorTest ); 26 // CPPUNIT_TEST ( constructionResultTest ); 27 // CPPUNIT_TEST ( isContainedTest ); 28 // CPPUNIT_TEST ( intersectionTest ); 29 // CPPUNIT_TEST ( rotationTest ); 30 CPPUNIT_TEST ( getRotationMatrixTest ); 31 // CPPUNIT_TEST ( sphereIntersectionTest ); 31 32 CPPUNIT_TEST_SUITE_END(); 32 33 … … 40 41 void intersectionTest(); 41 42 void rotationTest(); 43 void getRotationMatrixTest(); 42 44 void sphereIntersectionTest(); 43 45 -
LinearAlgebra/src/unittests/RealSpaceMatrixUnitTest.cpp
r2db053 r50c35d 31 31 #include <boost/archive/text_iarchive.hpp> 32 32 33 #include "CodePatterns/Assert.hpp" 34 33 35 #include "defs.hpp" 34 36 #include "Exceptions.hpp" … … 45 47 46 48 void RealSpaceMatrixTest::setUp(){ 49 // failing asserts should be thrown 50 ASSERT_DO(Assert::Throw); 51 47 52 zero = new RealSpaceMatrix(); 48 53 for(int i =NDIM;i--;) { … … 270 275 RealSpaceMatrix res; 271 276 RealSpaceMatrix inverse; 277 Vector fixture; 272 278 273 279 // zero rotation angles yields unity matrix … … 287 293 res.setRotation(M_PI/3.,0.,0.); 288 294 CPPUNIT_ASSERT_EQUAL(inverse, res.transposed()); 295 296 // check arbitrary axis 297 res.setRotation(unitVec[0], M_PI/3.); 298 inverse.setRotation(M_PI/3.,0.,0.); 299 CPPUNIT_ASSERT_EQUAL( res, inverse); 300 res.setRotation(unitVec[1], M_PI/3.); 301 inverse.setRotation(0., M_PI/3.,0.); 302 CPPUNIT_ASSERT_EQUAL( res, inverse); 303 res.setRotation(unitVec[2], M_PI/3.); 304 inverse.setRotation(0.,0.,M_PI/3.); 305 CPPUNIT_ASSERT_EQUAL( res, inverse); 306 307 // check axis not normalized throws 308 #ifndef NDEBUG 309 CPPUNIT_ASSERT_THROW( res.setRotation(unitVec[0]+unitVec[1], M_PI/3.),Assert::AssertionFailure); 310 #endif 311 312 // check arbitrary axis and det=1 313 fixture = (unitVec[0]+unitVec[1]).getNormalized(); 314 res.setRotation(fixture, M_PI/3.); 315 CPPUNIT_ASSERT(fabs(res.determinant() - 1.) <= LINALG_MYEPSILON()); 316 fixture = (unitVec[1]+unitVec[2]).getNormalized(); 317 res.setRotation(fixture, M_PI/3.); 318 CPPUNIT_ASSERT(fabs(res.determinant() - 1.) <= LINALG_MYEPSILON()); 319 fixture = (unitVec[1]+unitVec[2]).getNormalized(); 320 res.setRotation(fixture, M_PI/3.); 321 CPPUNIT_ASSERT(fabs(res.determinant() - 1.) <= LINALG_MYEPSILON()); 289 322 } 290 323
Note:
See TracChangeset
for help on using the changeset viewer.