Wolfram Research

Function Repository Resource:

QuadricPlot3D

Source Notebook

Plot a quadric surface, automatically determining the regions of interest, view direction and scaling

Contributed by: Daniel Lichtblau

ResourceFunction["QuadricPlot3D"][poly]

plots the quadric surface given by poly==0.

ResourceFunction["QuadricPlot3D"][poly1==poly2]

plots the quadric surface given by poly1==poly2.

ResourceFunction["QuadricPlot3D"][poly,"ShowCode"]

returns the code used to create the plot, wrapped in Hold.

Examples

Basic Examples

A hyperboloid of one sheet:

In[1]:=
ResourceFunction["QuadricPlot3D"][z^2 - (x^2 + 3 y^2) + 3]
Out[1]=

A hyperboloid of two sheets, entered in equation form:

In[2]:=
ResourceFunction["QuadricPlot3D"][x^2 - 2 y^2 - z^2 == 8]
Out[2]=

Return the code used to create an ellipsoid plot:

In[3]:=
ellipsoid = ResourceFunction["QuadricPlot3D"][x^2/10 + y^2 + z^2 - 40, "ShowCode"]
Out[3]=

Now deploy that code:

In[4]:=
Release[ellipsoid]
Out[4]=

Plot a paraboloid:

In[5]:=
ResourceFunction[
 "QuadricPlot3D"][(2 y + z) + 3*(x - y)^2 + 2 (x + z)^2 - 4]
Out[5]=

Scope

QuadricPlot3D handles degenerate quadrics.

Plot a cone:

In[6]:=
ResourceFunction["QuadricPlot3D"][x^2 - y^2 - 2 z^2]
Out[6]=

Plot a pair of intersecting planes:

In[7]:=
ResourceFunction["QuadricPlot3D"][-y + x y + z - x z]
Out[7]=

These are intersecting planes because the polynomial factors:

In[8]:=
-y + x y + z - x z // Factor
Out[8]=

Plot a parabolic cylinder:

In[9]:=
ResourceFunction[
 "QuadricPlot3D"][(x - 3 y + z)^2 - 2 (-2 x + y + 4 z)^2 + 8]
Out[9]=

Plot some “random” quadrics:

In[10]:=
randomQuadric[max_] := RandomReal[{-max, max}, 10].{x^2, x*y, x*z, y^2, y*z, z^2, x, y, z, 1}
In[11]:=
SeedRandom[11111];
rc = Table[randomQuadric[3], {5}];
In[12]:=
Map[ResourceFunction["QuadricPlot3D"], rc]
Out[12]=

Possible Issues

QuadricPlot3D will return unevaluated if the argument is not discernibly a polynomial of total degree 2 in three variables:

In[13]:=
ResourceFunction[
 "QuadricPlot3D"][-4 - 3*(-11 + Exp[x] - y^Pi)^2 + 2*y + z + 2*(x + z)^2]
Out[13]=

For some quadrics, e.g. “thin” hyperboloids of one sheet, QuadricPlot3D may show a view that obscures a part of the saddle:

In[14]:=
ResourceFunction[
 "QuadricPlot3D"][-4 - 3*(-11 + x - y)^2 + 2*y + z + 2*(x + z)^2]
Out[14]=

One can get different views simply by rotating using the mouse:

3D graphic objects can be large:

In[15]:=
qcode = ResourceFunction[
  "QuadricPlot3D"][-4 - 3*(-11 + x - y)^2 + 2*y + z + 2*(x + z)^2, "ShowCode"]
Out[15]=
In[16]:=
ByteCount[g1 = Release@qcode]
Out[16]=

One can reduce this considerably by rasterizing the 3D graphic object:

In[17]:=
ByteCount[g2 = Rasterize@g1]
Out[17]=

There is good fidelity in the rasterized image (though it can no longer be rotated):

In[18]:=
g1
Out[18]=
In[19]:=
g2
Out[19]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

License Information