Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

# negative Signed distance #27

How to compute negative signed distance, i.e. penetration and direction to move? It seems that now I can only get 0 distance and some non-sense points.

Code snippet is

``````world = WorldModel()
create.primitives.box(1, 1, 1, world=world, name='Y')  #, type='GeometricPrimitive')
create.primitives.box(2, 2, 2, center=[1.4,0,0], world=world, name='Z')  #, type='GeometricPrimitive')
obj1 = world.terrain(0)
obj2 = world.terrain(1)
g1 = obj1.geometry()
g2 = obj2.geometry()
vis.spin(float('inf'))
rst = g1.distance(g2)
print('distance is ', rst.d)
p1 = [rst.cp1[i] for i in range(3)]
p2 = [rst.cp2[i] for i in range(3)]
print(p1, p2)

result is
distance is 0.0
[-0.30000000000000004, 0.5, -0.30000000000000004] [0.4, 0.5, -1.0]

• replies 4
• views 2K
• likes 0

There are some geometry types that support penetration depth estimation. Namely, primitive-primitive, volume grid-primitive, and volume grid-point cloud.

Penetration depth estimation between meshes is not (yet?) supported in Python. There are some approximation techniques in the C++ API that may be ok for small penetrations but they are not generally accurate.

The thing is, even if I uncomment it into

``````world = WorldModel()
create.primitives.box(1, 1, 1, world=world, name='Y', type='GeometricPrimitive')
create.primitives.box(2, 2, 2, center=[1.4,0,0], world=world, name='Z', type='GeometricPrimitive')
obj1 = world.terrain(0)
obj2 = world.terrain(1)
g1 = obj1.geometry()
g2 = obj2.geometry()
print(g1.type(), g2.type())
vis.spin(float('inf'))
rst = g1.distance(g2)
print('distance is ', rst.d)
p1 = [rst.cp1[i] for i in range(3)]
p2 = [rst.cp2[i] for i in range(3)]
print(p1, p2)

and the outputs are

GeometricPrimitive GeometricPrimitive
distance is 0.0

and rst.cp1 has zero size

With the help of someone else, I can adapt code from

to make distance computation correct. It gives me negative distance for penetrated objects.

A follow-up question, it seems that the implementation is to compute shortest distance between two point clouds. Should I worry about its computational complexity?

The complexity and availability of signed distances depends very much on the geometry types. The most recent pythondocs.klampt.org documentation should provide up to date information on the availability.

As for point-cloud distances, these are indeed somewhat slow for large point clouds (roughly O(n log n))