MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / computeFrictionVectors

Method computeFrictionVectors

src/systems/ContactSolverSystem.cpp:789–818  ·  view source on GitHub ↗

Compute the two unit orthogonal vectors "t1" and "t2" that span the tangential friction plane for a contact manifold. The two vectors have to be such that : t1 x t2 = contactNormal.

Source from the content-addressed store, hash-verified

787// Compute the two unit orthogonal vectors "t1" and "t2" that span the tangential friction plane
788// for a contact manifold. The two vectors have to be such that : t1 x t2 = contactNormal.
789void ContactSolverSystem::computeFrictionVectors(const Vector3& deltaVelocity, ContactManifoldSolver& contact) const {
790
791 RP3D_PROFILE("ContactSolver::computeFrictionVectors()", mProfiler);
792
793 assert(contact.normal.length() > decimal(0.0));
794
795 // Compute the velocity difference vector in the tangential plane
796 decimal deltaVDotNormal = deltaVelocity.dot(contact.normal);
797 Vector3 normalVelocity = deltaVDotNormal * contact.normal;
798 Vector3 tangentVelocity(deltaVelocity.x - normalVelocity.x, deltaVelocity.y - normalVelocity.y,
799 deltaVelocity.z - normalVelocity.z);
800
801 // If the velocty difference in the tangential plane is not zero
802 const decimal lengthTangentVelocity = tangentVelocity.length();
803 if (lengthTangentVelocity > MACHINE_EPSILON) {
804
805 // Compute the first friction vector in the direction of the tangent
806 // velocity difference
807 contact.frictionVector1 = tangentVelocity / lengthTangentVelocity;
808 }
809 else {
810
811 // Get any orthogonal vector to the normal as the first friction vector
812 contact.frictionVector1 = contact.normal.getOneUnitOrthogonalVector();
813 }
814
815 // The second friction vector is computed by the cross product of the first
816 // friction vector and the contact normal
817 contact.frictionVector2 = contact.normal.cross(contact.frictionVector1);
818}

Callers

nothing calls this directly

Calls 4

lengthMethod · 0.45
dotMethod · 0.45
crossMethod · 0.45

Tested by

no test coverage detected