Function Repository Resource:

# LineIntersection

Find the intersection of two lines

Contributed by: Ed Pegg Jr and Jan Mangaldan
 ResourceFunction["LineIntersection"][{a,b},{c,d}] returns the intersection of the infinite lines through points a to b and points c to d. ResourceFunction["LineIntersection"][Line[{a,b}],Line[{c,d}]] returns the intersection of the infinite lines through points a to b and points c to d. ResourceFunction["LineIntersection"][{{a,b},{c,d}}] returns the intersection of the infinite lines through points a to b and points c to d.

## Details

ResourceFunction["LineIntersection"] also supports 3D intersections.

## Examples

### Basic Examples (4)

Fine a line intersection:

 In[1]:=
 Out[3]=

Show it:

 In[4]:=
 Out[4]=

Line may be used:

 In[5]:=
 Out[5]=

A list of two lines may be used:

 In[6]:=
 Out[6]=

### Scope (4)

Find the intersection of two infinite lines:

 In[7]:=
 Out[7]=

Two lines in 3D:

 In[8]:=

Find their intersection:

 In[9]:=
 Out[9]=

Show the lines and the intersection point:

 In[10]:=
 Out[10]=

Ten thousand line pairs:

 In[11]:=

Find the intersections and get timing:

 In[12]:=
 Out[12]=

In the documentation for InfiniteLine, the following method is used:

 In[13]:=

That method is slower:

 In[14]:=
 Out[14]=

RegionIntersection may also be used:

 In[15]:=

That method is also slower:

 In[16]:=
 Out[16]=

All three methods give the same results:

 In[17]:=
 Out[17]=

Inexact values may be used:

 In[18]:=
 Out[20]=

### Possible Issues (3)

The lines are considered to be infinite lines, so the intersection point may not be on the defining segments:

 In[21]:=
 Out[23]=

Show it:

 In[24]:=
 Out[24]=

Degenerate lines will not return an intersection point:

 In[25]:=
 Out[27]=

Parallel lines will not return an intersection point:

 In[28]:=
 Out[30]=

## Requirements

Wolfram Language 12.3 (May 2021) or above

## Version History

• 1.0.1 – 29 November 2023
• 1.0.0 – 14 June 2022