 Three-Dimensional Mathematica Graphics (Section 4.3)

# Three-Dimensional Mathematica Graphics (Section 4.3)

### Extract from Mathematica Graphics: An Intensive Tutorial

#### by Tom Wickham-Jones

This HTML document is based on Mathematica Graphics: An Intensive Tutorial by Tom Wickham-Jones. It was adapted by Martin Kraus for non-commercial use.

All other product names mentioned are trademarks of their producers.

Copyright 1992 by Wolfram Research, Inc.

All rights reserved. No part of this document may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior written permission of the copyright holder.

## 4.3 Combining and Converting Images

There are a number of ways to combine and convert images which are possible.

 Prolog, Epilog include Graphics primitives Plot, ParametricPlot, ParametricPlot3D combine plots of several functions Graphics3D[ obj ] convert to Graphics3D object Graphics[ obj ] convert to Graphics object Show[ obj1 , obj2 , ... ] convert and combine several objects
Ways to combine and convert Mathematica images.

### Plotting several functions

The function plotting commands Plot, ParametricPlot and ParametricPlot3D all allow more than one function to be plotted.

 The Evaluate command is necessary since ParametricPlot3D is HoldAll. In:= ParametricPlot3D[Evaluate[Table[{Cos[x], Sin[x], n x}, {n, 5}]], {x, 0, 2 Pi}, BoxRatios -> {1, 1, 1}] Out= - Graphics3D -

### Show

 To combine existing images we can just use Show. In:= Graphics3D[Line[{{0, 0, 0}, {0, 0, 40}}]] Out= - Graphics3D - In:= Show[%%, %] Out= - Graphics3D -

There are also methods to convert graphics of one type to another. One of the most common is the conversion of SurfaceGraphics to Graphics3D. This is useful since Graphics3D primitives can intersect and generally represent more complex shapes than SurfaceGraphics.

 This makes a SurfaceGraphics object. In:= plot1 = Plot3D[x^2 - y^2, {x, -1, 1}, {y, -1, 1}, BoxRatios -> {1, 1, 2}, PlotPoints -> 10, DisplayFunction -> Identity] Out= - SurfaceGraphics - This converts it to Graphics3D. In:= Show[Graphics3D[plot1], DisplayFunction -> \$DisplayFunction] Out= - Graphics3D - This makes another SurfaceGraphics object. In:= plot2 = Plot3D[y^2 - x^2, {x, -1, 1}, {y, -1, 1}, BoxRatios -> {1, 1, 2}, PlotPoints -> 10, DisplayFunction -> Identity] Out= - SurfaceGraphics - The convertion to Graphics3D happens automatically. In:= Show[plot1, plot2, DisplayFunction -> \$DisplayFunction] Out= - Graphics3D -

With this ability to combine objects one can build up complex pictures by making use of built-in commands to build individual components. It is always good to use the tools provided by a computer system as much as possible. As an example we will put a vector field on the surface of a sphere.

 This generates a sphere. The setting of PlotPoints is crucial in this case. In:= sphere = ParametricPlot3D[{Cos[p] Sin[t], Sin[p] Sin[t], Cos[t]}, {p, 0., 2 Pi}, {t, 0., Pi}, PlotPoints -> {12 + 1, 8 + 1}, DisplayFunction -> Identity] Out= - Graphics3D - This produces a list of pairs of starting points and corresponding vectors. In:= vecs = Flatten[Table[{{Cos[p] Sin[t], Sin[p] Sin[t], Cos[t]}, 0.3 {Cos[p] Sin[t], Sin[p] Sin[t], Cos[t]} + {0.2, 0, 0}}, {p, 0., 2 Pi, 2 Pi / 12}, {t, 0., Pi, Pi / 8}], 1]; To show the vectors I will use the package Graphics`PlotField3D`. In:= <