# 3D visualization in Mathematica

We have discussed in the last lecture and lab 2 dimensional graphics. Now let's do a bit of 3D graphics.

## 3D functions

For plotting functions in 3D, you can use:

```Plot3D[f, {x, xmin, xmax}, {y, ymin, ymax}] generates a three-dimensional \ plot of f as a function of x and y. Plot3D[{f, s}, {x, xmin, xmax}, {y, ymin, \ ymax}] generates a three-dimensional plot in which the height of the surface \ is specified by f, and the shading is specified by s.```
For example, look at the surface of the function Sin[x y]:
`Plot3D[Sin[x y], {x, 0, 1/2}, {y, 0, 6}];`

Table[]. Let's have a look at how George explains this command.
So now we can use ot to make a series of plots by iterating on the variables inside the Plot3D command:
```Table[ Plot3D[Sin[x y], {x, 0, t/2}, {y, 0, t}], {t, 1, 6, 3/4} ];```

## 3D data

For plotting data, you have to get a bit fancier.
The standard Mathematica packages can only plot regularly spaced 3D data. That is not so interesting in lots of geological examples, such as topographic mapping.
Follow these steps to get 3D:

### Load Extended graphics packages

We need to get some special packages from Tom Wickham-Jones book, Mathematica Graphics, in order to do what we want. The packages were actually loaded as part of the GLG416 Field Geophysics class.

#### Connect to the glg416 folder on the Information Technology zone, IT instructional server

Chooser-> Appleshare -> Information Technology -> IT Instructional
user: glg416 (all lower case!)
password: glg416
That will connect us to that server. We won't need to do anything else with it.

#### AppendPath

Now in your Mathematica notebook, we need to tell Mathematica where to look for things, so copy these commands and paste them into your notebook:
```AppendTo[\$Path, "Instructor Volumes:GLG416:TWJ_Packages"]```

#### Load specific packages

Copy these commands and paste them into your notebook:
Needs["ExtendGraphics`SurfaceGraphics3D`"]
Needs["ExtendGraphics`TriangularInterpolate`"]

### Prepare a list of topography (or other scattered 3D data that you ant to see as a surface)

Given this list of data, get it into the list format that Mathematica wants:
```data = { {x1, y1, z1}, {x2, y2, z2}, .... {xn, yn, zn} }``` where n is the number of points.

The trick is to go into Micorsoft Word with the data (just copy it), and select Replace under the Edit menu. Type this:
Find: ^p
Replace all with: },^p{
What that will do is take the end of line and add in the curly brackets that we need to define the list. We will jsut have to tidy up the beginning and the end to get it in the right format. Copy the replaced list into Mathematica and push enter to define the list.
Now we are ready.

### Plot it!

Copy this and paste it into your Mathematica document:
topoplot = Graphics3D[
ListSurfacePlot3D[topography, Mesh->False, Axes->True,
AxesLabel->{"Easting (m)", "Northing (m)", "Elevation (m)"},
AspectRatio->Automatic,
ViewPoint->{1.3, -2.4, 2}]
];
The important thing to recognize is how the ViewPoint assignments work:
```"ViewPoint is an option for Graphics3D and SurfaceGraphics which gives the \ point in space from which the objects plotted are to be viewed."``` Note that the numbers scale roughly as the longest half axis length is equal to 1.
Feel free to change the position of the viewpoint.

## Getting graphics out of Mathematica

Assignment 10

Pages maintained by
Prof. Ramón Arrowsmith
Last modified December 5, 1997