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.

Parameters
angle() → float[source]

Get the angle of this line.

bounding_box() → Tuple[mpu.geometry.Point, mpu.geometry.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) → Union[None, mpu.geometry.LineSegment, mpu.geometry.Point][source]

Get the intersection between this LineSegment and another LineSegment.

Parameters

other (LineSegment) –

Returns

intersection

Return type

Union[None, LineSegment, Point]

is_point()[source]

Check if this LineSegment is a point.

length() → float[source]

Get the length of this line segment.

simplify()[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) –

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[mpu.geometry.Point, mpu.geometry.Point], b: Tuple[mpu.geometry.Point, mpu.geometry.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[mpu.geometry.LineSegment]) → Set[FrozenSet[mpu.geometry.LineSegment]][source]

Get all interectionLines by applying a brute force algorithm.

Parameters

lines (all lines you want to check, in no order) –

Returns

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.