mpu.geometry
Create and manipulate two-dimensional geometrical entities such as lines.
For more advanced use cases, see:
- class mpu.geometry.LineSegment(p1: mpu.geometry.Point, p2: mpu.geometry.Point, name: str = 'LineSegment')[source]
Bases:
object
A line segment a a 2-dimensional Euclidean space.
- bounding_box() tuple[Point, Point] [source]
Get the bounding box of this line represented by two points.
The p1 point is in the lower left corner, the p2 one at the upper right corner.
- intersect(other: LineSegment) None | LineSegment | Point [source]
Get the intersection between this LineSegment and another LineSegment.
- Parameters
other (LineSegment) –
- Returns
intersection
- Return type
None | LineSegment | Point
- simplify() Point | LineSegment [source]
Simplify this line segment to a point, if possible.
- class mpu.geometry.Point(x: float, y: float)[source]
Bases:
object
A point in a 2-dimensional Euclidean space.
- Parameters
x (float) –
y (float) –
- simplify() mpu.geometry.Point [source]
- mpu.geometry.crossproduct(a: mpu.geometry.Point, b: mpu.geometry.Point) float [source]
Get the cross product of two points.
- mpu.geometry.do_bounding_boxes_intersect(a: tuple[Point, Point], b: tuple[Point, Point]) bool [source]
Check if bounding boxes do intersect.
If one bounding box touches the other, they do intersect.
- mpu.geometry.do_lines_intersect(a: mpu.geometry.LineSegment, b: mpu.geometry.LineSegment) bool [source]
Check if LineSegments a and b intersect.
- mpu.geometry.get_all_intersecting_lines_by_brute_force(lines: list[LineSegment]) set[frozenset[LineSegment]] [source]
Get all intersecting lines by applying a brute force algorithm.
- Parameters
lines (all lines you want to check, in no order) –
- Returns
intersections
- Return type
a list that contains all pairs of intersecting lines
- mpu.geometry.is_point_on_line(a: mpu.geometry.LineSegment, b: mpu.geometry.Point) bool [source]
Check if point b is on LineSegment a.
- mpu.geometry.is_point_right_of_line(a: mpu.geometry.LineSegment, b: mpu.geometry.Point) bool [source]
Check if point b is right of line a.
- mpu.geometry.line_segment_touches_or_crosses_line(a: mpu.geometry.LineSegment, b: mpu.geometry.LineSegment) bool [source]
Check if line segment a touches or crosses line segment b.