Skip to content

Add collision detection sample codes and doc #1217

Open

Description

@AtsushiSakai

Collision detection algorithm for real time processing is important for robotics.
So, these basic algorithm and knowledge should be added in this project.

Reference:
Amazon | Real-Time Collision Detection (The Morgan Kaufmann Series In Inteacive 3-D Technolagy) | Ericson, Christer | Software Development https://www.amazon.co.jp/-/en/Christer-Ericson/dp/1558607323

Activity

  1. idocode717 commented on Dec 28, 2025

    @idocode717

    Continuous Collision Detection (CCD)
    python

    Simplified CCD for moving spheres

    def sphere_ccd(sphere1_pos, sphere1_vel, sphere1_radius,
    sphere2_pos, sphere2_vel, sphere2_radius):
    # Relative motion
    rel_pos = sphere2_pos - sphere1_pos
    rel_vel = sphere2_vel - sphere1_vel
    combined_radius = sphere1_radius + sphere2_radius

    # Solve quadratic for collision time
    a = np.dot(rel_vel, rel_vel)
    b = 2 * np.dot(rel_pos, rel_vel)
    c = np.dot(rel_pos, rel_pos) - combined_radius**2
    
    discriminant = b**2 - 4*a*c
    if discriminant < 0:
        return float('inf')  # No collision
    
    t = (-b - np.sqrt(discriminant)) / (2*a)
    return max(0, t) if t >= 0 else float('inf')
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions