iMSTK
Interactive Medical Simulation Toolkit
imstkPbdAngularConstraint.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:
21  PbdAngularConstraint(int numParticles) : PbdConstraint(numParticles) { }
22  ~PbdAngularConstraint() override = default;
23 
24  IMSTK_TYPE_NAME(PbdAngularConstraint)
25 
26 
27  void projectConstraint(PbdState& bodies,
30  const double dt, const SolverType& type) override;
31 };
32 
40 {
41 public:
43  ~PbdAngularHingeConstraint() override = default;
44 
45  void initConstraint(const PbdParticleId& pIdx0,
46  const Vec3d& hingeAxes,
47  const double compliance);
48 
55  bool computeValueAndGradient(PbdState& bodies,
56  double& c, std::vector<Vec3d>& dcdx) override;
57 
58 protected:
59  Vec3d m_hingeAxes = Vec3d(1.0, 0.0, 0.0); // The axes it can rotate around
60 };
61 
69 {
70 public:
72  ~PbdAngularDistanceConstraint() override = default;
73 
77  void initConstraint(const PbdParticleId& p0,
78  const PbdParticleId& p1,
79  const double compliance);
80 
85  void initConstraintOffset(
86  const PbdState& bodies,
87  const PbdParticleId& p0,
88  const PbdParticleId& p1,
89  const double compliance);
90 
95  void initConstraintOffset(
96  const PbdParticleId& p0,
97  const PbdParticleId& p1,
98  const Quatd rotationalOffset,
99  const double compliance);
100 
107  bool computeValueAndGradient(PbdState& bodies,
108  double& c, std::vector<Vec3d>& dcdx) override;
109 
110 protected:
111  Quatd m_offset = Quatd::Identity();
112 };
113 } // namespace imstk
void projectConstraint(PbdState &bodies, const double dt, const SolverType &type) override
Update positions by projecting constraints.
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.
Applies rotational correction only.
virtual bool computeValueAndGradient(PbdState &bodies, double &c, std::vector< Vec3d > &dcdx)=0
Compute value and gradient of the constraint.
Base Constraint class for Position based dynamics constraints.
SolverType
Type of solvers.
Constraints one orientation to be relative by a given angular distance/offset to another orientation...
Provides interface for accessing particles from a 2d array of PbdBody,Particles.
Definition: imstkPbdBody.h:229
Constraint a single oriented particle along an axes of rotation Aligns oriented particles up axes to ...