Find the intersection of two lines: Difference between revisions

→‎{{header|Python}}: Describe approaches (proced/func) and mark library w header
m (→‎{{header|Python}}: Reorganize examples--native, internal lib, external lib)
(→‎{{header|Python}}: Describe approaches (proced/func) and mark library w header)
Line 1,356:
 
=={{header|Python}}==
Find the intersection procedurally, with no imports.
Simpler version
<lang python>def line_intersect(Ax1, Ay1, Ax2, Ay2, Bx1, By1, Bx2, By2):
""" returns a (x, y) tuple or None if there is no intersection """
Line 1,380:
{{Out}}
<pre>(5.0, 5.0)</pre>
Or, one approach to doing this by hand, without importing special libraries:
{{Works with|Python|3.7}}
Find the intersection using a functional approach, by importing [https://docs.python.org/3/library/functools.html functools.reduce]
<lang python>'''The intersection of two lines.'''
Line 1,497:
{{out}}
<pre>(5.0, 5.0)</pre>
{{libheader|Shapely}}
UsingFind the intersection by importing the external [https://shapely.readthedocs.io/en/latest/manual.html Shapely] library.
<lang python>from shapely.geometry import LineString