7 #include "imstkPbdVolumeConstraint.h" 13 const Vec3d& p0,
const Vec3d& p1,
const Vec3d& p2,
const Vec3d& p3,
25 m_restVolume = (1.0 / 6.0) * ((p1 - p0).cross(p2 - p0)).dot(p3 - p0);
30 double& c, std::vector<Vec3d>& dcdx)
32 const Vec3d& x0 = bodies.getPosition(
m_particles[0]);
33 const Vec3d& x1 = bodies.getPosition(
m_particles[1]);
34 const Vec3d& x2 = bodies.getPosition(
m_particles[2]);
35 const Vec3d& x3 = bodies.getPosition(
m_particles[3]);
37 const double onesixth = 1.0 / 6.0;
39 dcdx[0] = onesixth * (x1 - x2).cross(x3 - x1);
40 dcdx[1] = onesixth * (x2 - x0).cross(x3 - x0);
41 dcdx[2] = onesixth * (x3 - x0).cross(x1 - x0);
42 dcdx[3] = onesixth * (x1 - x0).cross(x2 - x0);
44 const double volume = dcdx[3].dot(x3 - x0);
void initConstraint(const Vec3d &p0, const Vec3d &p1, const Vec3d &p2, const Vec3d &p3, const PbdParticleId &pIdx0, const PbdParticleId &pIdx1, const PbdParticleId &pIdx2, const PbdParticleId &pIdx3, const double k=2.0)
Initializes the volume constraint.
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
double m_restVolume
Rest volume.
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.