Package: collision
collision.pyInfoCollision is a python library meant for collision detection between convex and concave polygons, circles, and points.InsallationTo get the latest stable version:pip install collisionOr to get the latest development version:pip install https://github.com/QwekoDev/collision/archive/master.zipClassesclasscollision.Vector(x, y)A 2D vector/point classProperties:x(int) or (float)- The x-coordinatey(int) or (float)- The y-coordinateMethods:funccopy()→collision.vecReturn a copy of the vectorfuncset(v)Copy another vectors values onto the vectorv(collision.vec)- The vector to copy fromfuncperp()→collision.vecReturn the vector rotated perpandicularlyfuncrotate(angle)→collision.vecReturn the vector rotated the angleangle(int) or (float)- Radians to rotate the pointfuncreverse()→collision.vecReturn a reversed version of the vectorfuncnormalize()→collision.vecReturn a normalized version of the vectorfuncproject(v)→collision.vecReturn the vector projected onto the passed vectorv(collision.vec)- The vector to project uponfuncproject_n(v)→collision.vecReturn the vector projected onto a unit vectorv(collision.vec)- The vector to project uponfuncreflect(axis)→collision.vecReturn the vector reflected upon the passed axis vectoraxis(collision.vec)- The axis to reflect uponfuncreflect_n(axis)→collision.vecReturn the vector reflected upon the passed axis unit vectoraxis(collision.vec)- The axis to reflect uponfuncdot(v)→int or floatReturns the dot product of the vector and anotherv(collision.vec)- The other vector for the dot productfuncln()→int or floatReturns the length of the vectorfuncln2()→int or floatReturns the squared length of the vectorclasscollision.Circle(pos, radius)A simple circle with a position and radiusProperties:pos(collision.vec)- The center coordinate of the circleradius(int) or (float)- The radius of the circleMethods:funcget_aabb()→collision.PolyReturns the AABB bounding box of the circleclasscollision.Poly(pos, points, angle = 0)Aconvexpolygon with a position, a list of points relative to that position, and an angleProperties: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.Class Methods:funcPoly.from_box(pos, width, height)→collision.PolyCreates a polygon frompos(collision.vec)- The center coordinate of the polygon/boxwidth(int) or (float)- The width of the boxheight(int) or (float)- The height of the boxMethods:funcaabb()→collision.PolyReturns the AABB bounding box of the polygonfuncset_points(points)Change the base points relative to the position. After this is done, the polygon will be recalculated again. Angle will be preserved. Use this instead of editing thepointsproperty.funcget_centroid()→collision.vecGet the centroid of the polygon. The arithmatic mean of all of the points.classcollision.Concave_Poly(pos, points, angle = 0)Aconcavepolygon with a position, a list of points relative to that position, and an angle. This takes longer to collide than a regularPolydoes, 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 make up the concave polygon. Used for concave collisions.angle(int) or (float)- The angle which the polygon is rotated. Changing this will cause the polygon to be recalculated.Methods:funcaabb()→collision.Concave_PolyReturns the AABB bounding box of the polygonfuncset_points(points)Change the base points relative to the position. After this is done, the polygon will be recalculated again. Angle will be preserved. Use this instead of editing thepointsproperty.funcget_centroid()→collision.vecGet the centroid of the polygon. The arithmatic mean of all of the points.classcollision.Response()The result of a collision between two objects. 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,aandbwill no longer be colliding.a_in_b(bool)- Whetherais fully inside ofbb_in_a(bool)- Whetherbis fully inside ofaMethods:funcclear()→collision.ResponseClears the Response for re-use, and returns itselfTo be finished