pymunk.util Module

This submodule contains utility functions, mainly to help with polygon creation.

pymunk.util.is_clockwise(points)[source]

Check if the points given forms a clockwise polygon

Returns:True if the points forms a clockwise polygon
pymunk.util.reduce_poly(points, tolerance=0.5)[source]

Remove close points to simplify a polyline tolerance is the min distance between two points squared.

Returns:The reduced polygon as a list of (x,y)
pymunk.util.convex_hull(points)[source]

Create a convex hull from a list of points. This function uses the Graham Scan Algorithm.

Returns:Convex hull as a list of (x,y)
pymunk.util.calc_area(points)[source]

Calculate the area of a polygon

Returns:Area of polygon
pymunk.util.calc_center(points)[source]

Calculate the center of a polygon

Returns:The center (x,y)
pymunk.util.poly_vectors_around_center(pointlist, points_as_Vec2d=True)[source]

Rearranges vectors around the center If points_as_Vec2d, then return points are also Vec2d, else pos

Returns:pointlist ([Vec2d/pos, ...])
pymunk.util.is_convex(points)[source]

Test if a polygon (list of (x,y)) is convex or not

Returns:True if the polygon is convex, False otherwise
pymunk.util.calc_perimeter(points)[source]

Calculate the perimeter of a polygon

Returns:Perimeter of polygon
pymunk.util.triangulate(poly)[source]

Triangulates poly and returns a list of triangles

Parameters :
poly

list of points that form an anticlockwise polygon (self-intersecting polygons won’t work, results are undefined)

pymunk.util.convexise(triangles)[source]

Reduces a list of triangles (such as returned by triangulate()) to a non-optimum list of convex polygons

Parameters :
triangles

list of anticlockwise triangles (a list of three points) to reduce