7 #include "imstkPbdEdgeEdgeConstraint.h" 15 double stiffnessA,
double stiffnessB)
22 m_stiffness[0] = stiffnessA;
23 m_stiffness[1] = stiffnessB;
28 double& c, std::vector<Vec3d>& dcdx)
30 const Vec3d& x0 = bodies.getPosition(
m_particles[0]);
31 const Vec3d& x1 = bodies.getPosition(
m_particles[1]);
32 const Vec3d& x2 = bodies.getPosition(
m_particles[2]);
33 const Vec3d& x3 = bodies.getPosition(
m_particles[3]);
35 const double a = (x3 - x2).dot(x1 - x0);
36 const double b = (x1 - x0).dot(x1 - x0);
37 const double cc = (x0 - x2).dot(x1 - x0);
38 const double d = (x3 - x2).dot(x3 - x2);
40 const double f = (x0 - x2).dot(x3 - x2);
42 const double det = a * e - d * b;
45 if (fabs(det) > 1e-12)
47 s = (cc * e - b * f) / det;
48 t = (cc * d - a * f) / det;
49 if (s < 0 || s > 1.0 || t < 0 || t > 1.0)
57 const Vec3d P = x0 + t * (x1 - x0);
58 const Vec3d Q = x2 + s * (x3 - x2);
62 const double l = n.norm();
72 dcdx[0] = (1 - t) * n;
75 dcdx[2] = -(1 - s) * n;
bool computeValueAndGradient(PbdState &bodies, double &c, std::vector< Vec3d > &dcdx) override
Compute value and gradient of constraint function.
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...
std::vector< PbdParticleId > m_particles
body, particle index
void initConstraint(const PbdParticleId &ptA1, const PbdParticleId &ptA2, const PbdParticleId &ptB1, const PbdParticleId &ptB2, double stiffnessA, double stiffnessB)
Initialize constraint.
Provides interface for accessing particles from a 2d array of PbdBody,Particles.