Module pymunk.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=500)
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 circumference and area of a given polygon

Function Details

is_clockwise

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

is_left

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

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

reduce_poly(points, tolerance=500)
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

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

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

poly_vectors_around_center

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

get_poly_UA(pointlist, points_as_Vec2d=True)
Calculates the circumference and area of a given polygon
Returns:
int(U), int(A)