py4sci

Table Of Contents

Previous topic

Welcome to Collider’s documentation!

This Page

The Collider API

collider

Collider

The collider module contains classes which can be used to test membership of a point in some space. See individual class documentation for details.

_images/Screenshot.png

To use it you first have to cythonize the code. To do that, cd to the directory containing collider.pyx and:

python setup.py build_ext --inplace
class collider.Collide2DPoly

Bases: object

Collide2DPoly checks whether a point is within a polygon defined by a list of corner points.

Based on http://alienryderflex.com/polygon/

For example, a simple triangle:

>>> collider = Collide2DPoly([10., 10., 20., 30., 30., 10.],
... cache=True)
>>> (0.0, 0.0) in collider
False
>>> (20.0, 20.0) in collider
True

The constructor takes a list of x,y points in the form of [x1,y1,x2,y2...] as the points argument. These points define the corners of the polygon. The boundary is linearly interpolated between each set of points. The x, and y values must be floating points. The cache argument, if True, will calculate membership for all the points so when collide_point is called it’ll just be a table lookup.

class collider.CollideEllipse

Bases: object

CollideEllipse checks whether a point is within an ellipse or circle aligned with the Cartesian plain, as defined by a center point and a major and minor radius. That is, the major and minor axes are along the x and y axes.

Parameters:
x: float

the x position of the center of the ellipse

y: float

the y position of the center of the ellipse

rx: float

the radius of the ellipse along the x direction

ry: float

the radius of the ellipse along the y direction

For example:

>>> collider = CollideEllipse(x=0, y=10, rx=10, ry=10)
>>> (0, 10) in collider
True
>>> (0, 0) in collider
True
>>> (10, 10) in collider
True
>>> (11, 10) in collider
False
>>>
>>> collider = CollideEllipse(x=0, y=10, rx=20, ry=10)
>>> (20, 10) in collider
True
>>> (21, 10) in collider
False