API Reference¶
distance3d
¶
Distance computation and collision detection in 3D.
distance3d.distance
¶
Distance calculation of specific geometric shapes.
Note that for distance calculations to triangles, rectangles, boxes, cylinders, spheres, capsules, and convex meshes GJK is usually the fastest option if applicable. GJK is not applicable if one of the geometric objects is a line or a plane and GJK is slower when one of the objects is a point or a line segment.
In the following table an X indicates that the distance computation between two geometric objects is implemented. G means the pair of shapes is covered by GJK.
point | line | line segment | plane | triangle | rectangle | circle | disk | box | ellipsoid | cylinder | |
---|---|---|---|---|---|---|---|---|---|---|---|
point | - | X | X | X | X | X | X | X | X | X | X |
line | X | X | X | X | X | X | X | - | X | - | - |
line segment | X | X | X | X | X | X | X | G | X | G | G |
plane | X | X | X | X | X | X | - | - | X | X | X |
triangle | X | X | X | X | X | X | - | G | G | G | G |
rectangle | X | X | X | X | X | G | - | G | G | G | G |
circle | X | X | X | - | - | - | - | - | - | - | - |
disk | X | - | G | - | G | G | - | X | G | G | G |
box | X | X | X | X | G | G | - | G | G | G | G |
ellipsoid | X | - | G | X | G | G | - | G | G | G | G |
cylinder | X | - | G | X | G | G | - | G | G | G | G |
Compute the shortest distance between point and line. |
|
Compute the shortest distance between point and line segment. |
|
Compute the shortest distance between a point and a plane. |
|
Compute the shortest distance between point and triangle. |
|
Compute the shortest distance from point to rectangle. |
|
Compute the shortest distance between point and circle (only line). |
|
Compute the shortest distance between point and disk. |
|
Compute the shortest distance between point and box. |
|
Compute the shortest distance between point and cylinder. |
|
Compute the shortest distance between point and ellipsoid. |
|
Compute the shortest distance between two lines. |
|
Compute the shortest distance between line and line segment. |
|
Compute the shortest distance from line to plane. |
|
Compute the shortest distance between point and triangle. |
|
Compute the shortest distance between line and rectangle. |
|
Compute the shortest distance between line and circle. |
|
Compute the shortest distance between line and box. |
|
Compute the shortest distance between two line segments. |
|
Compute the shortest distance between line segment and plane. |
|
Compute the shortest distance from line segment to triangle. |
|
Compute the shortest distance between line segment and rectangle. |
|
Compute the shortest distance between line segment and circle. |
|
Compute the shortest distance from line segment to box. |
|
Compute the shortest distance between two planes. |
|
Compute the shortest distance between a plane and a triangle. |
|
Compute the shortest distance between a plane and a rectangle. |
|
Compute the shortest distance between a plane and a box. |
|
Compute the shortest distance between a plane and an ellipsoid. |
|
Compute the shortest distance between a plane and a cylinder. |
|
Compute the shortest distance between two triangles. |
|
Compute the shortest distance between triangle and rectangle. |
|
Compute the shortest distance between two rectangles. |
|
Compute the shortest distance from rectangle to box. |
|
Compute the shortest distance between two disks. |
distance3d.colliders
¶
Colliders used for collision detection with GJK and MPR algorithms.
Convex collider base class. |
|
Convex hull of a set of vertices. |
|
Mesh collider that uses triangles for hill climbing. |
|
Box collider. |
|
Sphere collider. |
|
Capsule collider. |
|
Ellipsoid collider. |
|
Cylinder collider. |
|
Disk collider. |
|
Ellipse collider. |
|
Cone collider. |
|
Margin around collider. |
distance3d.broad_phase
¶
Broad-phase collision detection.
Bounding volume hierarchy (BVH) for broad phase collision detection. |
distance3d.containment
¶
Containment methods compute bounding volumes.
Compute axis-aligned bounding box (AABB) that contains points. |
|
Compute axis-aligned bounding box of sphere. |
|
Compute axis-aligned bounding box of an oriented box. |
|
Compute axis-aligned bounding box of cylinder. |
|
Compute axis-aligned bounding box of a capsule. |
|
Compute axis-aligned bounding box of a capsule. |
|
Compute axis-aligned bounding box of a disk. |
|
Compute axis-aligned bounding box of an ellipse. |
|
Compute axis-aligned bounding box of a cone. |
distance3d.gjk
¶
Gilbert-Johnson-Keerthi (GJK) for distance calculation of convex shapes.
The GJK algorithm only works for convex shapes. Concave objects have to be decomposed into convex shapes first.
This module contains several flavours of the GJK algorithm. Some of them only detect collisions (intersections) and some of them calculate distances between separated objects as well.
The original publication describing the algorithm is:
E.G. Gilbert, D.W. Johnson, S.S. Keerthi: A fast procedure for computing the distance between complex objects in three-dimensional space, IEEE Journal on Robotics and Automation (1988), https://graphics.stanford.edu/courses/cs448b-00-winter/papers/gilbert.pdf
Gilbert-Johnson-Keerthi (GJK) algorithm for distance calculation. |
|
Gilbert-Johnson-Keerthi (GJK) algorithm for distance calculation. |
|
Intersection test with Gilbert-Johnson-Keerthi (GJK) algorithm. |
|
Gilbert-Johnson-Keerthi (GJK) algorithm for distance calculation. |
|
Intersection test with Gilbert-Johnson-Keerthi (GJK) algorithm. |
|
Gilbert-Johnson-Keerthi (GJK) algorithm for distance calculation. |
|
Intersection test with Gilbert-Johnson-Keerthi (GJK) algorithm. |
|
Nesterov-accelerated GJK algorithm for distance calculation. |
|
Intersection test with Nesterov-accelerated GJK. |
|
Nesterov-accelerated GJK algorithm for distance calculation. |
|
Intersection test with Nesterov-accelerated GJK. |
distance3d.epa
¶
Expanding polytope algorithm (EPA) for collision resolution after GJK.
Expanding Polytope Algorithm (EPA). |
distance3d.mpr
¶
Minkowski portal refinement (MPR) for collision detection.
Another name for the algorithm is XenoCollide (for details, see http://xenocollide.snethen.com/). It has been presented in “Game Programming Gems 7” (Gem 2.5: XenoCollide: Complex Collision Made Simple).
This implementation of MPR is based on libccd (for details, see https://github.com/danfis/libccd). For the original code the copyright is of Daniel Fiser <danfis@danfis.cz>. It has been released under 3-clause BSD license.
Intersection test with Minkowski Portal Refinement (MPR). |
|
Minkowski Portal Refinement (MPR) with penetration info. |
distance3d.geometry
¶
Tools for geometric computations.
Extract line segment from rectangle. |
|
Convert rectangle to vertices. |
|
Convert box to face. |
|
Convert line segment to line. |
|
Convert box to vertices. |
|
Compute extreme point of cylinder along a direction. |
|
Compute extreme point of cylinder along a direction. |
|
Compute extreme point of ellipsoid along a direction. |
|
Compute extreme point of box along a direction. |
|
Compute extreme point of box along a direction. |
|
Compute extreme point of disk along a direction. |
|
Compute extreme point of ellipse along a direction. |
|
Compute extreme point of cone along a direction. |
|
Computes Hesse normal form of a plane. |
|
Computes line from Plücker coordinates. |
distance3d.self_collision
¶
Self-collision detection.
Detect self collisions of a robot represented by a BVH. |
|
Detect self collisions of a robot represented by a BVH. |
distance3d.containment_test
¶
Test if points are in sphere. |
|
Test if points are in capsule. |
|
Test if points are in ellipsoid. |
|
Test if points are in disk. |
|
Test if points are in cone. |
|
Test if points are in cylinder. |
|
Test if points are in box. |
|
Test if points are in convex mesh. |
distance3d.hydroelastic_contact
¶
Hydroelastic contact model for contact wrenches of rigid bodies.
The original name for this model is pressure field model. It has been presented in:
R. Elandt, E. Drumwright, M. Sherman and A. Ruina: A pressure field model for fast, robust approximation of net contact force and moment between nominally rigid objects, IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS), 2019, pp. 8238-8245, doi: 10.1109/IROS40897.2019.8968548.
The implementation is different, but is inspired by:
V. Huang, F. Wang, E. Zhang: An Efficient Implementation of Pressure Field Models, https://www.ekzhang.com/assets/pdf/Hydroelastics.pdf.
Contact forces between two objects. |
|
Find contact plane of two rigid bodies. |
|
Rigid body represented by tetrahedral mesh. |
|
Contact surface of tetrahedral meshes. |
distance3d.plotting
¶
Plotting functions for geometric shapes.
Plot line. |
|
Plot line. |
|
Plot rectangle. |
|
Plot triangle. |
|
Plot rectangle. |
|
Plot circle. |
|
Plot ellipse. |
|
Plot axis-aligned bounding box. |
|
Plot convex mesh. |
|
Plot tetrahedron. |
|
Plot tree of axis-aligned bounding boxes. |
distance3d.random
¶
Sample geometric shapes.
Sample 3D point from standard normal distribution. |
|
Sample 3D direction from standard normal distribution and normalize it. |
|
Sample 3D line. |
|
Sample 3D line segment. |
|
Sample plane in 3D. |
|
Sample rectangle. |
|
Sample triangle. |
|
Sample box. |
|
Sample capsule. |
|
Sample ellipsoid. |
|
Sample cylinder. |
|
Sample sphere. |
|
Sample ellipse. |
|
Sample cone. |
|
Sample convex mesh. |
distance3d.aabb_tree
¶
AABB Tree for broad phase collision detection. |
|
Creates result lists of all the overlapping aabbs (brute force). |
|
Returns true if aabb1 and aabb2 overlap. |