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

Module util

Contains utility functions, mainly to help with polygon creation
Functions
 
is_clockwise(points)
Check if the points given forms a clockwise polygon
 
is_left(p0, p1, p2)
Test if p2 is left, on or right of the (infinite) line (p0,p1).
 
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
 
get_poly_UA(pointlist, points_as_Vec2d=True)
Calculates the perimeter and area of a given polygon
Function Details

is_clockwise(points)

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

is_left(p0, p1, p2)

 
Test if p2 is left, on or right of the (infinite) line (p0,p1).
Returns:
> 0 for p2 left of the line through p0 and p1 = 0 for p2 on the line < 0 for p2 right of the line

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, ...])

get_poly_UA(pointlist, points_as_Vec2d=True)

 

Calculates the perimeter and area of a given polygon

Use calc_area() to get the area instead of this method

Returns:
U, A

Deprecated: Scheduled for deletion in pymunk 0.8.5+