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 <: Shape2DLineSegment(v, w)constructs a line segment connectingvandw.
Polygon <: Shape2DPolygon(points...): constructs a convex polygon with verticespoints.pointsmust be supplied in counter-clockwise order.Triangle(p1, p2, p3): convenience constructor that reorders three points into CCW order before callingPolygon.
Circle <: Shape2DCircle(c, r): constructs a circle centered atcwith radiusr.Circle(r): constructs a circle centered at the origin with radiusr.
CompoundShape <: Shape2DCompoundShape(parts...): groups a list of otherShape2Ds 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 toCircles as there is currently noEllipseshape implemented.inflate(X, ε; round_corners=true): inflates a shapeXby a bufferε> 0. Theround_cornerskeyword argument may be set tofalseto ensure that inflating anAABB,LineSegment, orPolygonyields just a singlePolygon(performing an approximate inflation) instead of aCompoundShapeconsisting of aPolygonandCircles.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 shapeX1to shapeX2(if sweepingX1toX2involves 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:
intersectingfor discrete collision detection.intersecting(X, Y): true iffXandYare in collision.intersecting(X, Y, f): true iffXandf(Y)are in collision.
sweep_intersectingfor continuous collision detection.Xstatic andYdynamicsweep_intersecting(X, Y1, Y2): true iffXandsweep(Y1, Y2)are in collision.sweep_intersecting(X, Y, f1, f2): true iffX1andsweep(f1(X), f2(X))are in collision.
XandYboth dynamicsweep_intersecting(X, fX1, fX2, Y, fY1, fY2): supposing thatXis getting swept from transformationfX1tofX2andYis simultaneously getting swept from transformationfY1tofY2, returns true iff the shapes are ever in collision.