A simple python collision dectection tool
Project description
Features:
Polygon Collision Detection: Determine whether two 2D polygons overlap with accurate collision detection algorithms. Customizable Shapes: Define custom 2D shapes by specifying their vertices as Vector objects. Efficient Algorithm: Implementing the Separating Axis Theorem (SAT) ensures fast and reliable collision detection for complex polygons.
How It Works:
The library checks for collisions by projecting the shapes onto various axes and checking if the projections overlap. If there is no axis along which the projections of the two shapes do not overlap, they are colliding.
Code Examples:
from PolygonCollision import Shape
#Create 2 squares
polygon1=Shape(vertices=[(0,0),(0,20),(20,20),(20,0)]) #x:0 y:0, size 20
polygon2=Shape(vertices=[(10,10),(10,30),(30,30),(30,10)], fill=False) #x:10 y:10, size 20, outline shape
#Create circle
circle=Shape(vertices=[(30,30)],radius=10) #x:30 y:30, radius 10
if polygon1.collide(polygon2): #Check if polygon2 is touching polygon1 (True)
print("POLYGON COLLISION!!!")
else:
print("no polygon collision")
if polygon1.collide(circle): #Check if circle is touching polygon1 (False)
print("CIRCLE COLLISION!!!")
else:
print("no circle collision")
Output
POLYGON COLLISION!!!
no circle collision
License:
This Collision Detection Library is licensed under the MIT License - see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for PolygonCollision-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c6688662784960967bc0608ba950c19777fcfb44b713f56f987b347130def8d |
|
MD5 | 38303134e894ee144b2a0f8eb13ce82b |
|
BLAKE2b-256 | 83f6de43d8570ae352466d7e887860abc249763059fe26a2fe2cf0f9f58980ae |