Coal (Flexible Collision Library Extension)

3.0.2 · active · verified Thu Apr 16

Coal is an extension of the Flexible Collision Library (FCL) that provides efficient implementations of GJK and EPA algorithms for collision detection and distance computation in robotics and related fields. It offers robust Python bindings for easy prototyping and integration. Originally a fork named HPP-FCL, it was officially renamed to Coal in 2024. The library is actively maintained, with version 3.0.2 being the latest stable release.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define geometric primitives (e.g., capsules), set their poses using `Transform3s`, create `CollisionObject` instances, and perform collision detection and distance computation using `coal.collide` and `coal.distance`.

import numpy as np
import coal

# Define geometries
radius = 0.1
length = 0.5
capsule1_geom = coal.Capsule(radius, length)
capsule2_geom = coal.Capsule(radius, length)

# Define poses (transformations)
# Capsule 1 at origin, identity orientation
capsule1_tf = coal.Transform3s.Identity()

# Capsule 2 shifted along X-axis
capsule2_tf = coal.Transform3s.Identity()
capsule2_tf.translation[:] = np.array([0.2, 0.0, 0.0])

# Create collision objects
obj1 = coal.CollisionObject(capsule1_geom, capsule1_tf)
obj2 = coal.CollisionObject(capsule2_geom, capsule2_tf)

# Perform collision check
req = coal.CollisionRequest()
res = coal.CollisionResult()

# Note: coal.collide returns a boolean indicating collision state
collision_occurred = coal.collide(obj1, obj2, req, res)

if collision_occurred:
    print(f"Collision detected! Number of contacts: {len(res.contacts)}")
    for contact in res.contacts:
        print(f"  Contact point: {contact.pos.transpose()}, Normal: {contact.normal.transpose()}")
else:
    print("No collision detected.")

# Example for distance computation
req_dist = coal.DistanceRequest()
res_dist = coal.DistanceResult()

distance_found = coal.distance(obj1, obj2, req_dist, res_dist)

if distance_found:
    print(f"Minimum distance: {res_dist.min_distance}")
    print(f"Closest point on obj1: {res_dist.nearest_points[0].transpose()}")
    print(f"Closest point on obj2: {res_dist.nearest_points[1].transpose()}")

view raw JSON →