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. 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.Shape(vertices=[(0,0),(0,20),(20,20),(20,0)]) #x:0 y:0, size 20
polygon2=shape.Shape(vertices=[(10,10),(10,30),(30,30),(30,10)], fill=False) #x:10 y:10, size 20, outline shape

#Create circle
circle=shape.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

PolygonCollision-0.0.1.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

PolygonCollision-0.0.1-py3-none-any.whl (3.9 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