intersection_segment_polyline

compas.geometry.intersection_segment_polyline(segment, polyline, tol=1e-06)[source]

Calculate the intersection point of a segment and a polyline.

Parameters
  • segment ([point, point] | Line) – XYZ coordinates of two points defining a line segment.

  • polyline (sequence[point] | Polyline) – XYZ coordinates of the points of the polyline.

  • tol (float, optional) – The tolerance for intersection verification.

Returns

[float, float, float] | None – The intersection point or None if the segment does not intersect with any of the polyline segments.

Examples

>>> from compas.geometry import is_point_on_polyline
>>> from compas.geometry import is_point_on_segment
>>> from compas.geometry import distance_point_point
>>> from compas.geometry import centroid_points
>>> p = [(0.0, 0.0, 0.0), (1.0, 0.0, 0.5), (2.0, 0.5, 1.0)]
>>> s = [(0.5, 0.0, 0.0), (0.5, 0.0, 2.0)]
>>> x1, x2 = intersection_segment_polyline(s, p)
>>> x = centroid_points([x1, x2])
>>> is_point_on_polyline(x, p)
True
>>> is_point_on_segment(x, s)
True
>>> distance_point_point((0.5, 0.0, 0.25), x) < 1e-6
True