logo
Overview  Gallery  Introduction  Objects  Packages  Packages 3D  Basic Options  3D Options  Advanced 

4. Working with Graphics3D Packages

Standard

Mathematica provides built-in commands to render function graphs, parametrized surfaces and curves in 3D.

Function Graph

Graph of a scalar function on a rectangular domain. In[1]:= fg = Plot3D[y/6 Sin[x], {x, -Pi, Pi}, {y, 0., 6}]

In[2]:= JavaView[fg]


Compare with Mathematica

Parametrized Surfaces

Sphere in standard parametrization with meridians and parallels. In[1]:= gp = ParametricPlot3D[{Cos[u] Cos[v], Sin[u] Cos[v], Sin[v]}, {u, 0, 2Pi}, {v, -Pi/2, Pi/2}, PlotPoints -> {40, 10}];

In[2]:= JavaView[gp]


Compare with Mathematica

3D Curves

A closed curve in space. In[1]:= cv = ParametricPlot3D[{Cos[5t], Sin[3t], Sin[t]}, {t, 0, 2 Pi}];

In[2]:= JavaView[cv]


Compare with Mathematica

Graphics`ContourPlot3D`

Compute implicit surfaces as zero set of a function or of a scalar values given at vertices of a ZxZxZ grid.

Zero level of a function.

 

In[1]:= <<Graphics`ContourPlot3D`
In[2]:= gc = ContourPlot3D[ Cos[Sqrt[x^2 + y^2 + z^2]], {x, -2, 2}, {y, 0, 2}, {z, -2, 2}];

In[3]:= JavaView[gc]


Compare with Mathematica
Zero level of a regular scalar field in 3D. In[1]:= <<Graphics`ContourPlot3D`
In[2]:= data = Table[ x^2 + 2*y^2 + 3*z^2, {z, -1, 1, .25}, {y, -1, 1, .25}, {x, -1, 1, .25}];
In[3]:= gl = ListContourPlot3D[data, MeshRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, Lighting -> False, Contours -> {1.5, 3.}, Axes -> True, ContourStyle -> {{RGBColor[0, 1, 0]}, {RGBColor[1, 0, 0]}}]

In[4]:= JavaView[gl]


Compare with Mathematica

Graphics`Graphics3D`

Package supplies different representations of 3D data like bar chart and shadow plots.

Bar Charts

Display scalar values on a uv-mesh as vertical columns whose height represent the value.

This gives a bar chart made from a two-by-three array of bars with integer height. In[1]:= <<Graphics`Graphics3D`
In[2]:= gb = BarChart3D[{{1, 2, 3}, {4, 5, 6}}, BoxRatios -> Automatic];

In[3]:= JavaView[gb]


Compare with Mathematica

ScatterPlot3D

ScatterPlot3D[] shows a set of 3D points and thereby extends ListPlot to 3D. Optionally, the points may be connected by a line.

Here is a list of points in three dimensions. The scatter plot of points lies on a conical helix. In[1]:= <<Graphics`Graphics3D`
In[2]:= lpts = Table[{t Cos[t], t Sin[t], t}, {t, 0, 4Pi, Pi/20}];
In[3]:= sc = ScatterPlot3D[lpts]

In[4]:= JavaView[sc]


Compare with Mathematica
Join the points of the same list with a thicker line. In[1]:= <<Graphics`Graphics3D`
In[2]:= lpts = Table[{t Cos[t], t Sin[t], t}, {t, 0, 4Pi, Pi/20}];
In[3]:= scl = ScatterPlot3D[lpts, PlotJoined -> True, PlotStyle -> Thickness[0.01]]

In[4]:= JavaView[scl]


Compare with Mathematica

ListSurfacePlot3D uses an array of points and generates the faces of a surface.

Take an array of points in three dimensions.

The array of points is used to generate vertices of a polygonal mesh. It creates a piece of a sphere.

In[1]:= <<Graphics`Graphics3D`
In[2]:= apts = Table[{Cos[t] Cos[u], Sin[t] Cos[u], Sin[u]}, {t, 0, Pi, Pi/5}, {u, 0, Pi/2, Pi/10}];
In[3]:= lsp = ListSurfacePlot3D[apts]

In[4]:= JavaView[lsp]


Compare with Mathematica

Shadow Plot

Draw shadows of a surface at its bounding box. ShadowPlot3D and ListShadowPlot3D work exactly like the built­in Plot3D and ListPlot3D, except shadows are drawn.

Plot a 2D shadow below a 3D surface. In[1]:= <<Graphics`Graphics3D`
In[2]:= sp = ShadowPlot3D[Sin[x y], {x, 0, 3}, {y, 0, 3}]

In[3]:= JavaView[sp]


Compare with Mathematica
ShadowPosition determines whether shadow is above or below. In[1]:= <<Graphics`Graphics3D`
In[2]:= st = ShadowPlot3D[Exp[-(x^2 + y^2)], {x, -2, 2}, {y, -2, 2}, ShadowPosition -> 1]

In[3]:= JavaView[st]


Compare with Mathematica
Plot shadows at the bounding box of a 3D surface. In[1]:= <<Graphics`Graphics3D`
In[2]:= dbell = ParametricPlot3D[{Sin[t], Sin[2t] Sin[u], Sin[2t] Cos[u]}, {t, -Pi/2, Pi/2}, {u, 0, 2Pi}, Ticks -> None];
In[3]:= sa := Shadow[dbell, ZShadow -> False];

In[4]:= JavaView[sa]


Compare with Mathematica

Graphics`ParametricPlot3D`

The command ParametricPlot3D[] in this package expands the built-in command by allowing du and dv increments to be specified.

Determine number of lines through du and dv instead of PlotPoints. In[1]:= <<Graphics`ParametricPlot3D`
In[2]:= gps = ParametricPlot3D[{Cos[u] Cos[v], Sin[u] Cos[v], Sin[v]}, {u, 0, 2Pi, Pi/20}, {v, -Pi/2, Pi/2, Pi/10}];

In[3]:= JavaView[gps]


Compare with Mathematica
Only a collection of points is shown when you use PointParametricPlot3D. In[1]:= <<Graphics`ParametricPlot3D`
In[2]:= gpp = PointParametricPlot3D[{Cos[u] Cos[v], Sin[u] Cos[v], Sin[v]}, {u, 0, 2Pi}, {v, -Pi/2, Pi/2}];

In[3]:= JavaView[gpp]


Compare with Mathematica

Graphics`PlotField3D`

Creates and renders vector fields in 3D.

A 3D vortex vector field. In[1]:= <<Graphics`PlotField3D`
In[2]:= gv3 = PlotVectorField3D[{y, -x, 0}/z, {x, -1, 1}, {y, -1, 1}, {z, 1, 3}]

In[3]:= JavaView[gv3]


Compare with Mathematica
The same vector field with VectorHeads. In[1]:= <<Graphics`PlotField3D`
In[2]:= gv3h = PlotVectorField3D[{y, -x, 0}/z, {x, -1, 1}, {y, -1, 1}, {z, 1, 3}, VectorHeads -> True]

In[3]:= JavaView[gv3h]


Compare with Mathematica

Graphics`Polyhedra`

This package contains a collection of Platonic solids and commands for their modification like Stellate[] and Truncate[].

Load package Graphics`Polyhedra and display a dodecahedron in a JavaView display. In[1]:= <<Graphics`Polyhedra`
In[2]:= dode = Graphics3D[Dodecahedron[]];

In[3]:= JavaView[dode]


Compare with Mathematica
Truncate the dodecahedron. In[1]:= tg = Truncate[dode];

In[2]:= JavaView[tg]


Compare with Mathematica
Stellate the remainder. In[1]:= ts = Stellate[tg];

In[2]:= JavaView[ts]


Compare with Mathematica

Graphics`Shapes`

A collection of primitive surfaces including sphere, torus, Mbius band etc. is provided by this package.

Combine two shapes and position them in a scene.

JavaView accepts a list of geometries.

In[1]:= << Graphics`Shapes`
In[2]:=
g1 = TranslateShape[Graphics3D[Torus[]], {1., 0., 0.}];
In[3]:= g2 = RotateShape[Graphics3D[MoebiusStrip[1., 0.2, 30]], Pi/2., Pi/2., 0.];

In[4]:= JavaView[{g1,g2}]


Compare with Mathematica

Graphics`SurfaceOfRevolution`

This package simplifies the task to generate a surface of revolution from a planar (or non-planar) curve by rotation around the default z-axis, or about a user specified rotation axis.

The curve Sin[x] is rotated around the z-axis with an offset. In[1]:= << Graphics`SurfaceOfRevolution`
In[2]:= g = SurfaceOfRevolution[{1.2 + Sin[x], x}, {x, 0, 2Pi}];

In[3]:= JavaView[g]


Compare with Mathematica

The Pseudosphere is obtained by rotating a tractix around the z-axis.

Rotate the tractrix {f[x],g[x]} around the z-axis. In[1]:= << Graphics`SurfaceOfRevolution`
In[2]:= gPsd = SurfaceOfRevolution[{ Exp[-Abs[x]], -Sign[x](Sqrt[1 - Exp[-2 Abs[x]]] - Log[(1 + Sqrt[1 - Exp[-2 Abs[x]]])/Exp[-Abs[x]]])}, {x, -2., 2.}]

In[3]:= JavaView[gPsd]


Compare with Mathematica
© 1997-2017 Last modified: 22.06.2017 --- www.javaview.de --- The JavaView Project