humanoid-path-planner / hpp-fcl

An extension of the Flexible Collision Library
Other
300 stars 90 forks source link

Compute multiple contact points/contact surfaces #574

Closed lmontaut closed 4 months ago

lmontaut commented 5 months ago

This solves #144 and #163, i.e. hpp::fcl::computeContactPatch(s1, tf1, s2, tf2, collision_result, patch_request, patch_result) now computes the intersection polygon between the collision pair (s1, tf1) and (s2, tf2), after hpp::fcl::collide(s1, tf1, s2, tf2, collision_request, collision_result) has been called on the collision pair.

The C++ code has been exposed to python. Example using the python bindings:

    halfside = 0.5
    shape1 = hppfcl.Box(2 * halfside, 2 * halfside, 2 * halfside)
    shape2 = hppfcl.Box(2 * halfside, 2 * halfside, 2 * halfside)

    tf1 = hppfcl.Transform3f()
    tf2 = hppfcl.Transform3f()
    offset = 0.05
    tf2.setTranslation(np.array([0., 0., 2 * halfside - offset]))
    theta = np.pi / 4
    c = np.cos(theta)
    s = np.sin(theta)
    R = np.array([[c, -s, 0.0],
                  [s, c, 0.0],
                 [0, 0, 1.0]])
    tf1.setRotation(R)

    col_req = hppfcl.CollisionRequest()
    col_res = hppfcl.CollisionResult()
    hppfcl.collide(shape1, tf1, shape2, tf2, col_req, col_res)

    patch_req = hppfcl.ContactPatchRequest()
    patch_res = hppfcl.ContactPatchResult()
    hppfcl.computeContactPatch(shape1, tf1, shape2, tf2, col_res, patch_req, patch_res)

This script gives the following result (in purple, the points of the contact patch, in blue the contact patch normal): Screenshot 2024-05-06 at 18 16 14

Todos: