Possible Bug in walberla::geometry::getClosestLineBoxPoints
For some combinations of Capsules and Boxes the analytical collision detection of PE seems to yield wrong results.
This is probably caused by a bug in the function
Code Example to reproduce: The Capsule has radius 3, length 6 and is not rotated and translated, so its center line runs from (-3,0,0) to (3,0,0). The Box has size (3, 1.5, 1.5) and is somehow rotated and translated.
Vec3 box_pos(real_t(-2.46404), real_t(2.90053), real_t(-2.177)); Quat box_rot(real_t(0.712691),real_t(-0.509519),real_t(0.0466145), real_t(0.479884)); //Corresponding Bodies Box box(0, 0, box_pos, Vec3(0,0,0), box_rot, Vec3(3, real_t(1.5), real_t(1.5)), iron, false, true, false); Capsule cap(1, 1, Vec3(0,0,0), Vec3(0,0,0), Quat(), real_t(3.0), real_t(6.0), iron, false, true, false); //This is how getClosestLineBoxPoints is called in the collide-function: Vec3 line_point, box_point; walberla::geometry::getClosestLineBoxPoints( Vec3(3,0,0), Vec3(-3,0,0), box_pos, box_rot.toRotationMatrix(), Vec3(real_t(3), real_t(1.5), real_t(1.5)), line_point, box_point); std::cerr << "Result: Line-Point " << line_point ", Box-Point " << box_point << std::endl;
This results in the following output:
Result: Line-Point <3,0,0>, Box-Point <-1.66899,2.22324,-1.94998>
This result is wrong, because if you rotate and translate the Corner (-1.5,-0.75,-0.75)(in box local coordinates) e.g. by
std::cerr << "Corner Position of Box: " << box_pos+box_rot.rotate(Vec3(real_t(-1.5), real_t(-0.75), real_t(-0.75))) << std::endl;
you obtain the point (-2.40108,1.35235,-1.18999) which is the nearest point of the box to the line. The nearest point on the line would then be (-2.40108, 0, 0).
The return of the incorrect points in this case results in a failure to detect the collision between the Box and the Capsule (which has a large penetration depth of about 1.1986).