A simple python collision dectection tool
Project description
PolygonCollision is a Python module designed for efficient collision detection between 2D polygons. Using the Separating Axis Theorem (SAT), this library enables precise detection of intersections between polygons, making it an essential tool for game developers, simulations, and applications requiring accurate collision detection between shapes.
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. Calculate verlocity: Calculate the verlocity between two different shapes. 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:
import PolygonCollision
#Create Squares
polygon1 = PolygonCollision.shape.Shape(vertices = [(0, 0), (0, 10), (10, 10), (10, 0)])
polygon2 = PolygonCollision.shape.Shape(vertices = [(5, 5), (5, 15), (15, 15), (15, 5)], fill=False)
#Create Circle
circle = PolygonCollision.shape.Shape(vertices = [(30, 30)], radius = 5)
#Output The Size And Posiotion Of The Shapes
print('polygon1:', polygon1.get_width(), polygon1.get_height())
#Check For Polygons Collision
if polygon1.collide(polygon2):
print('POLYGON COLLISION!!!')
else:
print('no polygon colllision')
#Check For Polygons + Circle Collision
if polygon1.collide(polygon2):
print('CIRCLE COLLISION!!!')
else:
print('no circle colllision')
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
File details
Details for the file PolygonCollision-0.0.6.tar.gz
.
File metadata
- Download URL: PolygonCollision-0.0.6.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4645f577508b47810755ccf5e502a6556ffbcd4080e4166e37d1d5cb0d6d3d2c |
|
MD5 | 0691b59ebdd23d570cbe66612192701c |
|
BLAKE2b-256 | ba2dc0f77bb8b080c90a9a6f4bedf71bfd66590934d99e60bfa376d141c96285 |
File details
Details for the file PolygonCollision-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: PolygonCollision-0.0.6-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 131d005b49bfb9812b8a626347dea76aa90de7b57abbb97d6d187cccbb016b18 |
|
MD5 | 9453e51a513c0d2f6ba223ecf42b1ad6 |
|
BLAKE2b-256 | 5f3757c1ee9b28f211e21ff3fdb097ddf61ff4def559c15e5fcab3b8a32d70c8 |