Skip to content
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

Sphere-sphere normal is nan during collision #344

Closed
EpicDuckPotato opened this issue Sep 11, 2022 · 2 comments
Closed

Sphere-sphere normal is nan during collision #344

EpicDuckPotato opened this issue Sep 11, 2022 · 2 comments

Comments

@EpicDuckPotato
Copy link

I'm trying to compute the normal vector between two intersecting spheres using computeDistances, and whenever I set their positions such that the min_distance <= 0, the normal vector is computed as nan. If I try the same experiment with a sphere and a box, I get a sensible normal vector.

import hppfcl
import numpy as np

sphere1_pos = np.array([-0.9, 0, 0])
sphere1_rmat = np.eye(3)
sphere1_rad = 0.5
sphere1_geom = hppfcl.Sphere(sphere1_rad)
sphere1_obj = hppfcl.CollisionObject(sphere1_geom, sphere1_rmat, sphere1_pos)

sphere2_pos = np.zeros(3)
sphere2_rmat = np.eye(3)
sphere2_rad = 0.5
sphere2_geom = hppfcl.Sphere(sphere2_rad)
sphere2_obj = hppfcl.CollisionObject(sphere2_geom, sphere2_rmat, sphere2_pos)

# Distance computation between sphere1 and sphere2
req = hppfcl.DistanceRequest(True)
res = hppfcl.DistanceResult()
distance = hppfcl.distance(sphere1_obj, sphere2_obj, req, res)
print(res.normal) # Prints [nan, nan, nan]

box_pos = np.zeros(3)
box_rmat = np.eye(3)
box_size = 1.0
box_geom = hppfcl.Box(box_size, box_size, box_size)
box_obj = hppfcl.CollisionObject(box_geom, box_rmat, box_pos)

# Distance computation between sphere1 and box
req = hppfcl.DistanceRequest(True)
res = hppfcl.DistanceResult()
distance = hppfcl.distance(sphere1_obj, box_obj, req, res)
print(res.normal) # Prints [1., 0., 0.]
@jmirabel
Copy link
Contributor

Indeed, I checked the code and the normal is not set.

Could you open a PR with a fix ? It is rather straightforward. If you do it, take care of the convention. I don't remember which one it is and it is not in the doc of DistanceResult::normal. Maybe @lmontaut can recall it ?

FCL_REAL ShapeShapeDistance<Sphere, Sphere>(

@jcarpent
Copy link
Member

This should be fixed in branch hppfcl3x ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants