Aller au contenu principal

raygeo.geo.shape.line

Line segment geometry queries.

Provides line-line intersection (infinite lines), line-segment intersection, closest point on a line or segment to a given point, line-segment-vs-polygon intersections, point-on-segment tests, point-in-rectangle tests, rectangle containment checks, and angle-at-vertex computation.

Functions

does_line_segment_intersect_circle()

does_line_segment_intersect_circle(p1: Point, p2: Point, circle_center: Point, circle_radius: float) -> bool

Check if a line segment intersects a circle.

Returns: True if the segment intersects the circle.

ParameterTypeDescription
p1PointStart of the line segment.
p2PointEnd of the line segment.
circle_centerPointCircle center (x, y).
circle_radiusfloatCircle radius.
Returnsbool

does_line_segment_intersect_rect()

does_line_segment_intersect_rect(p1: Point, p2: Point, rect: Rect) -> bool

Check if a line segment intersects a rectangle.

Returns: True if the segment intersects the rectangle.

ParameterTypeDescription
p1PointStart of the line segment.
p2PointEnd of the line segment.
rectRectRectangle (x_min, y_min, x_max, y_max).
Returnsbool

get_angle_at_vertex()

get_angle_at_vertex(p0: Point, p1: Point, p2: Point) -> float

Get the angle at a vertex between three points.

Returns: Angle in radians.

ParameterTypeDescription
p0PointFirst point.
p1PointVertex point.
p2PointThird point.
Returnsfloat

get_line_closest_point()

get_line_closest_point(line_p1: Point, line_p2: Point, x: float, y: float) -> Point

Get the closest point on a line to a given point.

Returns: Closest point (x, y) on the line.

ParameterTypeDescription
line_p1PointFirst point on the line.
line_p2PointSecond point on the line.
xfloatX coordinate of target point.
yfloatY coordinate of target point.
ReturnsPoint

get_line_line_intersection()

get_line_line_intersection(p1: Point, p2: Point, p3: Point, p4: Point) -> Optional[Point]

Get the intersection of two infinite lines.

Returns: Intersection point (x, y) or None.

ParameterTypeDescription
p1PointFirst point on line 1.
p2PointSecond point on line 1.
p3PointFirst point on line 2.
p4PointSecond point on line 2.
ReturnsOptional[Point]

get_line_segment_closest_point()

get_line_segment_closest_point(seg_p1: Point, seg_p2: Point, x: float, y: float) -> tuple[float, Point, float]

Get closest point on a line segment to a point.

Returns: Tuple of (parameter, closest_point, distance).

ParameterTypeDescription
seg_p1PointStart of the line segment.
seg_p2PointEnd of the line segment.
xfloatX coordinate of target point.
yfloatY coordinate of target point.
Returnstuple[float, Point, float]

get_line_segment_intersection()

get_line_segment_intersection(p1: Point, p2: Point, p3: Point, p4: Point) -> Optional[Point]

Get the intersection of two line segments.

Returns: Intersection point (x, y) or None.

ParameterTypeDescription
p1PointStart of segment 1.
p2PointEnd of segment 1.
p3PointStart of segment 2.
p4PointEnd of segment 2.
ReturnsOptional[Point]

get_line_segment_polygon_intersections()

get_line_segment_polygon_intersections(p1: Point, p2: Point, polygon: list[Polygon]) -> list[float]

Get t-values of line segment-polygon intersections.

Returns: List of t-values where the segment intersects.

ParameterTypeDescription
p1PointStart of the line segment.
p2PointEnd of the line segment.
polygonlist[Polygon]Polygon(s) to test against.
Returnslist[float]

get_point_line_distance()

get_point_line_distance(point: Point, line_p1: Point, line_p2: Point) -> float

Get the distance from a point to a line.

Returns: Perpendicular distance.

ParameterTypeDescription
pointPointPoint (x, y).
line_p1PointFirst point on the line.
line_p2PointSecond point on the line.
Returnsfloat

is_point_on_line_segment()

is_point_on_line_segment(point: Point, seg_p1: Point, seg_p2: Point) -> bool

Check if a point is on a line segment.

Returns: True if the point lies on the segment.

ParameterTypeDescription
pointPointPoint (x, y) to test.
seg_p1PointStart of the line segment.
seg_p2PointEnd of the line segment.
Returnsbool