Function Repository Resource:

CollinearQ

Source Notebook

Determine whether a set of points lie on a line

Contributed by: Wolfram|Alpha Math Team

ResourceFunction["CollinearQ"][{list1,list2,}]

returns True if the set of points determined by the listi lie on a single line.

Details and Options

ResourceFunction["CollinearQ"] accepts numeric and symbolic arguments.

Examples

Basic Examples (2) 

Determine whether three points lie on a single line:

In[1]:=
ResourceFunction["CollinearQ"][{{1, 2}, {3, 4}, {4, 5}}]
Out[1]=
In[2]:=
Show[Plot[x + 1, {x, 0, 5}], ListPlot[{{1, 2}, {3, 4}, {4, 5}}, PlotMarkers -> Style["\[FilledCircle]", Red]]]
Out[2]=

A set of three points need not be colinear:

In[3]:=
ResourceFunction["CollinearQ"][{{1, 2}, {3, 4}, {4, 8}}]
Out[3]=
In[4]:=
ListLinePlot[{{1, 2}, {3, 4}, {4, 8}}, PlotMarkers -> Style["\[FilledCircle]", Red]]
Out[4]=

Scope (3) 

CollinearQ works in more than two dimensions:

In[5]:=
ResourceFunction["CollinearQ"][{{1, 2, 3}, {3, 4, 5}, {4, 8, 12}}]
Out[5]=

Three points in three dimensions on a line:

In[6]:=
ResourceFunction["CollinearQ"][{{1, 2, 3}, {3, 4, 5}, {4, 5, 6}}]
Out[6]=

CollinearQ works with symbolic input:

In[7]:=
ResourceFunction["CollinearQ"][{{a, b}, {2 a, 2 b}, {3 a, 3 b}}]
Out[7]=

Publisher

Wolfram|Alpha Math Team

Version History

  • 2.0.0 – 23 March 2023
  • 1.0.0 – 11 May 2020

Related Resources

Author Notes

To view the code:

In[1]:=
SystemOpen[
 FileNameJoin[{DirectoryName[FindFile["ResourceFunctionHelpers`"]], "CollinearQ.wl"}]]

License Information