skspatial.objects.Line.distance_line

Line.distance_line(other: skspatial.objects.line.Line) numpy.float64[source]

Return the shortest distance from the line to another.

Parameters
otherLine

Other line.

Returns
np.float64

Distance between the lines.

References

http://mathworld.wolfram.com/Line-LineDistance.html

Examples

There are three cases:

  1. The lines intersect (i.e., they are coplanar and not parallel).

>>> from skspatial.objects import Line
>>> line_a = Line([1, 2], [4, 3])
>>> line_b = Line([-4, 1], [7, 23])
>>> line_a.distance_line(line_b)
0.0
  1. The lines are parallel.

>>> line_a = Line([0, 0], [1, 0])
>>> line_b = Line([0, 5], [-1, 0])
>>> line_a.distance_line(line_b)
5.0
  1. The lines are skew.

>>> line_a = Line([0, 0, 0], [1, 0, 1])
>>> line_b = Line([1, 0, 0], [1, 1, 1])
>>> line_a.distance_line(line_b).round(3)
0.707