Package pymunk :: Module util
[frames] | no frames]

Module util

Contains utility functions, mainly to help with polygon creation

Version: $Id: util.py 244 2010-01-16 17:39:13Z vb@viblo.se $

Functions
 
is_clockwise(points)
Check if the points given forms a clockwise polygon
 
is_convex(points)
Test if a polygon (list of (x,y)) is convex or not
 
reduce_poly(points, tolerance=0.5)
Remove close points to simplify a polyline tolerance is the min distance between two points squared.
 
convex_hull(points)
Create a convex hull from a list of points.
 
calc_center(points)
Calculate the center of a polygon
 
poly_vectors_around_center(pointlist, points_as_Vec2d=True)
Rearranges vectors around the center If points_as_Vec2d, then return points are also Vec2d, else pos
 
calc_area(points)
Calculate the area of a polygon
 
calc_perimeter(points)
Calculate the perimeter of a polygon
 
triangulate(poly)
Triangulates poly and returns a list of triangles
 
convexise(triangles)
Reduces a list of triangles (such as returned by triangulate()) to a non-optimum list of convex polygons
Function Details

is_clockwise(points)

 
Check if the points given forms a clockwise polygon
Returns:
True if the points forms a clockwise polygon

is_convex(points)

 
Test if a polygon (list of (x,y)) is convex or not
Returns:
True if the polygon is convex, False otherwise

reduce_poly(points, tolerance=0.5)

 
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)

convex_hull(points)

 
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)

calc_center(points)

 
Calculate the center of a polygon
Returns:
The center (x,y)

poly_vectors_around_center(pointlist, points_as_Vec2d=True)

 
Rearranges vectors around the center If points_as_Vec2d, then return points are also Vec2d, else pos
Returns:
pointlist ([Vec2d/pos, ...])

calc_area(points)

 
Calculate the area of a polygon
Returns:
Area of polygon

calc_perimeter(points)

 
Calculate the perimeter of a polygon
Returns:
Perimeter of polygon

triangulate(poly)

 
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)

convexise(triangles)

 
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