iMSTK
Interactive Medical Simulation Toolkit
RbdAxesLockingConstraint.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkRbdConstraint.h"
10 
11 using namespace imstk;
12 
19 {
20 public:
22  std::shared_ptr<RigidBody> obj,
23  const Vec3d& axesPt,
24  const Vec3d& axesDir,
25  const double beta = 0.05) : RbdConstraint(obj, nullptr, Side::A),
26  m_axesPt(axesPt),
27  m_axesDir(axesDir),
28  m_beta(beta)
29  {
30  }
31 
32  ~RbdAxesLockingConstraint() override = default;
33 
34  IMSTK_TYPE_NAME(RbdAxesLockingConstraint)
35 
36 public:
37  void compute(double dt) override
38  {
39  // Jacobian of contact (defines linear and angular constraint axes)
40  J = Eigen::Matrix<double, 3, 4>::Zero();
41  if ((m_side == Side::AB || m_side == Side::A) && !m_obj1->m_isStatic)
42  {
43  // Displacement to needle Axes, constrain it to the axes
44  const Vec3d diff = m_obj1->getPosition() - m_axesPt;
45  const Vec3d perpDisplacement = diff - m_axesDir.dot(diff) * m_axesDir;
46  const double displacement = perpDisplacement.norm();
47  if (displacement != 0)
48  {
49  const Vec3d displacementDir = perpDisplacement / displacement;
50  vu = displacement * m_beta / dt;
51 
52  // Displacement from center of mass
53  J(0, 0) = -displacementDir[0]; J(0, 1) = 0.0;
54  J(1, 0) = -displacementDir[1]; J(1, 1) = 0.0;
55  J(2, 0) = -displacementDir[2]; J(2, 1) = 0.0;
56  }
57  else
58  {
59  vu = 0.0;
60  }
61  }
62  }
63 
64 private:
65  Vec3d m_axesPt;
66  Vec3d m_axesDir;
67  double m_beta = 0.05;
68 };
Abstract class for rigid body constraints. A RbdConstraint should mainly provide a constraint jacobia...
Compound Geometry.
Constrains the body center of mass to a fixed axes.
void compute(double dt) override
Compute constraint jacobian.