flexible-collision-library / fcl

Flexible Collision Library
https://flexible-collision-library.github.io/
Other
1.44k stars 416 forks source link

Collision distance for mesh models does not return correct results when objects are in collision #491

Open SLrepo opened 4 years ago

SLrepo commented 4 years ago

According to the reference, collision distance should be negative when objects are in collision. However, when the objects are not primitive shapes (e.g. when a loaded .obj file object is in collision with some other objects), the min_distance returned by DistanceResult is always 0. Below is an example.

BVHModel<RSS> m1; std::vector<Vector3> p1; std::vector t1; loadOBJFile("mesh.obj", p1, t1); m1.beginModel(); m1.addSubModel(p1, t1); m1.endModel(); BVHModel<RSS> m2; Cylinder c2(20, 40); generateBVHModel(m2, c2, Transform3::Identity(), 16, 16); Transform3 tf1 = Transform3::Identity(); tf1.translation() = Vector3(20, 0, 0); DistanceRequest request; request.enable_signed_distance = true; DistanceResult res; res.clear(); distance(&m1, Transform3::Identity(), &m2, tf1, request, res); std::cout << "The penetration depth is " << res.min_distance << "\n";

When I change the first axis of "tf1" from 0 to 20, the returned min_distance gradually become smaller, at some point, it should become negative (objects in collision). However, it never becomes negative and stayed at 0. The .obj file I used is from here, the 'loadOBJFile' function is the same as the one used in fcl/test.

jmirabel commented 4 years ago

FCL cannot compute the penetration between a non-convex mesh and anything else, for several reasons.

  1. BVHModel may not even be closed so the interior or exterior is not well defined. Thus BVHModel are surface only.
  2. Even if you define conventionally an interior, for a non-convex model, computing the penetration depth is not a local problem any more and is thus hard (read time-consuming) to compute. This isn't implemented in FCL.
SLrepo commented 4 years ago

FCL cannot compute the penetration between a non-convex mesh and anything else, for several reasons.

  1. BVHModel may not even be closed so the interior or exterior is not well defined. Thus BVHModel are surface only.
  2. Even if you define conventionally an interior, for a non-convex model, computing the penetration depth is not a local problem any more and is thus hard (read time-consuming) to compute. This isn't implemented in FCL.

Does it mean if the meshes are convex, fcl would work? Since a non-convex shape can be decomposed into several convex shapes.

SeanCurtis-TRI commented 4 years ago

Correct. The key being that convex shapes, by definition, must be closed. :) There is no ambiguity about inside/outside and there will be a well-defined minimum-translational distance (even though the "nearest point" may not be unique.)