Function Repository Resource:

FivePointConic

Source Notebook

Find a conic equation that passes through five given points

Contributed by: Ed Pegg Jr

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

returns the implicit Cartesian equation in the variables x and y of the conic section that goes through the points pts.

ResourceFunction["FivePointConic"][pts]

uses the formal variables x and y.

Details

For random, uniformly-distributed points in a rectangle, the probability of a hyperbola is and the probability of an ellipse is .

Examples

Basic Examples (2) 

Find a conic section through five points:

In[1]:=
p5 = {{1, 4}, {4, 2}, {2, 8}, {8, 5}, {5, 7}};
conic = ResourceFunction["FivePointConic"][p5, {x, y}]
Out[2]=

Show the conic and points:

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

Scope (7) 

Use formal variables:

In[4]:=
ResourceFunction[
 "FivePointConic"][{{1, 4}, {4, 2}, {2, 8}, {8, 5}, {5, 7}}]
Out[4]=

The results of a five point conic are usually a hyperbola:

In[5]:=
points = {{-2, 1}, {-1, -2}, {1, -2}, {2, 1}, {0, 0}};
conic = ResourceFunction["FivePointConic"][points, {x, y}];
curve = ContourPlot[conic == 0, {x, -3, 3}, {y, -4, 4}][[1]];
Labeled[Graphics[{curve, {Directive[
AbsolutePointSize[5], 
RGBColor[0.922526, 0.385626, 0.209179]], Point[points]}}, ImageSize -> Small], conic]
Out[8]=

A random five point conic is also frequently an ellipse:

In[9]:=
points = {{-2, 1}, {-1, -2}, {1, -2}, {2, 1}, {0, 2}};
conic = ResourceFunction["FivePointConic"][points, {x, y}];
curve = ContourPlot[conic == 0, {x, -3, 3}, {y, -4, 4}][[1]];
Labeled[Graphics[{curve, {Directive[
AbsolutePointSize[5], 
RGBColor[0.922526, 0.385626, 0.209179]], Point[points]}}, ImageSize -> Small], conic]
Out[12]=

A circle can also be the result of a five point conic:

In[13]:=
points = {{-2, 1}, {-1, -2}, {1, -2}, {2, 1}, {1, 2}};
conic = ResourceFunction["FivePointConic"][points, {x, y}];
curve = ContourPlot[conic == 0, {x, -3, 3}, {y, -4, 4}][[1]];
Labeled[Graphics[{curve, {Directive[
AbsolutePointSize[5], 
RGBColor[0.922526, 0.385626, 0.209179]], Point[points]}}, ImageSize -> Small], conic]
Out[16]=

A parabola may also appear:

In[17]:=
points = {{-2, 1}, {-1, -2}, {1, -2}, {2, 1}, {0, -3}};
conic = ResourceFunction["FivePointConic"][points, {x, y}];
curve = ContourPlot[conic == 0, {x, -3, 3}, {y, -4, 4}][[1]];
Labeled[Graphics[{curve, {Directive[
AbsolutePointSize[5], 
RGBColor[0.922526, 0.385626, 0.209179]], Point[points]}}, ImageSize -> Small], conic]
Out[20]=

Degenerate conics are also possible:

In[21]:=
points = {{-2, 1}, {-1, -2}, {1, -2}, {2, 1}, {0, -1}};
conic = ResourceFunction["FivePointConic"][points, {x, y}];
curve = ContourPlot[conic == 0, {x, -3, 3}, {y, -4, 4}][[1]];
Labeled[Graphics[{curve, {Directive[
AbsolutePointSize[5], 
RGBColor[0.922526, 0.385626, 0.209179]], Point[points]}}, ImageSize -> Small], conic]
Out[24]=

See the properties of the non-degenerate conics with the resource function ConicProperties:

In[25]:=
base = {{-2, 1}, {-1, -2}, {1, -2}, {2, 1}};
last = {{0, 0}, {0, 2}, {0, -3}, {1, 2}};
ResourceFunction["ConicProperties"][
   ResourceFunction["FivePointConic"][Append[base, #]] == 0, {\[FormalX], \[FormalY]}] & /@ last
Out[26]=

Neat Examples (5) 

A function for characterizing a conic section:

In[27]:=
CharacterizeConic[poly_] := Module[{\[FormalCapitalA], \[FormalCapitalB], \[FormalCapitalC], \[FormalCapitalD], \[FormalCapitalE], \[FormalCapitalF], discriminant,
    coeff},
  If[Length[FactorList[poly]] > 2 || NumericQ[poly], Return["D" (*degenerate*)]];
  coeff = Flatten[CoefficientList[poly, {\[FormalX], \[FormalY]}, {3, 3}]];
  {\[FormalCapitalA], \[FormalCapitalB], \[FormalCapitalC], \[FormalCapitalD], \[FormalCapitalE], \[FormalCapitalF]} = coeff[[{7, 5, 3, 4, 2, 1}]]; discriminant = \[FormalCapitalB]^2 - 4 \[FormalCapitalA] \[FormalCapitalC];
  Which[
   \[FormalCapitalB] == 0 && \[FormalCapitalA] == \[FormalCapitalC], "C" (*circle*),
   discriminant == 0, "P" (*parabola*),
   discriminant < 0, "E" (*ellipse*),
   discriminant > 0, "H" (*hyperbola*),
   True, "D" (*degenerate*)
   ]]

A sample conic section:

In[28]:=
SeedRandom[2];
r5 = RandomInteger[{-10, 10}, {5, 2}];
poly = ResourceFunction["FivePointConic"][r5]
Out[29]=

The above polynomial defines a hyperbola:

In[30]:=
CharacterizeConic[poly]
Out[30]=

Degenerate conics appear frequently when selecting from a limited lattice:

In[31]:=
SeedRandom[1];
pols = Table[
   ResourceFunction["FivePointConic"][
    RandomInteger[{-4, 4}, {5, 2}]], {5000}];
SortBy[Tally[CharacterizeConic /@ pols], -Last[#] &]
Out[32]=

For random real-valued points, the result is always a hyperbola or ellipse:

In[33]:=
SeedRandom[1];
pols = Table[
   ResourceFunction["FivePointConic"][
    RandomReal[{-4, 4}, {5, 2}]], {5000}];
SortBy[Tally[CharacterizeConic /@ pols], -Last[#] &]
Out[34]=

Version History

  • 1.0.0 – 22 July 2022

Related Resources

License Information