A Conic Through Five Given Points

A "pedestrian" version

x=RandomReal[{-5,5},{5}]

y=RandomReal[{-5,5},{5}]

x^2

x y

Clear[a,b,c,d,e]
a x^2 + b x y +c y^2+d x +e y==1
sol=Solve[a x^2 + b x y +c y^2+d x +e y==1]
sol=Flatten[sol]

a=sol[[1,2]]
b=sol[[2,2]]
c=sol[[3,2]]
d=sol[[4,2]]
e=e/.sol

pts=Transpose[{x,y}]

ContourPlot[a x^2+b x y +c y^2+d x+e y==1,{x,-10,10},{y,-10,10},Epilog->{AbsolutePointSize[6],Red,Point[pts]},PlotPoints->50]

The “pedestrian” version as a module

Conic2[pts_]:=Module[{a,b,c,d,e,x=pts[[All,1]],y=pts[[All,2]]},sol=Flatten[Solve[a x^2 + b x y +c y^2+d x +e y==1]];{a,b,c,d,e}={a,b,c,d,e}/.sol;
ContourPlot[a s^2+b s t +c t^2+d s+e t-1==0,{s,-10,10},{t,-10,10},Epilog->{AbsolutePointSize[6],Red,Point[pts]},PlotPoints->50,ImageSize->600]]

pts=RandomReal[{-5,5},{5,2}]

Conic2[pts]

Displaying the equation as well:

Conic3[pts_]:=Module[{eqn,a,b,c,d,e,x=pts[[All,1]],y=pts[[All,2]]},sol=Flatten[Solve[a x^2 + b x y +c y^2+d x +e y==1]];{a,b,c,d,e}={a,b,c,d,e}/.sol;eqn=a s^2+b s t +c t^2+d s+e t-1;
ContourPlot[eqn==0,{s,-10,10},{t,-10,10},Epilog->{AbsolutePointSize[6],Red,Point[pts]},PlotPoints->50,PlotLabel->Row[{eqn," = 0"}],Axes->True,Frame->False,AxesLabel->{s,t},ImageSize->600,BaseStyle->{Bold,12}]]

Conic3[pts]

A fancy version by Ed Pegg Jr and Paul Abbott

Source: http : // demonstrations.wolfram.com/FivePointsDetermineAConicSection/

This code uses the fact that the equation of the conic section can be found by setting the following determinant equal to zero:

The next command produces the conic section:

makeRow[{x_,y_}]:={(x^2),x y,(y^2),x,y,1}
conicsection=Det[makeRow/@Join[{{s,t}},pts]]

Plugging in the 5 points yields 0 :

conicsection/.{s->pts[[All,1]],t->pts[[All,2]]}
Chop[%]

Here is the Pegg/Abbott code:

Clear[x,y];
makeRow[{x_,y_}]:={(x^2),x y,(y^2),x,y,1}
Conic[x_,y_][pts_]:=Det[makeRow/@Join[{{x,y}},pts]]

Manipulate[
ContourPlot[Evaluate[Thread[Conic[x,y]/@Subsets[r,{5}]==0]],{x,-2,2},{y,-2,2},PlotPoints->50,ImageSize->{600,490}],
{{r,RandomReal[{-1,1},{5,2}]},{-2,-2},{2,2},Locator,LocatorAutoCreate->{5,6}},SaveDefinitions-> True]