Converting between Graphics3D, SurfaceGraphcs, ContourGraphics, DensityGraphics, Graphics

The different type of Mathematica graphics include Graphics, Graphics3D, SurfaceGraphics, DensityGraphics, and ContourGraphics.  Mathematica allows one to easily make the following conversions on SurfaceGraphics, ContourGraphics, and DensityGraphics.

SurfaceGraphics[…] ⇒ DensityGraphics[…]
SurfaceGraphics[…] ⇒ ContourGraphics[…]
SurfaceGraphics[…] ⇒ Graphics3D[…]

ContourGraphics[…] ⇒ DensityGraphics[…]
ContourGraphics[…] ⇒ SurfaceGraphics[…]
ContourGraphics[…] ⇒ Graphics[…]

DensityGraphics[…] ⇒ ContourGraphics[…]
DensityGraphics[…] ⇒ SurfaceGraphics[…]
DensityGraphics[…] ⇒ Graphics[…]

To see how simple this is consider the next cell which makes a course DensityPlot, and displays the underlying expression for the graphic.  You will notice the underlying expression is simply the head DensityGraphics with a matrix of real numbers and a list of options.

DensityGraph = DensityPlot[Sin[x  y], {x, 0, 3}, {y, 0, 3}, PlotPoints->5] ; InputForm[DensityGraph]

In the next cell we simply evaluate SurfaceGraphics[DensityGraph]  to change the above DensityGraphic to SurfaceGraphics.  This cell also shows the SurfaceGraphics and returns the underlying expression of the SurfaceGraphics.  Notice to the underlying expression is very similar to the one for DensityGraph.  We only changed the head to SurfaceGraphics, and made some minor changes to the options. Switching between SurfaceGraphics, DensityGraphics, and ContourGraphics is trivial because the three type of graphics have the same underlying form.

SurfaceGraph = SurfaceGraphics[DensityGraph] ; Show[SurfaceGraph] ; InputForm[SurfaceGraph]

In the next cell we simply evaluate  Graphics3D[SurfaceGraph]  to change the above SurfaceGraphics to Graphics3D.  This cell also shows the SurfaceGraphics and returns the underlying expression of the Graphics3D.  The result we get back has the form Graphics3D[{primatives}, options].  While the graphic rendered below is the same we get from Show[SurfaceGraph], we could combine the Graphics3D primitives below with other primitives in ways that aren't possible with SurfaceGraphics.

Graph3Dim = Graphics3D[SurfaceGraph] ; Show[Graph3Dim] ; InputForm[Graph3Dim]

In the next cell we simply evaluate  Graphics[DensityGraph]  to change the above DensityGraphics to Graphics primitives.  This cell also shows the Graphics and returns the underlying expression.  The result we get back has the form Graphics[{primatives}, options].  While the graphic rendered below is the same we get from Show[DensityGraph], we could combine the Graphics primitives below with other primitives in ways that aren't possible with DensityGraphics.

gr = Graphics[DensityGraph] ; Show[gr] ; InputForm[gr]


Created by Mathematica  (May 16, 2004)

Back to Ted’s Tricks index page