3D Graphics Examples

Math 213 - Math with Mathematica
Christopher Hanusa

Overview

We will use the ideas from Tutorials 8 and 9 to attack some more complicated examples.

In these examples, you may find it useful to do a Google search for Quadric Surfaces to learn what sorts of canonical 2D surfaces there are in 3D.

ListSurfacePlot3D

When you have a large number of 3D points that you would like to connect, use ListSurfacePlot3D.

data=ExampleData[{"Geometry3D","StanfordBunny"},"VertexData"];

ListPointPlot3D[data]

ListSurfacePlot3D[data,MaxPlotPoints->50]

Comprehension Question

Create a dataset of 1000 points that are on the surface of a perfect cube by using RandomReal.  Use ListSurfacePlot3D to draw the cube.

BSplineSurface

If you have ((Subscript[x, i]),(Subscript[y, i]),(Subscript[z, i])) control points and you’d like a surface that is a smooth function z=f(x,y), then use BSplineSurface

cpts=Table[{i,j,RandomReal[{-1,1}]},{i,5},{j,5}];

b=Graphics3D[BSplineSurface[cpts]]

Show[Graphics3D[{PointSize[Medium],Red,Map[Point,cpts],Gray,Line[cpts],Line[Transpose[cpts]]}],b]

This is from the Wolfram Demonstration: “Designing a Car Body with Splines” available here:
http://demonstrations.wolfram.com/DesigningACarBodyWithSplines/

Manipulate[
Graphics3D[{
color,Specularity[White,50],
BSplineSurface[carbody,SplineDegree->Floor[degrees]],
If[mesh,
{Dashed,Blue,Line[carbody],Line[Transpose[carbody]],Red,PointSize[Medium],Point/@carbody},{}]},
Boxed->False,Lighting->"Neutral",RotationAction->"Clip",ViewPoint->{-2,-2,2}],
Row[{Control[{{degrees,{1,1}},{1,1},{14,7},ImageSize->{140,70}}],Dynamic[Floor[degrees]]},Spacer[10]],
Row[{Control[{color,ColorData["HTML","GoldenRod"]}],Control[{mesh,{False,True}}]},Spacer[10]],
Initialization:>(carbody={
{{-.2,-2.25,0},{-.2,-2.25,0},{-.2,-2,0},{-.2,0,0},{-.2,2,0},{-.2,2.25,0},{-.2,2.25,0}},
{{0,-2.25,0},{0,-2.25,1.75},{0,-2,1.75},{0,0,1.75},{0,2,1.75},{0,2.25,1.75},{0,2.25,0}},
{{1,-2.25,0},{1,-2.25,1.75},{1,-2,1.75},{1,0,1.75},{1,2,1.75},{1,2.25,1.75},{1,2.25,0}},
{{1.01,-2.25,1.5},{1.01,-2.25,1.75},{1.01,-2,1.75},{1.01,0,1.75},{1.01,2,1.75},{1.01,2.25,1.75},{1.01,2.25,1.5}},
{{2.99,-2.25,1.5},{2.99,-2.25,1.75},{2.99,-2,1.75},{2.99,0,1.75},{2.99,2,1.75},{2.99,2.25,1.75},{2.99,2.25,1.5}},
{{3,-2.25,0},{3,-2.25,1.75},{3,-2,1.75},{3,0,1.75},{3,2,1.75},{3,2.25,1.75},{3,2.25,0}},
{{4,-2.25,0},{4,-2.25,1.75},{4,-2,1.75},{4,0,1.75},{4,2,1.75},{4,2.25,1.75},{4,2.25,0}},
{{5,-2.25,0},{5,-2.25,1.75},{5,-2,3.5},{5,0,3.5},{5,2,3.5},{5,2.25,1.75},{5,2.25,0}},
{{8,-2.25,0},{8,-2.25,1.75},{8,-2,3.5},{8,0,3.5},{8,2,3.5},{8,2.25,1.75},{8,2.25,0}},
{{8.01,-2.25,1.5},{8.01,-2.25,1.75},{8.01,-2,3.5},{8.01,0,3.5},{8.01,2,3.5},{8.01,2.25,1.75},{8.01,2.25,1.5}},
{{9,-2.25,1.5},{9,-2.25,2},{9,-2,2},{9,0,2},{9,2,2},{9,2.25,2},{9,2.25,1.5}},
{{9.99,-2.25,1.5},{9.99,-2.25,2},{9.99,-2,2},{9.99,0,2},{9.99,2,2},{9.99,2.25,2},{9.99,2.25,1.5}},
{{10,-2.25,0},{10,-2.25,2},{10,-2,2},{10,0,2},{10,2,2},{10,2.25,2},{10,2.25,0}},
{{11,-2.25,0},{11,-2.25,2},{11,-2,2},{11,0,2},{11,2,2},{11,2.25,2},{11,2.25,0}},
{{11.01,-2.25,0},{11.01,-2.25,0},{11.01,-2,0},{11.01,0,0},{11.01,2,0},{11.01,2.25,0},{11.01,2.25,0}}
})]

Comprehension Question

Generate some (x,y,z) points that have some meaning (like on a paraboloid) and apply BSplineSurface to give the surface.  
Modify the points slightly and see how it changes the surface.

Example:  Costa Rica Pendant

This is an example in which the geography of Costa Rica is transformed into a polygon, and then given some thickness by adding in rectangles along the boundary to connect two polygonal sheets distance 0.25 apart.

CREdges=CountryData[Entity["Country","CostaRica"],"Polygon"][[1,1,1]];

Graphics3D[{Polygon[Map[Prepend[#,0]&,CREdges]],Polygon[Map[Prepend[#,0.25]&,CREdges]]}]

Graphics3D[{Table[Polygon[{
Prepend[CREdges[[i]],0],
Prepend[CREdges[[Mod[i+1,Length[CREdges],1]]],0],
Prepend[CREdges[[Mod[i+1,Length[CREdges],1]]],0.25],
Prepend[CREdges[[i]],0.25]}],{i,Length[CREdges]}]}]

Comprehension Question

Merge the two parallel plates with the edges to create a solid pendant.

Example: Hyperbolic Paraboloid Surface

This code was generously published by Henry Segerman in his preprint: 3D printing for mathematical visualisation. 
(Read page 7 of http://www.ms.unimelb.edu.au/~segerman/papers/3d_printed_visualisation.pdf, where he describes what each line does)

f[u_,v_]:={u,v,u^2−v^2};
scale=40;
radius=0.75;
numPoints=24;
gridSteps=10;
curvesU=Table[scale f[u,i],{i,−1,1,2/gridSteps}];
curvesV=Table[scale f[j,v],{j,−1,1,2/gridSteps}];
tubesU=ParametricPlot3D[curvesU,{u,−1,1},PlotStyle->Tube[radius,PlotPoints->numPoints],PlotRange->All];
tubesV=ParametricPlot3D[curvesV,{v,−1,1},PlotStyle->Tube[radius,PlotPoints->numPoints],PlotRange->All];
corners=Graphics3D[Table[Sphere[scale f[i,j],radius],{i,−1,1,2},{j,−1,1,2}],PlotPoints->numPoints];
output=Show[tubesU,tubesV,corners]

Comprehension Question

Modify the surface to something different that you find more appealing.

Example: Create a die with pips using RegionPlot3D.

pip=.04;
RegionPlot3D[Abs[x]≤1&&Abs[y]≤1&&Abs[z]≤1&&
(* 1 side *)
(x^2+y^2+(z-1)^2≥pip)&&
(* 6 side *)
((x+.5)^2+y^2+(z+1)^2≥pip)&&
((x+.5)^2+(y+.5)^2+(z+1)^2≥pip)&&
((x+.5)^2+(y-.5)^2+(z+1)^2≥pip)&&
((x-.5)^2+y^2+(z+1)^2≥pip)&&
((x-.5)^2+(y+.5)^2+(z+1)^2≥pip)&&
((x-.5)^2+(y-.5)^2+(z+1)^2≥pip)&&
(* 2 side *)
((x-1)^2+(y+.5)^2+(z+.5)^2≥pip)&&
((x-1)^2+(y-.5)^2+(z-.5)^2≥pip) &&
(* 5 side *)
(* 3 side *)
(x^2+(y-1)^2+z^2≥pip)&&
((x+.5)^2+(y-1)^2+(z+.5)^2≥pip)&&
((x-.5)^2+(y-1)^2+(z-.5)^2≥pip) &&
(* 4 side *)
((x+.5)^2+(y+1)^2+(z+.5)^2≥pip)&&
((x+.5)^2+(y+1)^2+(z-.5)^2≥pip)&&
((x-.5)^2+(y+1)^2+(z+.5)^2≥pip)&&
((x-.5)^2+(y+1)^2+(z-.5)^2≥pip)
,{x,-1.5,1.5},{y,-1.5,1.5},{z,-1.5,1.5},PlotPoints->50,PlotStyle->White,Mesh->None,Axes->False,Boxed->False]

Comprehension Question

Put in the pips on the last side of the die.

Solutions

Die Die Die

((x+1)^2+y^2+z^2≥pip)&&
((x+1)^2+(y+.5)^2+(z+.5)^2≥pip)&&
((x+1)^2+(y+.5)^2+(z-.5)^2≥pip)&&
((x+1)^2+(y-.5)^2+(z+.5)^2≥pip)&&
((x+1)^2+(y-.5)^2+(z-.5)^2≥pip)&&