iMSTK
Interactive Medical Simulation Toolkit
imstkPbdDistanceConstraint.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 "imstkPbdConstraint.h"
10 
11 namespace imstk
12 {
19 {
20 public:
22 
23  IMSTK_TYPE_NAME(PbdDistanceConstraint)
24 
25 
26  void initConstraint(
30  const Vec3d& p0, const Vec3d& p1,
31  const PbdParticleId& pIdx0, const PbdParticleId& pIdx1,
32  const double k = 1e5)
33  {
34  initConstraint((p0 - p1).norm(), pIdx0, pIdx1, k);
35  }
36 
40  void initConstraint(const double restLength,
41  const PbdParticleId& pIdx0, const PbdParticleId& pIdx1,
42  const double k = 1e5);
43 
44  bool computeValueAndGradient(PbdState& bodies,
45  double& c, std::vector<Vec3d>& dcdx) override;
46 
50  double getRestValue() const { return m_restLength; }
51 
52 public:
53  double m_restLength = 0.0;
54 };
55 } // namespace imstk
double m_restLength
Rest length between the nodes.
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...
Compound Geometry.
void initConstraint(const Vec3d &p0, const Vec3d &p1, const PbdParticleId &pIdx0, const PbdParticleId &pIdx1, const double k=1e5)
Initialize the constraint with resting length as the length between the two points.
Distance constraints between two nodal points.
bool computeValueAndGradient(PbdState &bodies, double &c, std::vector< Vec3d > &dcdx) override
Compute value and gradient of the constraint.
Base Constraint class for Position based dynamics constraints.
double getRestValue() const
Return the rest configuration for the constraint.
Provides interface for accessing particles from a 2d array of PbdBody,Particles.
Definition: imstkPbdBody.h:229