7 #include "imstkEdgeEdgeCCDState.h" 8 #include "imstkPbdEdgeEdgeCCDConstraint.h" 9 #include "imstkLineMeshToLineMeshCCD.h" 15 Vec3d* prevPtA0, Vec3d* prevPtA1,
16 Vec3d* prevPtB0, Vec3d* prevPtB1,
19 double stiffnessA,
double stiffnessB,
22 m_prevEdgeA[0] = prevPtA0;
23 m_prevEdgeA[1] = prevPtA1;
24 m_prevEdgeB[0] = prevPtB0;
25 m_prevEdgeB[1] = prevPtB1;
32 m_stiffness[0] = stiffnessA;
33 m_stiffness[1] = stiffnessB;
34 m_ccdSubsteps = ccdSubsteps;
43 for (
int k = 0; k < m_ccdSubsteps; k++)
51 double& c, std::vector<Vec3d>& dcdx)
53 const Vec3d& currPt0 = bodies.getPosition(
m_particles[0]);
54 const Vec3d& currPt1 = bodies.getPosition(
m_particles[1]);
55 const Vec3d& currPt2 = bodies.getPosition(
m_particles[2]);
56 const Vec3d& currPt3 = bodies.getPosition(
m_particles[3]);
58 const Vec3d& prevPt0 = *m_prevEdgeA[0];
59 const Vec3d& prevPt1 = *m_prevEdgeA[1];
60 const Vec3d& prevPt2 = *m_prevEdgeB[0];
61 const Vec3d& prevPt3 = *m_prevEdgeB[1];
66 double timeOfImpact = 0.0;
68 if (collisionType == 0)
74 const double s = currState.
si();
75 const double t = currState.
sj();
76 const Vec3d n0 = prevState.
pi() - prevState.
pj();
77 const Vec3d n1 = currState.
pi() - currState.
pj();
81 bool crossing =
false;
88 const double d = n.norm();
98 dcdx[0] = (1 - s) * n;
101 dcdx[2] = -(1 - t) * n;
106 c = d + currState.thickness();
110 c = std::abs(d - currState.thickness());
const Vec3d & pj() const
Pj is the closest point on segment xj–xj1 to segment xi–xi1.
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
const Vec3d & pi() const
Pi is the closest point on segment xi–xi1 to segment xj–xj1.
void initConstraint(Vec3d *prevPtA0, Vec3d *prevPtA1, Vec3d *prevPtB0, Vec3d *prevPtB1, const PbdParticleId &ptA0, const PbdParticleId &ptA1, const PbdParticleId &ptB0, const PbdParticleId &ptB1, double stiffnessA, double stiffnessB, int ccdSubsteps=25)
Initialize constraint.
static int testCollision(const EdgeEdgeCCDState &prev, EdgeEdgeCCDState &curr, double &relativeTimeOfImpact)
Performs a collision test based on two given timesteps that store the state of two lines each...
void projectConstraint(PbdState &bodies, const double dt, const SolverType &type) override
Performs the actual positional solve.
bool computeValueAndGradient(PbdState &bodies, double &c, std::vector< Vec3d > &dcdx) override
Compute value and gradient of constraint function.
const double sj() const
Parameterized position of closest point on segment xj–xj1 to segment xi–xi1.
SolverType
Type of solvers.
const double si() const
Parameterized position of closest point on segment xi–xi1 to segment xj–xj1.
void projectConstraint(PbdState &bodies, const double dt, const SolverType &type) override
Performs the actual positional solve.
Provides interface for accessing particles from a 2d array of PbdBody,Particles.