Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Find the intersection of two lines
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"][{{a,b},{c,d}}] returns the intersection of the infinite lines through points a to b and points c to d. |
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]= | ![]() |
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]= | ![]() |
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]= | ![]() |
Wolfram Language 12.3 (May 2021) or above
This work is licensed under a Creative Commons Attribution 4.0 International License