intersection_line_line

compas.geometry.intersection_line_line(l1, l2, tol=None)[source]

Computes the intersection of two lines.

Parameters:
l1[point, point] | compas.geometry.Line

XYZ coordinates of two points defining the first line.

l2[point, point] | compas.geometry.Line

XYZ coordinates of two points defining the second line.

tolfloat, optional

Tolerance for evaluating the intersection points of each of the lines with the corresponding skew plane. Default is TOL.absolute.

Returns:
tuple[[float, float, float], [float, float, float]] | tuple[None, None]

Two intersection points. If the lines intersect, these two points are identical. If the lines are skewed and thus only have an apparent intersection, the two points are different. In all other cases there are no intersection points.

Examples

The 2 intersection points of intersecting lines are identical.

>>> l1 = [0, 0, 0], [1, 0, 0]
>>> l2 = [0, 0, 0], [0, 1, 0]
>>> intersection_line_line(l1, l2)
([0.0, 0.0, 0.0], [0.0, 0.0, 0.0])

Note that lines extend beyond their start and end points.

>>> l1 = [0, 0, 0], [1, 0, 0]
>>> l2 = [2, 0, 0], [0, 1, 0]
>>> intersection_line_line(l1, l2)
([2.0, 0.0, 0.0], [2.0, 0.0, 0.0])

Skew lines have two different intersection points.

>>> l1 = [0, 0, 0], [1, 0, 0]
>>> l2 = [0, 0, 1], [0, 1, 1]
>>> intersection_line_line(l1, l2)
([0.0, 0.0, 0.0], [0.0, 0.0, 1.0])

Parallel lines don’t intersect.

>>> l1 = [0, 0, 0], [1, 0, 0]
>>> l2 = [0, 0, 0], [1, 0, 0]
>>> intersection_line_line(l1, l2)
(None, None)