Function Repository Resource:

NinePointCubic

Source Notebook

Find a cubic plane curve that passes through nine given 2D points

Contributed by: Ed Pegg Jr

ResourceFunction["NinePointCubic"][pts,{x,y}]

returns the implicit Cartesian equation in the variables x and y of the cubic plane curve that goes through the points pts.

ResourceFunction["NinePointCubic"][pts]

uses the formal variables x and y.

Examples

Basic Examples (2) 

Find a cubic plane curve through nine points:

In[1]:=
BlockRandom[SeedRandom[1];
  p9 = RandomSample[Tuples[Range[-2, 2], {2}], 9]];
cubic = ResourceFunction["NinePointCubic"][p9, {x, y}]
Out[2]=

Show the cubic and points:

In[3]:=
ContourPlot[cubic == 0, {x, -4, 4}, {y, -4, 4}, Epilog -> {Directive[
AbsolutePointSize[5], 
RGBColor[0.922526, 0.385626, 0.209179]], Point[p9]}]
Out[3]=

Scope (2) 

Find a cubic equation through nine points:

In[4]:=
BlockRandom[SeedRandom[3];
  p9 = RandomSample[Tuples[Range[-2, 2], {2}], 9]];
cubic = ResourceFunction["NinePointCubic"][p9, {x, y}]
Out[5]=

Show the cubic and points:

In[6]:=
ContourPlot[cubic == 0, {x, -4, 4}, {y, -4, 4}, Epilog -> {Directive[
AbsolutePointSize[5], 
RGBColor[0.922526, 0.385626, 0.209179]], Point[p9]}]
Out[6]=

Use formal variables:

In[7]:=
ResourceFunction["NinePointCubic"][p9]
Out[7]=

Find a cubic through nine points:

In[8]:=
p9 = Partition[RealDigits[N[1/19, 18]][[1]], 2];
cubic = ResourceFunction["NinePointCubic"][p9, {x, y}]
Out[9]=

The cubic is factorizable and thus degenerate, and is composed of an ellipse and a line:

In[10]:=
ContourPlot[cubic == 0, {x, -1, 10}, {y, 0, 9}, Epilog -> {Directive[
AbsolutePointSize[5], 
RGBColor[0.922526, 0.385626, 0.209179]], Point[p9]}]
Out[10]=

Neat Examples (2) 

Some points and a cubic curve:

In[11]:=
points = {{0, 0}, {6, -6}, {-6, 6}, {-2, -6}, {2, 6}, {6, 6}, {-6, -6}, {-6, 0}, {6, 0}, {0, 3}, {0, -3}};
cubic = ResourceFunction["NinePointCubic"][
  RandomSample[points, 9], {x, y}]
Out[12]=

Any line going through two points of a cubic will meet one of three criteria: 1. it will go through a third point (gray),
2. it will be tangent at one of the points (red), or
3. it will be parallel with the cubics' asymptote (green), also called a point at infinity:

In[13]:=
lines = ResourceFunction["FindExtraordinaryLines"][points];
linesinf = {{2, 10}, {3, 11}, {4, 8}, {5, 9}};
curve = ContourPlot[cubic == 0, {x, -9, 9}, {y, -9, 9}, ContourStyle -> Thickness[.02]][[1]];
ordinary = {{2, 5}, {3, 4}, {4, 9}, {4, 10}, {5, 8}, {5, 11}};
Graphics[{curve, EdgeForm[Thick], Gray, Line[points[[#]]] & /@ lines, Thick,
  Green, InfiniteLine[points[[#]]] & /@ linesinf,
  Red, InfiniteLine[points[[#]]] & /@ ordinary,
  {White, Disk[#, .2]} & /@ points}]
Out[17]=

Version History

  • 1.0.0 – 26 July 2022

Related Resources

License Information