layermesh.geometry module

Geometry calculations.

layermesh.geometry.bounds_of_points(points)

Returns bounding box around the specified tuple, list, array or set of points, each one a tuple, list or array of length 2.

layermesh.geometry.in_polygon(pos, polygon)

Tests if the point pos (a tuple, list or array of length 2) a lies within a given polygon (a tuple or list of points, each itself a tuple, list or array of length 2).

layermesh.geometry.in_rectangle(pos, rect)

Tests if the point pos lies in an axis-aligned rectangle, defined as a two-element tuple or list of points [bottom left, top right], each itself a tuple, list or array of length 2.

layermesh.geometry.line_intersects_rectangle(rect, line)
layermesh.geometry.line_polygon_intersections(polygon, line, bound_line=(True, True), indices=False)

Returns a list of the intersection points at which a line crosses a polygon. The list is sorted by distance from the start of the line. The parameter bound_line controls whether to limit intersections between the line’s start and end points. If indices is True, also return polygon side indices of intersections.

layermesh.geometry.line_projection(a, line, return_xi=False)

Finds projection of point a onto a line (defined by two points, each a tuple, list or array of length 2). Optionally returns the non-dimensional distance xi between the line start and end.

layermesh.geometry.point_line_distance(a, line)

Finds the distance between point a and a line.

layermesh.geometry.polygon_area(polygon)

Calculates the (unsigned) area of an arbitrary polygon (a tuple, list or array of points, each one a tuple, list or array of length 2).

layermesh.geometry.polygon_boundary(this, other, polygon)

Returns point on a line between vector this and other and also on the boundary of the polygon.

layermesh.geometry.polygon_centroid(polygon)

Calculates the centroid of an arbitrary polygon (a tuple, list or array of points, each one a tuple, list or array of length 2).

layermesh.geometry.polyline_line_distance(polyline, line)

Returns minimum distance between a polyline and a line.

layermesh.geometry.polyline_polygon_intersections(polygon, polyline)

Returns a list of intersection points at which a polyline (a tuple, list or array of points, each one a tuple, list or array of length 2) crosses a polygon.

layermesh.geometry.rect_to_poly(rect)

Converts a rectangle to a polygon.

layermesh.geometry.rectangles_intersect(rect1, rect2)

Returns True if two rectangles intersect.

layermesh.geometry.rotation(angle, centre=None)

Returns 2-by-2 matrix A and vector b representing a rotation of the specified angle (degrees clockwise) about the specified centre (or the origin if no centre is specified). The rotation of a point p is then given by Ap + b.

layermesh.geometry.simplify_polygon(polygon, tolerance=1e-06)

Simplifies a polygon by deleting colinear points. The tolerance for detecting colinearity of points can optionally be specified.

layermesh.geometry.sub_rectangles(rect)

Returns the sub-rectangles formed by subdividing the given rectangle evenly in four.

layermesh.geometry.vector_heading(p)

Returns heading angle of a point p (tuple, list or array of length 2), in radians clockwise from the y-axis (‘north’).