Skip to main content

raygeo.geo.algo.intersect

Geometry intersection utilities.

Low-level intersection primitives for ray-segment and segment-segment tests, plus higher-level self-intersection and cross-intersection checks on geometry command arrays.

Functions

get_ray_line_intersection()

get_ray_line_intersection(
origin: tuple[float, float],
direction: tuple[float, float],
a: tuple[float, float],
b: tuple[float, float],
) -> tuple[float, float] | None

Intersect a ray with a line segment.

Given a ray starting at origin in the given direction, and a line segment from a to b, returns the intersection point if the ray hits the segment (including endpoints) in the forward direction, or None if there is no intersection.

ParameterTypeDescription
origintuple[float, float]Ray start point (x, y).
directiontuple[float, float]Ray direction vector (dx, dy).
atuple[float, float]Line segment start point (x, y).
btuple[float, float]Line segment end point (x, y).
Returnstuple[float, float] | NoneIntersection point (x, y), or None.
ComplexityO(1) time, O(1) space

Ray–line segment intersection: the ray from origin O hits segments S₁ and S₂ (marked), misses S₃

Ray–line segment intersection: the ray from origin O hits segments S₁ and S₂ (marked), misses S₃

get_ray_polygon_intersection()

get_ray_polygon_intersection(
origin: tuple[float, float],
direction: tuple[float, float],
polygon: list[tuple[float, float]],
) -> tuple[float, float] | None

Intersect a ray with a polygon boundary.

Given a ray starting at origin in the given direction, and a closed polygon defined by a list of vertices, returns the closest intersection point with any edge of the polygon (including edge endpoints), or None if the ray does not hit the polygon in the forward direction.

ParameterTypeDescription
origintuple[float, float]Ray start point (x, y).
directiontuple[float, float]Ray direction vector (dx, dy).
polygonlist[tuple[float, float]]List of polygon vertices [(x1, y1), (x2, y2), ...].
Returnstuple[float, float] | NoneClosest intersection point (x, y), or None.
ComplexityO(N) time, O(1) space

Ray–polygon intersection: the ray from origin O hits the polygon boundary at the closest intersection point along the ray direction.

Ray–polygon intersection: the ray from origin O hits the polygon boundary at the closest intersection point along the ray direction.