Changeset 42a101


Ignore:
Timestamp:
May 28, 2010, 8:25:27 AM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
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:
ccf826
Parents:
643e76
Message:

Removed RotateVector() function in favor of Line::rotateVector() method.

Line::rotateVector() is able to rotate any vector around any line in space.

Location:
src
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • src/Legacy/oldmenu.cpp

    r643e76 r42a101  
    2626#include "vector_ops.hpp"
    2727#include "Plane.hpp"
     28#include "Line.hpp"
    2829
    2930#include "UIElements/UIFactory.hpp"
     
    184185          // rotate vector around first angle
    185186          first->x = x;
    186           first->x = RotateVector(first->x,z,b - M_PI);
     187          first->x = Line(zeroVec,z).rotateVector(first->x,b - M_PI);
    187188          Log() << Verbose(0) << "Rotated vector: " << first->x << endl,
    188189          // remove the projection onto the rotation plane of the second angle
     
    200201          // rotate another vector around second angle
    201202          n = y;
    202           n = RotateVector(n,x,c - M_PI);
     203          n = Line(zeroVec,x).rotateVector(n,c - M_PI);
    203204          Log() << Verbose(0) << "2nd Rotated vector: " << n << endl;
    204205
  • src/Line.cpp

    r643e76 r42a101  
    175175}
    176176
     177/** Rotates the vector by an angle of \a alpha around this line.
     178 * \param rhs Vector to rotate
     179 * \param alpha rotation angle in radian
     180 */
     181Vector Line::rotateVector(const Vector &rhs, double alpha) const{
     182  Vector helper = rhs;
     183
     184  // translate the coordinate system so that the line goes through (0,0,0)
     185  helper -= *origin;
     186
     187  // partition the vector into a part that gets rotated and a part that lies along the line
     188  pair<Vector,Vector> parts = helper.partition(*direction);
     189
     190  // we just keep anything that is along the axis
     191  Vector res = parts.first;
     192
     193  // the rest has to be rotated
     194  Vector a = parts.second;
     195  // we only have to do the rest, if we actually could partition the vector
     196  if(!a.IsZero()){
     197    // construct a vector that is orthogonal to a and direction and has length |a|
     198    Vector y = a;
     199    // direction is normalized, so the result has length |a|
     200    y.VectorProduct(*direction);
     201
     202    res += cos(alpha) * a + sin(alpha) * y;
     203  }
     204
     205  // translate the coordinate system back
     206  res += *origin;
     207  return res;
     208}
     209
    177210Line makeLineThrough(const Vector &x1, const Vector &x2){
    178211  if(x1==x2){
  • src/Line.hpp

    r643e76 r42a101  
    3333  Vector getIntersection(const Line& otherLine) const;
    3434
     35  Vector rotateVector(const Vector &rhs, double alpha) const;
     36
    3537private:
    3638  std::auto_ptr<Vector> origin;
  • src/Plane.cpp

    r643e76 r42a101  
    4242/**
    4343 * Constructs a plane from two direction vectors and a offset.
    44  * If no offset is given a plane through origin is assumed
    4544 */
    4645Plane::Plane(const Vector &y1, const Vector &y2, double _offset) throw(ZeroVectorException,LinearDependenceException) :
  • src/Space.cpp

    r643e76 r42a101  
    1919}
    2020
     21Vector Space::getVectorToPoint(const Vector &origin) const{
     22  Vector support = getClosestPoint(origin);
     23  return support-origin;
     24}
     25
    2126bool Space::isContained(const Vector &point) const{
    2227  return (distance(point)) < MYEPSILON;
  • src/Space.hpp

    r643e76 r42a101  
    1919  virtual double distance(const Vector &point) const=0;
    2020  virtual Vector getClosestPoint(const Vector &point) const=0;
     21  virtual Vector getVectorToPoint(const Vector &point) const;
    2122  virtual bool isContained(const Vector &point) const;
    2223  virtual bool hasZero() const;
  • src/unittests/LineUnittest.cpp

    r643e76 r42a101  
    221221  CPPUNIT_ASSERT_THROW(la3->getIntersection(*lp1),SkewException);
    222222}
     223
     224void LineUnittest::rotationTest(){
     225  Vector fixture;
     226
     227  // rotate zero Vector along the axes lines by various degrees
     228  fixture = la1->rotateVector(zeroVec,1.);
     229  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
     230  fixture = la2->rotateVector(zeroVec,1.);
     231  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
     232  fixture = la3->rotateVector(zeroVec,1.);
     233  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
     234
     235  fixture = la1->rotateVector(zeroVec,2.);
     236  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
     237  fixture = la2->rotateVector(zeroVec,2.);
     238  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
     239  fixture = la3->rotateVector(zeroVec,2.);
     240  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
     241
     242  // rotate vectors on the axis around their lines
     243  fixture = la1->rotateVector(e1,1.);
     244  CPPUNIT_ASSERT_EQUAL(fixture,e1);
     245  fixture = la2->rotateVector(e2,1.);
     246  CPPUNIT_ASSERT_EQUAL(fixture,e2);
     247  fixture = la3->rotateVector(e3,1.);
     248  CPPUNIT_ASSERT_EQUAL(fixture,e3);
     249
     250  fixture = la1->rotateVector(e1,2.);
     251  CPPUNIT_ASSERT_EQUAL(fixture,e1);
     252  fixture = la2->rotateVector(e2,2.);
     253  CPPUNIT_ASSERT_EQUAL(fixture,e2);
     254  fixture = la3->rotateVector(e3,2.);
     255  CPPUNIT_ASSERT_EQUAL(fixture,e3);
     256
     257  // more vectors on the axis
     258  fixture = la1->rotateVector(2*e1,1.);
     259  CPPUNIT_ASSERT_EQUAL(fixture,2*e1);
     260  fixture = la2->rotateVector(2*e2,1.);
     261  CPPUNIT_ASSERT_EQUAL(fixture,2*e2);
     262  fixture = la3->rotateVector(2*e3,1.);
     263  CPPUNIT_ASSERT_EQUAL(fixture,2*e3);
     264
     265  fixture = la1->rotateVector(2*e1,2.);
     266  CPPUNIT_ASSERT_EQUAL(fixture,2*e1);
     267  fixture = la2->rotateVector(2*e2,2.);
     268  CPPUNIT_ASSERT_EQUAL(fixture,2*e2);
     269  fixture = la3->rotateVector(2*e3,2.);
     270  CPPUNIT_ASSERT_EQUAL(fixture,2*e3);
     271
     272  // negative factors
     273  fixture = la1->rotateVector(-1*e1,1.);
     274  CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
     275  fixture = la2->rotateVector(-1*e2,1.);
     276  CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
     277  fixture = la3->rotateVector(-1*e3,1.);
     278  CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
     279
     280  fixture = la1->rotateVector(-1*e1,2.);
     281  CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
     282  fixture = la2->rotateVector(-1*e2,2.);
     283  CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
     284  fixture = la3->rotateVector(-1*e3,2.);
     285  CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
     286
     287
     288
     289  // now the real rotations
     290  // e2 around e1
     291  fixture = la1->rotateVector(e2,0);
     292  CPPUNIT_ASSERT_EQUAL(fixture,e2);
     293  fixture = la1->rotateVector(e2,1./2.*M_PI);
     294  CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
     295  fixture = la1->rotateVector(e2,M_PI);
     296  CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
     297  fixture = la1->rotateVector(e2,2*M_PI);
     298  CPPUNIT_ASSERT_EQUAL(fixture,e2);
     299
     300  // e3 around e2
     301  fixture = la2->rotateVector(e3,0);
     302  CPPUNIT_ASSERT_EQUAL(fixture,e3);
     303  fixture = la2->rotateVector(e3,1./2.*M_PI);
     304  CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
     305  fixture = la2->rotateVector(e3,M_PI);
     306  CPPUNIT_ASSERT_EQUAL(fixture,-1*e3);
     307  fixture = la2->rotateVector(e3,2*M_PI);
     308  CPPUNIT_ASSERT_EQUAL(fixture,e3);
     309
     310  // e1 around e3
     311  fixture = la3->rotateVector(e1,0);
     312  CPPUNIT_ASSERT_EQUAL(fixture,e1);
     313  fixture = la3->rotateVector(e1,1./2.*M_PI);
     314  CPPUNIT_ASSERT_EQUAL(fixture,-1*e2);
     315  fixture = la3->rotateVector(e1,M_PI);
     316  CPPUNIT_ASSERT_EQUAL(fixture,-1*e1);
     317  fixture = la3->rotateVector(e1,2*M_PI);
     318  CPPUNIT_ASSERT_EQUAL(fixture,e1);
     319
     320
     321  // and some rotation around the plane lines
     322
     323  // Vectors on the line
     324  fixture = lp1->rotateVector(e1,1.);
     325  CPPUNIT_ASSERT_EQUAL(fixture,e1);
     326  fixture = lp1->rotateVector(e2,1.);
     327  CPPUNIT_ASSERT_EQUAL(fixture,e2);
     328
     329  fixture = lp2->rotateVector(e2,1.);
     330  CPPUNIT_ASSERT_EQUAL(fixture,e2);
     331  fixture = lp2->rotateVector(e3,1.);
     332  CPPUNIT_ASSERT_EQUAL(fixture,e3);
     333
     334  fixture = lp3->rotateVector(e3,1.);
     335  CPPUNIT_ASSERT_EQUAL(fixture,e3);
     336  fixture = lp3->rotateVector(e1,1.);
     337  CPPUNIT_ASSERT_EQUAL(fixture,e1);
     338
     339  // the real stuff
     340  fixture = lp1->rotateVector(zeroVec,M_PI);
     341  CPPUNIT_ASSERT_EQUAL(fixture,Vector(1,1,0));
     342  fixture = lp2->rotateVector(zeroVec,M_PI);
     343  CPPUNIT_ASSERT_EQUAL(fixture,Vector(0,1,1));
     344  fixture = lp3->rotateVector(zeroVec,M_PI);
     345  CPPUNIT_ASSERT_EQUAL(fixture,Vector(1,0,1));
     346
     347  fixture = lp1->rotateVector(zeroVec,2*M_PI);
     348  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
     349  fixture = lp2->rotateVector(zeroVec,2*M_PI);
     350  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
     351  fixture = lp3->rotateVector(zeroVec,2*M_PI);
     352  CPPUNIT_ASSERT_EQUAL(fixture,zeroVec);
     353}
  • src/unittests/LineUnittest.hpp

    r643e76 r42a101  
    2121  CPPUNIT_TEST ( isContainedTest );
    2222  CPPUNIT_TEST ( intersectionTest );
     23  CPPUNIT_TEST ( rotationTest );
    2324  CPPUNIT_TEST_SUITE_END();
    2425
     
    3132  void isContainedTest();
    3233  void intersectionTest();
     34  void rotationTest();
    3335
    3436private:
  • src/unittests/vectorunittest.cpp

    r643e76 r42a101  
    230230};
    231231
    232 /** UnitTest for vector rotations.
    233  */
    234 void VectorTest::VectorRotationTest()
    235 {
    236   fixture = Vector(-1.,0.,0.);
    237 
    238   // zero vector does not change
    239   fixture = RotateVector(zero,unit, 1.);
    240   CPPUNIT_ASSERT_EQUAL( zero, fixture );
    241 
    242   fixture = RotateVector(zero, two, 1.);
    243   CPPUNIT_ASSERT_EQUAL( zero,  fixture);
    244 
    245   // vector on axis does not change
    246   fixture = RotateVector(unit,unit, 1.);
    247   CPPUNIT_ASSERT_EQUAL( unit, fixture );
    248 
    249   // rotations
    250   fixture = RotateVector(otherunit, unit, M_PI);
    251   CPPUNIT_ASSERT_EQUAL( Vector(0.,-1.,0.), fixture );
    252 
    253   fixture = RotateVector(otherunit, unit, 2. * M_PI);
    254   CPPUNIT_ASSERT_EQUAL( otherunit, fixture );
    255 
    256   fixture = RotateVector(otherunit,unit, 0);
    257   CPPUNIT_ASSERT_EQUAL( otherunit, fixture );
    258 
    259   fixture = RotateVector(Vector(0.,0.,1.), notunit, M_PI);
    260   CPPUNIT_ASSERT_EQUAL( otherunit, fixture );
    261 }
    262 
    263232/**
    264233 * UnitTest for Vector::IsInParallelepiped().
  • src/unittests/vectorunittest.hpp

    r643e76 r42a101  
    2828    CPPUNIT_TEST ( NormalsTest );
    2929    CPPUNIT_TEST ( LineIntersectionTest );
    30     CPPUNIT_TEST ( VectorRotationTest );
    3130    CPPUNIT_TEST ( IsInParallelepipedTest );
    3231    CPPUNIT_TEST_SUITE_END();
  • src/vector.cpp

    r643e76 r42a101  
    213213{
    214214  Vector tmp;
    215   tmp[0] = x[1]* (y[2]) - x[2]* (y[1]);
    216   tmp[1] = x[2]* (y[0]) - x[0]* (y[2]);
    217   tmp[2] = x[0]* (y[1]) - x[1]* (y[0]);
     215  tmp[0] = x[1]* y[2] - x[2]* y[1];
     216  tmp[1] = x[2]* y[0] - x[0]* y[2];
     217  tmp[2] = x[0]* y[1] - x[1]* y[0];
    218218  (*this) = tmp;
    219219};
     
    232232  *this -= tmp;
    233233};
    234 
    235 /** Calculates the minimum distance vector of this vector to the plane.
    236  * \param *out output stream for debugging
    237  * \param *PlaneNormal normal of plane
    238  * \param *PlaneOffset offset of plane
    239  * \return distance to plane
    240  * \return distance vector onto to plane
    241  */
    242 Vector Vector::GetDistanceVectorToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const
    243 {
    244   Vector temp = (*this) - PlaneOffset;
    245   temp.MakeNormalTo(PlaneNormal);
    246   temp.Scale(-1.);
    247   // then add connecting vector from plane to point
    248   temp += (*this)-PlaneOffset;
    249   double sign = temp.ScalarProduct(PlaneNormal);
    250   if (fabs(sign) > MYEPSILON)
    251     sign /= fabs(sign);
    252   else
    253     sign = 0.;
    254 
    255   temp.Normalize();
    256   temp.Scale(sign);
    257   return temp;
    258 };
    259 
    260234
    261235/** Calculates the minimum distance of this vector to the plane.
  • src/vector.hpp

    r643e76 r42a101  
    4444
    4545  double DistanceSquared(const Vector &y) const;
    46   Vector GetDistanceVectorToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const;
    4746  double DistanceToSpace(const Space& space) const;
    4847  double PeriodicDistance(const Vector &y, const double * const cell_size) const;
  • src/vector_ops.cpp

    r643e76 r42a101  
    111111  return true;
    112112};
    113 
    114 /** Rotates the vector relative to the origin around the axis given by \a *axis by an angle of \a alpha.
    115  * \param *axis rotation axis
    116  * \param alpha rotation angle in radian
    117  */
    118 Vector RotateVector(const Vector &vec,const Vector &axis, const double alpha)
    119 {
    120   Vector a,y;
    121   Vector res;
    122   // normalise this vector with respect to axis
    123   a = vec;
    124   a.ProjectOntoPlane(axis);
    125   // construct normal vector
    126   try {
    127     y = Plane(axis,a,0).getNormal();
    128   }
    129   catch (MathException &excp) {
    130     // The normal vector cannot be created if there is linar dependency.
    131     // Then the vector to rotate is on the axis and any rotation leads to the vector itself.
    132     return vec;
    133   }
    134   y.Scale(vec.Norm());
    135   // scale normal vector by sine and this vector by cosine
    136   y.Scale(sin(alpha));
    137   a.Scale(cos(alpha));
    138   res = vec.Projection(axis);
    139   // add scaled normal vector onto this vector
    140   res += y;
    141   // add part in axis direction
    142   res += a;
    143   return res;
    144 };
  • src/vector_ops.hpp

    r643e76 r42a101  
    1010
    1111bool LSQdistance(Vector &res,const Vector **vectors, int num);
    12 Vector RotateVector(const Vector &vec,const Vector &axis, const double alpha);
    1312
    1413#endif /* VECTOR_OPS_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.