Collision is a python library that is meant for collision detection between convex and concave polygons, circles, and points.
To get the latest stable version:
pip install collision
To get the latest development version run:
pip install https://github.com/qwertyquerty/collision/archive/master.zip
A 2D vector/point class
Properties:
x
(int) or (float) - The x-coordinatey
(int) or (float) - The y-coordinate
Methods:
Return a copy of the vector
Copy another vector's values onto the target vector
v
(collision.vec) - The vector to copy from
Return the vector rotated perpendicularly
Return the vector rotated to the angle
angle
(int) or (float) - Radians to rotate the point
Return a reversed version of the vector
Return a normalized version of the vector
Return the vector projected onto the passed vector
v
(collision.vec) - The vector to project upon
Return the vector projected onto a unit vector
v
(collision.vec) - The vector to project upon
Return the vector reflected upon the passed axis vector
axis
(collision.vec) - The axis to reflect upon
Return the vector reflected upon the passed axis unit vector
axis
(collision.vec) - The axis to reflect upon
Returns the dot product of the vector and another
v
(collision.vec) - The other vector for the dot product
Returns the length of the vector
Returns the squared length of the vector
A simple circle with a position and radius
Properties:
pos
(collision.vec) - The center coordinate of the circleradius
(int) or (float) - The radius of the circleaabb
(tuple(tuple(int or float)) - The axis alligned bounding box of the circle
A convex polygon with a position, a list of points relative to that position, and an angle
Properties:
pos
(collision.vec) - The center coordinate of the circlepoints
(list[collision.vec]) - A list of absolute points (each relative point + the position of the polygon.) Can not be directly edited.rel_points
(list[collision.vec]) - A list of points relative to the position. This property should not be directly changed.angle
(int) or (float) - The angle which the polygon is rotated. Changing this will cause the polygon to be recalculated.aabb
(tuple(tuple(int or float)) - The axis-aligned bounding box of the Poly
Class Methods:
Creates a polygon from
pos
(collision.vec) - The center coordinate of the polygon/boxwidth
(int) or (float) - The width of the boxheight
(int) or (float) - The height of the box
Methods:
Change the base points relative to the position. After this is done, the polygon will be recalculated again. The angle will be preserved. Use this instead of editing the points
property.
Get the centroid of the polygon. Arithmetic means all of the points.
A concave polygon with a position, a list of points relative to that position, and an angle. This takes longer to collide than a regular Poly
does, so only use this, if your shape must be concave.
Properties:
pos
(collision.vec) - The center coordinate of the circlepoints
(list[collision.vec]) - A list of absolute points (each relative point + the position of the polygon.) Can not be directly edited.rel_points
(list[collision.vec]) - A list of points relative to the position. This property should not be directly changed.tris
(list[collision.Poly]) - A list of triangles relative to the position on the poly that makes up the concave polygon is used for concave collisions.angle
(int) or (float) - The angle which the polygon is rotated. Changing this will cause the polygon to be recalculated.aabb
(tuple(tuple(int or float)) - The axis alligned bounding box of the Poly
Methods:
Change the base points relative to the position. After this is done, the polygon will be recalculated again. The angle will be preserved. Use this instead of editing the points
property.
Get the centroid of the polygon. Arithmetic means all of the points.
The result of a collision between two objects. It may optionally be passed to collision tests to retrieve additional information. At its cleared state, it may seem to have odd values. Ignore these, they are just there to make generating the response more efficient. The response should be ignored unless there is a successful collision.
Properties:
a
(collision shape) - The first object in the collision testb
(collision shape) - The second object in the collision testoverlap
(int) or (float) - Magnitude of the overlap on the shortest colliding axisoverlap_n
(collision.vec) - The shortest colliding axis (unit vector)overlap_v
(collision.vec) - The overlap vector. If this is subtracted from the position ofa
,a
andb
will no longer be colliding.a_in_b
(bool) - Whethera
is fully inside ofb
b_in_a
(bool) - Whetherb
is fully inside ofa
Methods:
Reset the Response for re-use, and returns itself
Test two shapes against each other. If a response is passed, and there is a collision, that response will be updated to the response values. The response will not be generated if there is no collision and it will be at its default values. Concave polys currently do not support responses.
a
(collision shape) - The first shape to testb
(collision shape) - The second shape to testresponse
(collision.Response) - Optional response that will be updated if there's a collision.
Test two axis-aligned bounding boxes against each other. This is already done in collision.collide
so there's no need for you to do it for optimization.
a
(tuple(tuple(int or float))) The first AABBb
(tuple(tuple(int or float))) The second AABB