mbsim  4.0.0
MBSim Kernel
rotation_about_axes_zyx.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@gmail.com
18  */
19 
20 #ifndef _ROTATION_ABOUT_AXES_ZYX_H_
21 #define _ROTATION_ABOUT_AXES_ZYX_H_
22 
23 #include "mbsim/functions/kinematics/rotation_about_three_axes.h"
24 #include "mbsim/functions/kinematics/rotation_about_axes_zyx_mapping.h"
25 #include "mbsim/functions/kinematics/rotation_about_axes_zyx_transformed_mapping.h"
26 
27 namespace MBSim {
28 
29  template<class Arg>
31  using B = fmatvec::Function<fmatvec::RotMat3(Arg)>;
35  public:
36  RotationAboutAxesZYX() { J.e(2,0) = 1; }
37  fmatvec::RotMat3 operator()(const Arg &q) override {
38  double a=q.e(0);
39  double b=q.e(1);
40  double g=q.e(2);
41  double cosa = cos(a);
42  double sina = sin(a);
43  double cosb = cos(b);
44  double sinb = sin(b);
45  double cosg = cos(g);
46  double sing = sin(g);
47  A.e(0,0) = cosa*cosb;
48  A.e(1,0) = sina*cosb;
49  A.e(2,0) = -sinb;
50  A.e(0,1) = -sina*cosg+cosa*sinb*sing;
51  A.e(1,1) = cosa*cosg+sina*sinb*sing;
52  A.e(2,1) = cosb*sing;
53  A.e(0,2) = sina*sing+cosa*sinb*cosg;
54  A.e(1,2) = -cosa*sing+sina*sinb*cosg;
55  A.e(2,2) = cosb*cosg;
56  return A;
57  }
58  typename B::DRetDArg parDer(const Arg &q) override {
59  double a = q.e(0);
60  double b = q.e(1);
61  double cosa = cos(a);
62  double sina = sin(a);
63  double cosb = cos(b);
64  if(fabs(cosb)<=1e-13)
65  Element::throwError("Singularity in rotation.");
66  //J.e(0,0) = 0;
67  J.e(0,1) = -sina;
68  J.e(0,2) = cosa*cosb;
69  //J.e(1,0) = 0;
70  J.e(1,1) = cosa;
71  J.e(1,2) = sina*cosb;
72  //J.e(2,0) = 1;
73  //J.e(2,1) = 0;
74  J.e(2,2) = -sin(b);
75  return J;
76  }
77  typename B::DRetDArg parDerDirDer(const Arg &qd, const Arg &q) override {
78  double a = q.e(0);
79  double b = q.e(1);
80  double ad = qd.e(0);
81  double bd = qd.e(1);
82  double cosa = cos(a);
83  double sina = sin(a);
84  double cosb = cos(b);
85  double sinb = sin(b);
86  Jd.e(0,1) = -cosa*ad;
87  Jd.e(0,2) = -sina*cosb*ad - cosa*sinb*bd;
88  Jd.e(1,1) = -sina*ad;
89  Jd.e(1,2) = cosa*cosb*ad - sina*sinb*bd;
90  Jd.e(2,2) = -cosb*bd;
91  return Jd;
92  }
93  Function<fmatvec::MatV(Arg)>* getMappingFunction() const override { return new RotationAboutAxesZYXMapping<Arg>; }
94  Function<fmatvec::MatV(Arg)>* getTransformedMappingFunction() const override { return new RotationAboutAxesZYXTransformedMapping<Arg>; }
95  };
96 
97 }
98 
99 #endif
Definition: rotation_about_axes_zyx_transformed_mapping.h:28
Definition: rotation_about_axes_zyx.h:30
rotation class for rotation about three axes
Definition: rotation_about_three_axes.h:31
Definition: contact_kinematics.h:32
Definition: rotation_about_axes_zyx_mapping.h:28
namespace MBSim
Definition: bilateral_constraint.cc:29