HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIM_ConRelSpring.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  */
7 
8 #ifndef __SIM_ConRelSpring_h__
9 #define __SIM_ConRelSpring_h__
10 
11 #include "SIM_API.h"
12 #include "SIM_ConRel.h"
13 #include "SIM_OptionsUser.h"
14 #include <UT/UT_Vector3.h>
15 #include <UT/UT_Matrix3.h>
16 
18 
19 /// Defines a spring force between two anchors to enforce the
20 /// constraint between them.
21 ///
22 /// The force is expressed mathematically as:
23 /// F = -k * (|x| - L) * ( x/|x| )
24 /// with a damping force of
25 /// Fd = -kd * (v . (x/|x|)) * (x/|x|)
26 /// where x is the vector connecting the two anchors and v is dx/dt.
27 ///
28 /// Torque is defined similarly.
30  public SIM_OptionsUser
31 {
32 public:
33  /// Retrieve the force (and optional jacobian) acting on objAnchor from a
34  /// spring.
35  UT_Vector3 getForce(const SIM_Time &time,
36  const SIM_ConAnchorSpatial &objAnchor,
37  const SIM_ConAnchorSpatial &otherAnchor,
38  UT_Matrix3 *jacobianPos = NULL,
39  UT_Matrix3 *jacobianVel = NULL);
40  UT_Vector3 getForce(const UT_Vector3 &objAnchorPos,
41  const UT_Vector3 &objAnchorVel,
42  const UT_Vector3 &otherAnchorPos,
43  const UT_Vector3 &otherAnchorVel,
44  const UT_Matrix3 &dofFilter);
45  UT_Vector3 getTorque(const UT_Quaternion &objOrient,
46  const UT_Vector3 &objAngVel,
47  const UT_Quaternion &anchorOrient,
48  const UT_Vector3 &anchorAngVel);
49  /// Get Jacobian with respect to position, dF/dx. The returned Jacobian
50  /// is w.r.t. the obj point (dF_i/dx_i); the Jacobian for the other
51  /// point is the same thing, just negated (dF_i/dx_j = -dF_i/dx_i)
52  UT_Matrix3 getJacobianPos(const UT_Vector3 &objAnchorPos,
53  const UT_Vector3 &objAnchorVel,
54  const UT_Vector3 &otherAnchorPos,
55  const UT_Vector3 &otherAnchorVel,
56  const UT_Matrix3 &dofFilter) const;
57  /// Get Jacobian with respect to velocity, dF/dv. Same caveats as dF/dx.
58  UT_Matrix3 getJacobianVel(const UT_Vector3 &objAnchorPos,
59  const UT_Vector3 &objAnchorVel,
60  const UT_Vector3 &otherAnchorPos,
61  const UT_Vector3 &otherAnchorVel,
62  const UT_Matrix3 &dofFilter) const;
63 
64  /// k
66  /// L
68  /// kd
70 
73 
74 protected:
75  explicit SIM_ConRelSpring(const SIM_DataFactory *factory);
76  virtual ~SIM_ConRelSpring();
77 
78  virtual void setStateForceSubclass(fpreal force);
79  virtual fpreal getStateForceSubclass() const;
81  virtual fpreal getStateDistanceSubclass() const;
82 
83  virtual void buildConRelGuide(
84  const GU_DetailHandle &gdh,
85  const SIM_Options &options,
86  const UT_Vector3 &anchor_pos_1,
87  const UT_Vector3 &anchor_pos_2,
88  const UT_Quaternion &anchor_rot_1,
89  const UT_Quaternion &anchor_rot_2,
90  const ConRelData &c_options) const;
91  virtual UT_Vector3 getForceSubclass(const UT_Vector3 &objAnchorPos,
92  const UT_Vector3 &objAnchorVel,
93  const UT_Vector3 &otherAnchorPos,
94  const UT_Vector3 &otherAnchorVel,
95  const UT_Matrix3 &dofFilter);
96  virtual UT_Vector3 getTorqueSubclass(const UT_Quaternion &objOrient,
97  const UT_Vector3 &objAngVel,
98  const UT_Quaternion &anchorOrient,
99  const UT_Vector3 &anchorAngVel);
100  virtual UT_Matrix3 getJacobianPosSubclass(const UT_Vector3 &objAnchorPos,
101  const UT_Vector3 &objAnchorVel,
102  const UT_Vector3 &otherAnchorPos,
103  const UT_Vector3 &otherAnchorVel,
104  const UT_Matrix3 &dofFilter) const;
105  virtual UT_Matrix3 getJacobianVelSubclass(const UT_Vector3 &objAnchorPos,
106  const UT_Vector3 &objAnchorVel,
107  const UT_Vector3 &otherAnchorPos,
108  const UT_Vector3 &otherAnchorVel,
109  const UT_Matrix3 &dofFilter) const;
110 
111  UT_Vector3 project(const UT_Vector3 &vec,
112  const UT_Matrix3 &dofFilter) const;
113 
114 private:
115  static const SIM_DopDescription *getConRelSpringDopDescription();
116 
117  fpreal myStateForce;
118  fpreal myStateDistance;
119 
122  SIM_ConRel,
123  "Spring Constraint Relationship",
124  getConRelSpringDopDescription());
125 };
126 
127 #endif
#define SIM_NAME_NUMITERATIONS
Definition: SIM_Names.h:152
#define DECLARE_STANDARD_GETCASTTOTYPE()
Definition: SIM_DataUtils.h:45
virtual void setStateForceSubclass(fpreal force)
#define GETSET_DATA_FUNCS_F(DataName, FuncName)
#define SIM_NAME_DISABLECOLLISIONS
Definition: SIM_Names.h:103
virtual fpreal getStateDistanceSubclass() const
#define DECLARE_DATAFACTORY(DataClass, SuperClass, Description, DopParms)
Definition: SIM_DataUtils.h:58
T distance(const UT_Vector4T< T > &v1, const UT_Vector4T< T > &v2)
Definition: UT_Vector4.h:634
#define GETSET_DATA_FUNCS_I(DataName, FuncName)
virtual void setStateDistanceSubclass(fpreal distance)
#define SIM_NAME_STRENGTH
Definition: SIM_Names.h:190
double fpreal
Definition: SYS_Types.h:263
#define SIM_API
Definition: SIM_API.h:10
virtual void buildConRelGuide(const GU_DetailHandle &gdh, const SIM_Options &options, const UT_Vector3 &anchor_pos_1, const UT_Vector3 &anchor_pos_2, const UT_Quaternion &anchor_rot_1, const UT_Quaternion &anchor_rot_2, const ConRelData &c_data) const
virtual fpreal getStateForceSubclass() const
#define SIM_NAME_RESTLENGTH
Definition: SIM_Names.h:175
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER Vec project(const Vec &s, const Vec &t)
Definition: ImathVecAlgo.h:96
#define SIM_NAME_DAMPING
Definition: SIM_Names.h:96