This package implements collision detection for 2D shapes based on the separating axis theorem. Shape representations leverage StaticArrays.jl for computational efficiency; this package targets applications potentially requiring millions of collision checks, e.g., robot motion planning.
This package exports the abstract type
Shape2D and the following concrete types for collision checking:
AxisAlignedBoundingBox <: Shape2D(equivalently,
AABB((xl, xu), (yl, yu)): constructs an instance corresponding to the set [
xu] × [
AABB(Δx, Δy): constructs an instance corresponding to the set [-
Δx/2] × [-
LineSegment <: Shape2D
LineSegment(v, w)constructs a line segment connecting
Polygon <: Shape2D
Polygon(points...): constructs a convex polygon with vertices
pointsmust be supplied in counter-clockwise order.
Triangle(p1, p2, p3): convenience constructor that reorders three points into CCW order before calling
Circle <: Shape2D
Circle(c, r): constructs a circle centered at
Circle(r): constructs a circle centered at the origin with radius
CompoundShape <: Shape2D
CompoundShape(parts...): groups a list of other
Shape2Ds into a single (possible non-convex) collision object.
This package also exports a few methods for transforming/creating new shapes from others.
Transformations from CoordinateTranformations.jl may be applied to shapes to produce the expected output; some care must be taken, however, to ensure that only rigid transformations are applied to
Circles as there is currently no
inflate(X, ε; round_corners=true): inflates a shape
Xby a buffer
ε> 0. The
round_cornerskeyword argument may be set to
falseto ensure that inflating an
Polygonyields just a single
Polygon(performing an approximate inflation) instead of a
CompoundShapeconsisting of a
sweep: this function is used internally to facilitate continuous (i.e., "swept") collision detection.
sweep(X1, X2): yields a shape corresponding to the area swept out by moving shape
X2involves a rotation, this rotation should be "reasonably small" or this will probably produce junk).
sweep(X, f1, f2): equivalent to
SeparatingAxisTheorem2D.jl defines the following functions for collision checking:
intersectingfor discrete collision detection.
intersecting(X, Y): true iff
Yare in collision.
intersecting(X, Y, f): true iff
f(Y)are in collision.
sweep_intersectingfor continuous collision detection.
sweep_intersecting(X, Y1, Y2): true iff
sweep(Y1, Y2)are in collision.
sweep_intersecting(X, Y, f1, f2): true iff
sweep(f1(X), f2(X))are in collision.
sweep_intersecting(X, fX1, fX2, Y, fY1, fY2): supposing that
Xis getting swept from transformation
Yis simultaneously getting swept from transformation
fY2, returns true iff the shapes are ever in collision.