iMSTK
Interactive Medical Simulation Toolkit
RbdLineToPointRotationConstraint.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  ~RbdLineToPointRotationConstraint() override = default;
32 
33  IMSTK_TYPE_NAME(RbdLineToPointRotationConstraint)
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 rotation to bring the line p,q to pass through point fixedPt
43  const Vec3d axes = (*m_q - m_obj1->getPosition()).normalized();
44  const Vec3d diff = m_fixedPt - m_obj1->getPosition();
45  const Vec3d rot = axes.cross(diff.normalized());
46  const Vec3d rotAxes = rot.normalized();
47 
48  // rot.norm gives area of crossed vectors, should be 0 when rotated to each other
49  vu = rot.norm() * m_beta / dt;
50  J(0, 0) = 0.0; J(0, 1) = rotAxes[0];
51  J(1, 0) = 0.0; J(1, 1) = rotAxes[1];
52  J(2, 0) = 0.0; J(2, 1) = rotAxes[2];
53  }
54  }
55 
56 private:
57  double m_beta = 0.05;
58 
59  Vec3d m_fixedPt;
60  Vec3d* m_p = nullptr;
61  Vec3d* m_q = nullptr;
62 };
Abstract class for rigid body constraints. A RbdConstraint should mainly provide a constraint jacobia...
void compute(double dt) override
Compute constraint jacobian.
Compound Geometry.