Wrong Collision Result between complicated mesh and sphere
chenyanzz opened this issue ยท 5 comments
Version
- OS: macos 13.4.1
- conda_env: python 3.10
- pip_package: hppfcl==2.2.0
Bug Description
Collision Object 1 is the mesh "model.stl" inside the zip
Collision Object 2 is a Sphere center at (-2, 3, 0), with a radius of 50
Actually the two models DOES have a small slice of space between them,
However, the collide(obj1, obj2)
returns a wrong answer:result.isCollision() == True
.
And it shows the collision point is (-30.44375973, -43.73033919, 1.37608287)
(It is hard to show that there isn't a collision in a non-convex model in one image, so you can test it in your methods)
I draw the situation on blender:
The yellow dot is the collision point hpp-fcl decleared to be. But it is outside the Sphere.
And, However, There is NOT a collison at all.
The blender project is "test.blend" in zip
Testing Env
"test.py" also in the zip file
import hppfcl
import numpy
mesh_stl_path = '/in_zip_file/model.stl'
ball_pos = (-2, 3, 0)
ball_d = 100
# create objects
mesh_model = hppfcl.MeshLoader(hppfcl.BV_OBB).load(mesh_stl_path)
ball_model = hppfcl.Sphere(ball_d / 2)
mesh_obj = hppfcl.CollisionObject(mesh_model)
ball_obj = hppfcl.CollisionObject(ball_model)
place = hppfcl.Transform3f(numpy.array(ball_pos))
ball_obj.setTransform(place)
# try collide
req = hppfcl.CollisionRequest()
result = hppfcl.CollisionResult()
req.enable_contact = True
req.num_max_contacts = 1
hppfcl.collide(mesh_obj, ball_obj, req, result)
print('isCollision:', result.isCollision())
if result.isCollision():
contacts = result.getContacts()
contacts = list(map(lambda c: c.pos, contacts))
print('contacts:', contacts)
Qs
- Is there some mistake for me ?
- Is there any approach to quick-fix such situation ?
- Is it the problem within 'BVHModel' or 'gjk collide test' ?
Attachment ( zip file of everything )
At first glance, it might be a problem of normal orientation in the case of BVHs.
This issue would need time to be deeply investigated. Unfortunately, we are lacking of man power to handle this issue rapidly.
Hi @chenyanzz,
There doesn't seem to be a mistake from your side. I may have identified the issue but I need more time to debug it.
It has to do with a specialized function which BVH-sphere collisions call.
In the mean time, a quick fix is to replace Sphere
by Ellipsoid
in your code, like so:
# ball_model = hppfcl.Sphere(ball_d / 2)
ball_model = hppfcl.Ellipsoid((ball_d / 2) * numpy.ones(3))
@lmontaut
Well, By Using Ellipsoid, the contact point comes to the ball at [ 33.32329434, -26.13812054, -19.20840025], but still results in 'collided' (/cry)
Hi @chenyanzz, apologies for the late reply.
I can't seem to reproduce your bug using an ellipsoid instead of a ball.
If I run your code on my side but replace the ball by an ellipsoid:
# ball_model = hppfcl.Sphere(ball_d / 2)
ball_model = hppfcl.Ellipsoid((ball_d / 2) * numpy.ones(3))
I get the following output:
isCollision: False
I am also on macos 13.4.1. I ran your code using the latest hppfcl v. 2.3.5
installed using conda.
I will have a look to fix the bug for the ball case.