7 #include "imstkRbdFrictionConstraint.h" 11 RbdFrictionConstraint::RbdFrictionConstraint(
12 std::shared_ptr<RigidBody> obj1,
13 std::shared_ptr<RigidBody> obj2,
14 const Vec3d& contactNormal,
15 const Vec3d& contactPt,
16 const double contactDepth,
17 const double frictionCoefficient,
18 const Side side) : RbdConstraint(obj1, obj2, side),
19 m_contactPt(contactPt), m_contactN(contactNormal),
20 m_contactDepth(contactDepth), m_frictionCoefficient(frictionCoefficient)
32 J = Eigen::Matrix<double, 3, 4>::Zero();
33 if ((m_side == Side::AB || m_side == Side::A) && !m_obj1->m_isStatic)
35 const double vN = m_contactN.dot(m_obj1->getVelocity());
36 const Vec3d vTan = m_obj1->getVelocity() - vN * m_contactN;
37 const Vec3d tan = vTan.normalized();
40 J(0, 0) = -tan[0];
J(0, 1) = 0.0;
41 J(1, 0) = -tan[1];
J(1, 1) = 0.0;
42 J(2, 0) = -tan[2];
J(2, 1) = 0.0;
44 const double fNMag = std::max(0.0, m_obj1->getForce().dot(-m_contactN));
45 const double fu = m_frictionCoefficient * fNMag;
49 if ((m_side == Side::AB || m_side == Side::B) && !m_obj2->m_isStatic)
51 const double vN = m_contactN.dot(m_obj2->getVelocity());
52 const Vec3d vTan = m_obj2->getVelocity() - vN * -m_contactN;
53 const Vec3d tan = vTan.normalized();
56 J(0, 0) = tan[0];
J(0, 1) = 0.0;
57 J(1, 0) = tan[1];
J(1, 1) = 0.0;
58 J(2, 0) = tan[2];
J(2, 1) = 0.0;
61 const double fNMag = std::max(0.0, m_obj2->getForce().dot(m_contactN));
62 const double fu = m_frictionCoefficient * fNMag;
void compute(double dt) override
Compute constraint jacobian.
Eigen::Matrix< double, 3, 4 > J
Jacobian, "vanish" to zero.