flexible-collision-library / fcl

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

Incorrect nearest points when using distance(...) #275

Open pierrefranklin opened 6 years ago

pierrefranklin commented 6 years ago

I get incorrect nearest points when I use the following code:

#include <fcl/narrowphase/distance.h>

using namespace fcl;
using S = double;

int main(){

  Sphere<S> s1{20};
  Sphere<S> s2{10};

  Transform3<S> tf1{Transform3<S>::Identity()};
  Transform3<S> tf2{Transform3<S>::Identity()};

  DistanceRequest<S> request;
  request.enable_signed_distance = true;
  request.enable_nearest_points = true;
  request.gjk_solver_type = GST_LIBCCD;

  DistanceResult<S> result;

  bool res{false};

  // Expecting distance to be 10
  result.clear();
  tf2.translation() = Vector3<S>(0, 40, 0);
  res = distance(&s1, tf1, &s2, tf2, request, result);

  std::cout<<"fcl_result = "<<result.min_distance<<std::endl;
  std::cout<<"fcl_result point 1 = "<<result.nearest_points[0]<<std::endl;
  std::cout<<"fcl_result point 2 = "<<result.nearest_points[1]<<std::endl;

  return 0;

}

The output of the executable is

fcl_result = 25
fcl_result point 1 =       0
27.3333
      0
fcl_result point 2 =        0
-13.6667
       0

This is copied almost verbatim from the tests, specifically the test_distance_spheresphere(...) function in test_fcl_signed_distance. The only difference is that tf2.translation() = Vector3<S>(0, 40, 0); instead of tf2.translation() = Vector3<S>( 40, 0, 0); (ie X and Y are flipped).

This also happens with using the Z coordinate, and with other primitives.

hongkai-dai commented 6 years ago

I believe now the error should be fixed after #305. I ran your test, and here is the result

fcl_result = 10
fcl_result point 1 = -0.00055429
         20
          0
fcl_result point 2 = 0.000277145
        -10
          0
sherm1 commented 6 years ago

@pierrefranklin can you verify that the problem you observed is now fixed, and if so close this issue?

Thanks!