iMSTK
Interactive Medical Simulation Toolkit
RbdLineToPointTranslationConstraint.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& fixedPt,
24  Vec3d* p, Vec3d* q,
25  const double beta = 0.05) : RbdConstraint(obj, nullptr, Side::A),
26  m_beta(beta), m_fixedPt(fixedPt),
27  m_p(p), m_q(q)
28  {
29  }
30 
31  ~RbdLineToPointTranslationConstraint() override = default;
32 
34 
35 public:
36  void compute(double dt) override
37  {
38  // Jacobian of contact (defines linear and angular constraint axes)
39  J = Eigen::Matrix<double, 3, 4>::Zero();
40  if ((m_side == Side::AB || m_side == Side::A) && !m_obj1->m_isStatic)
41  {
42  // Gives the translation to bring the line p,q to pass through point fixedPt
43  const Vec3d axes = (*m_q - *m_p).normalized();
44  const Vec3d diff = m_fixedPt - *m_p;
45  const Vec3d vecToLine = (diff - diff.dot(axes) * axes);
46  const Vec3d dirToLine = vecToLine.normalized();
47 
48  vu = vecToLine.norm() * m_beta / dt;
49  J(0, 0) = dirToLine[0]; J(0, 1) = 0.0;
50  J(1, 0) = dirToLine[1]; J(1, 1) = 0.0;
51  J(2, 0) = dirToLine[2]; J(2, 1) = 0.0;
52  }
53  }
54 
55 private:
56  double m_beta = 0.05;
57 
58  Vec3d m_fixedPt;
59  Vec3d* m_p = nullptr;
60  Vec3d* m_q = nullptr;
61 };
Abstract class for rigid body constraints. A RbdConstraint should mainly provide a constraint jacobia...
void compute(double dt) override
Compute constraint jacobian.
Compound Geometry.
Constraints the line p, q to the fixedPt by rotating p and q.