Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computing multiple contact points for Box-Box collision #616

Closed
vastsoun opened this issue Aug 9, 2024 · 1 comment
Closed

Computing multiple contact points for Box-Box collision #616

vastsoun opened this issue Aug 9, 2024 · 1 comment

Comments

@vastsoun
Copy link

vastsoun commented Aug 9, 2024

Hi there,

I've been trying to set up a box-on-box collision, one for a cube and another for a floor/ground, but have been getting only a single contact when performing collision checking. I used the unit test provided in test/box_box_collision.cpp as a sanity check against my own code, but it yields the same result:

Running 1 test case...
Num. Collisions: 1
Num. Collisions: 1
Num. Collisions: 0
Num. Collisions: 0

My question is: is it expected or intended to only issue a single contact for box-box or am I doing something wrong?
What I wanted to get was four (4) contacts.

Here is the modified version of the code I used to verify:

BOOST_AUTO_TEST_CASE(box_box_collision) {
  // Define boxes
  Box shape1(1, 1, 1);
  Box shape2(10, 10, 1);

  // Define transforms
  Transform3f T1 = Transform3f::Identity();
  Transform3f T2 = Transform3f::Identity();

  // Compute collision
  CollisionRequest req;
  req.num_max_contacts = 4;
  req.enable_cached_gjk_guess = true;
  req.distance_upper_bound = 1e-6;
  CollisionResult res;
  ComputeCollision collide_functor(&shape1, &shape2);

  T1.setTranslation(Vec3f(0, 0, 0.49));
  T2.setTranslation(Vec3f(0, 0, -0.5));
  res.clear();
  BOOST_CHECK(collide(&shape1, T1, &shape2, T2, req, res) == true);
  std::cout << "Num. Collisions: " << res.numContacts() << std::endl;
  res.clear();
  BOOST_CHECK(collide_functor(T1, T2, req, res) == true);
  std::cout << "Num. Collisions: " << res.numContacts() << std::endl;

  T1.setTranslation(Vec3f(0, 0, 1));
  res.clear();
  BOOST_CHECK(collide(&shape1, T1, &shape2, T2, req, res) == false);
  std::cout << "Num. Collisions: " << res.numContacts() << std::endl;
  res.clear();
  BOOST_CHECK(collide_functor(T1, T2, req, res) == false);
  std::cout << "Num. Collisions: " << res.numContacts() << std::endl;
}

I compiled and built the current version on the devel branch.

@lmontaut
Copy link
Contributor

lmontaut commented Aug 9, 2024

Hi @vastsoun,
You can check out #574 to see how to compute multiple contact points.
More processing is required to go from collision detection (computing the contact normal and a pair of contact points) to contact surface computation (computing multiple pairs of contact points that all share the same contact normal). Therefore, the contact surface computation uses the computeContactPatch function.

The num_max_contacts parameter in the CollisionRequest is the maximum number of contact normals that collide can compute. Since primitives are convex in hpp-fcl (box, sphere, ellipsoid, cones, convex meshes etc.), there is only one normal per call to collide.
The num_max_contacts is therefore only useful for non-convex objects such as BVHModel shapes.

@lmontaut lmontaut changed the title Problem with Box-Box collision Computing multiple contact points for Box-Box collision Aug 9, 2024
@coal-library coal-library locked and limited conversation to collaborators Aug 20, 2024
@jcarpent jcarpent converted this issue into discussion #617 Aug 20, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants