MBSim

Project Page
contact_utils.h
1 /* Copyright (C) 2004-2009 MBSim Development Team
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16  *
17  * Contact: martin.o.foerg@googlemail.com
18  * rzander@users.berlios.de
19  */
20 
21 #ifndef _CONTACT_UTILS_H_
22 #define _CONTACT_UTILS_H_
23 
24 #include "mbsim/contact.h"
25 #include "mbsim/contour.h"
26 #include "mbsim/contours/contour_interpolation.h"
27 #include "mbsim/dynamic_system_solver.h"
28 
29 #include <vector>
30 
31 namespace MBSim {
32 
38  double computeAngleOnUnitCircle(const fmatvec::Vec& r);
39 
45  fmatvec::Vec computeAnglesOnUnitSphere(const fmatvec::Vec& r);
46 
53  ContactKinematics* findContactPairingRigidRigid(const char* contour0, const char* contour1);
54 
60  template <class T>
62  ContactContourInterpolation(ds,contact,contour0,contour1,0);
63  }
64 
70  template <class T>
71  void ContactContourInterpolation(DynamicSystemSolver *ds, const T *contact, ContourInterpolation *contour0, ContourInterpolation *contour1, int master) {
72  ContourInterpolation *contour[2];
73  contour[0] = contour0;
74  contour[1] = contour1;
75  std::string contactName = contact->getName();
76 
77  int cStart, cEnd;
78  switch(master) {
79  case 0: cStart = 0; cEnd = 1; break;
80  case 1: cStart = 1; cEnd = 1; break;
81  case 2: cStart = 0; cEnd = 0; break;
82  }
83 
84  for(int c = cStart;c<cEnd+1;c++) { // loop with respect to contours
85  int numberOfPoints = contour[c]->getNPoints();
86  char contourName;
87  switch(c) {
88  case 0: contourName = 'A';break;
89  case 1: contourName = 'B';break;
90  }
91  for(int i = 0;i<numberOfPoints; i++) { // use all points
92  std::stringstream number;
93  std::string name = contactName + number.str();
94 
95  T *newContact = new T( contact , name );
96 
97  newContact->connect(contour[c]->getPoint(i),contour[1-c]);
98  ds->addLink(newContact);
99  }
100  }
101  }
102 
103 }
104 
105 #endif /* _CONTACT_UTILS_H_ */
106