Collider
kivy_garden.collider
- class kivy_garden.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.
- bounding_box(self)
Returns the bounding box containing the polygon as 4 points (x1, y1, x2, y2), where x1, y1 is the lower left and x2, y2 is the upper right point of the rectangle.
- collide_point(self, double x, double y)
- collide_points(self, points)
- get_area(self)
- get_centroid(self)
- get_inside_points(self)
Returns a list of all the points that are within the polygon.
- class kivy_garden.collider.CollideBezier
Bases:
object
Takes a list of control points describing a Bezier curve and tests whether a point falls in the Bezier curve described by them.
- bounding_box(self)
- collide_point(self, double x, double y)
- collide_points(self, points)
- static convert_to_poly(points, int segments=180)
- get_area(self)
- get_centroid(self)
- get_inside_points(self)
- class kivy_garden.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
- bounding_box(self)
- collide_point(self, double x, double y)
- collide_points(self, points)
- estimate_distance(self, double x, double y, double error=1e-5)
- get_area(self)
- get_centroid(self)
- get_inside_points(self)