iMSTK
Interactive Medical Simulation Toolkit
imstkPbdPointPointConstraint.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 "imstkPbdPointPointConstraint.h"
8 
9 namespace imstk
10 {
11 void
13  const PbdParticleId& ptA, const PbdParticleId& ptB,
14  double stiffnessA, double stiffnessB)
15 {
16  m_particles[0] = ptA;
17  m_particles[1] = ptB;
18 
19  m_stiffness[0] = stiffnessA;
20  m_stiffness[1] = stiffnessB;
21 }
22 
23 bool
25  double& c, std::vector<Vec3d>& dcdx)
26 {
27  // Current position during solve
28  const Vec3d& x0 = bodies.getPosition(m_particles[0]);
29  const Vec3d& x1 = bodies.getPosition(m_particles[1]);
30 
31  const Vec3d diff = x1 - x0;
32  c = diff.norm();
33 
34  if (c == 0.0)
35  {
36  return false;
37  }
38 
39  const Vec3d n = diff / c;
40 
41  // A
42  dcdx[0] = n;
43  // B
44  dcdx[1] = -n;
45 
46  return true;
47 }
48 } // namespace imstk
std::pair< int, int > PbdParticleId
Index pair that refers to a particle in a PbdState. Index 0 is the body id, Index 1 is the particle i...
bool computeValueAndGradient(PbdState &bodies, double &c, std::vector< Vec3d > &dcdx) override
Compute value and gradient of constraint function.
std::vector< PbdParticleId > m_particles
body, particle index
Compound Geometry.
Provides interface for accessing particles from a 2d array of PbdBody,Particles.
Definition: imstkPbdBody.h:229
void initConstraint(const PbdParticleId &ptA, const PbdParticleId &ptB, double stiffnessA, double stiffnessB)
Initialize constraint.