iMSTK
Interactive Medical Simulation Toolkit
imstkPbdRigidBaryPointToPointConstraint.cpp
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 #include "imstkPbdRigidBaryPointToPointConstraint.h"
8 
9 namespace imstk
10 {
11 PbdRigidBaryPointToPointConstraint::PbdRigidBaryPointToPointConstraint(std::shared_ptr<RigidBody> obj1) :
12  PbdBaryPointToPointConstraint(),
13  RbdConstraint(
14  obj1,
15  nullptr,
16  RbdConstraint::Side::A)
17 {
18 }
19 
27 bool
29  double& c, std::vector<Vec3d>& dcdx)
30 {
31  // Compute the middle position between the point on the rigid body and the PBD object
32  m_diff = 0.5 * computeInterpolantDifference(bodies);
33 
34  c = m_diff.norm();
35 
36  if (c < IMSTK_DOUBLE_EPS)
37  {
38  m_diff = Vec3d::Zero();
39  return false;
40  }
41  m_diff /= c;
42 
43  for (size_t i = 0; i < dcdx.size(); i++)
44  {
45  if (m_bodiesSides[i])
46  {
47  dcdx[i] = -m_diff * m_weights[i];
48  }
49  else
50  {
51  dcdx[i] = m_diff * m_weights[i];
52  }
53  }
54 
55  return true;
56 }
57 
58 void
60 {
61  J = Eigen::Matrix<double, 3, 4>::Zero();
62 
63  J(0, 0) = -m_diff[0]; J(0, 1) = 0.0;
64  J(1, 0) = -m_diff[1]; J(1, 1) = 0.0;
65  J(2, 0) = -m_diff[2]; J(2, 1) = 0.0;
66 
67  // B stabilization term
68  vu = m_diff.norm() * m_beta / dt;
69 }
70 } // namespace imstk
Compound Geometry.
bool computeValueAndGradient(PbdState &bodies, double &c, std::vector< Vec3d > &dcdx) override
Compute value and gradient of constraint function.
Provides interface for accessing particles from a 2d array of PbdBody,Particles.
Definition: imstkPbdBody.h:229
void compute(double dt) override
Compute constraint jacobian.