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:
Point
(alias forAbstractVector{<:Number}
)AxisAlignedBoundingBox <: Shape2D
(equivalently,AABB
)AABB((xl, xu), (yl, yu))
: constructs an instance corresponding to the set [xl
,xu
] × [yl
,yu
].AABB(Δx, Δy)
: constructs an instance corresponding to the set [-Δx/2
,Δx/2
] × [-Δy/2
,Δy/2
].
LineSegment <: Shape2D
LineSegment(v, w)
constructs a line segment connectingv
andw
.
Polygon <: Shape2D
Polygon(points...)
: constructs a convex polygon with verticespoints
.points
must be supplied in counter-clockwise order.Triangle(p1, p2, p3)
: convenience constructor that reorders three points into CCW order before callingPolygon
.
Circle <: Shape2D
Circle(c, r)
: constructs a circle centered atc
with radiusr
.Circle(r)
: constructs a circle centered at the origin with radiusr
.
CompoundShape <: Shape2D
CompoundShape(parts...)
: groups a list of otherShape2D
s into a single (possible non-convex) collision object.
This package also exports a few methods for transforming/creating new shapes from others.
Transformation
s 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 toCircle
s as there is currently noEllipse
shape implemented.inflate(X, ε; round_corners=true)
: inflates a shapeX
by a bufferε
> 0. Theround_corners
keyword argument may be set tofalse
to ensure that inflating anAABB
,LineSegment
, orPolygon
yields just a singlePolygon
(performing an approximate inflation) instead of aCompoundShape
consisting of aPolygon
andCircle
s.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 shapeX1
to shapeX2
(if sweepingX1
toX2
involves a rotation, this rotation should be "reasonably small" or this will probably produce junk).sweep(X, f1, f2)
: equivalent tosweep(f1(X), f2(X))
.
SeparatingAxisTheorem2D.jl defines the following functions for collision checking:
intersecting
for discrete collision detection.intersecting(X, Y)
: true iffX
andY
are in collision.intersecting(X, Y, f)
: true iffX
andf(Y)
are in collision.
sweep_intersecting
for continuous collision detection.X
static andY
dynamicsweep_intersecting(X, Y1, Y2)
: true iffX
andsweep(Y1, Y2)
are in collision.sweep_intersecting(X, Y, f1, f2)
: true iffX1
andsweep(f1(X), f2(X))
are in collision.
X
andY
both dynamicsweep_intersecting(X, fX1, fX2, Y, fY1, fY2)
: supposing thatX
is getting swept from transformationfX1
tofX2
andY
is simultaneously getting swept from transformationfY1
tofY2
, returns true iff the shapes are ever in collision.