Skip to main content

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

PolygonCollision-0.0.6.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

PolygonCollision-0.0.6-py3-none-any.whl (4.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page