distance3d.gjk.gjk_distance¶
- distance3d.gjk.gjk_distance(collider1, collider2, tolerance=1e-10, max_distance_squared=100000.0, sanity_check=1e-08)¶
Gilbert-Johnson-Keerthi (GJK) algorithm for distance calculation.
This implementation extends the intersection test by closest point calculation after convergence. It is also possible to clip colliders that are too far away early.
Implementation based on Jolt Physics, Copyright 2021 Jorrit Rouwe, MIT license.
Based on: A Fast and Robust GJK Implementation for Collision Detection of Convex Objects - Gino van den Bergen, http://www.dtecta.com/papers/jgt98convex.pdf
- Parameters:
- collider1ConvexCollider
Convex collider 1.
- collider2ConvexCollider
Convex collider 2.
- tolerancefloat, optional (default: 1e-10)
Minimal distance between objects when the objects are considered to be colliding.
- max_distance_squaredfloat, optional (default: 100000)
The maximum squared distance between colliders before the objects are considered infinitely far away and processing is terminated.
- sanity_checkfloat, optional (default: 1e-8)
Use sanity_check=float(“inf”) to bypass sanity check.
- Returns:
- distancefloat
The shortest distance between two convex shapes.
- closest_point1array, shape (3,)
Closest point on first convex shape. If the distance is MAX_FLOAT the points are invalid.
- closest_point2array, shape (3,)
Closest point on second convex shape. If the distance is MAX_FLOAT the points are invalid.
- simplexarray, shape (4, 3)
Simplex defined by 4 points of the Minkowski difference between vertices of the two colliders.