Mathematica Project, Math 21a, Fall, 2013

The project

This mostly creative project asks you to answer three problems and then to produce an object in Mathematica which can either be printed on a 3D printer or be imported in Google earth. 
Please use the latest version Mathematica 9 for this project.
There is a Mathematica workshop on November 20, 2013, from 7-8 PM in Hall C.  
The project is due Sunday December 8, 2013 but you can submit anytime until then. Submit the project electronically to knill@math.harvard.edu after deleting all output (Choose Cell->DeleteAllOutput in the menu to the top of this window. You will get a confirmation that the project has been accepted. The file name should contain your first and last name. Like OliverKnill.nb).

The assignment

Problem A  (2 points) Plot the parametrized surface r(u,v) = <x(u,v),y(u,v),z(u,v)> of your choice. Draw something pretty and new.

Problem B  (2 points) Choose a vector field F(x,y,z)  in space and draw a flow line. We want to see the field and the flow line.

Problem C  (6 points) Produce an object of your choice. Prepare it for 3D printing or inclusion into Google earth. Produce something on your own.

What to submit

Submit your Mathematica project file by email. Mention in the project whether you choose the Printing option or the google earth option. In the case of the printing option, submit the project to a printing service like Shapeways to test it. In case of the google earth option, import it into Sketchup and import it to google earth. This is demonstrated in the workshop.

Example Code

Parametric Surfaces

r[u_,v_]:=(1+Cos[3u] Sin[4v]/10){Cos[u] Sin[v],Sin[u] Sin[v],Cos[v]};
ParametricPlot3D[r[u,v],{u,0,2Pi},{v,0,Pi}]

R=5;
S1=Graphics3D[Table[{Hue[Abs[v]/2],Tube[Table[r[u,v],{u,0,2Pi+1/R,1/R}]]},{v,0,Pi,1/R}]];S2=Graphics3D[Table[{Hue[Abs[u]/2],Tube[Table[r[u,v],{v,0,Pi+1/R,1/R}]]},{u,0,2Pi,1/R}]];
Show[{S1,S2}]

S=ParametricPlot3D[5 (3+Sin[11 s]-Sin[7t]) {Cos[t] Sin[s],Sin[t] Sin[s],Cos[s]},{t,0,2 Pi},{s,0,Pi},Boxed->False,Axes->False,PlotPoints->30,ColorFunction->Function[{x,y,z,u,v},Hue[(Sin[11u])^2]]]

The simplest export is in STL format, but this does not use the color:

Example: Flow lines of aVector Field

Just cahnge the vector field F[{x_, y_, z_}] below and possibly the initial point which is now {0, 1, 0}. Use a simple vector field , like {-y, x, 3} and go from there.

RK[f_,x_,s_]:=Module[{a,b,c,u,v,w,q},u=s*f[x];
a=x+u/2;v=s*f[a];b=x+v/2;w=s*f[b];c=x+w;q=s*f[c];x+(u+2v+2w+q)/6];
F[{x_,y_,z_}]:={10 (y-x),-x z+28 x-y,x y-8/3 z};
T[X_]:=RK[F,X,0.01];s=NestList[T,{0,1,0},5000];
S1=Graphics3D[{Yellow,Tube[s]}];
S2=VectorPlot3D[F[{x,y,z}],{x,-20,20},{y,-20,20},{z,0,40},VectorPoints->5];
S=Show[{S1,S2},AspectRatio->1,Boxed->False]

Example: Exporting to Google earth

leaf=ParametricPlot3D[20 {Cos[t] Sin[s],0.2 Sin[t] Sin[s],0.1 Cos[s]},{t,0,2 Pi},{s,0,Pi},Mesh->False][[1]];
leafs=Table[{RGBColor[{(1+Random[])/2,Random[],0}],Rotate[leaf,2 Pi k/7,{0,0,1},{0,0,0}]},{k,1,7}];
stem={Green,Cylinder[{{0,0,0},{0,0,-20}},1]};
base={Yellow,Cylinder[{{0,0,-20},{0,0,-23}},10]};
flower={leafs,stem,base};
S=Show[Graphics3D[flower]]

Example: A form

S=ParametricPlot3D[10 {Cos[t] Sin[s],Sin[t] Sin[s],Cos[t]+Cos[s]+Sin[s]},{t,0,2 Pi},{s,0,Pi},
MeshShading->{{Green,Blue},{Yellow,Red}},Mesh->8,PlotPoints->50,Axes->False,Boxed->False,Mesh->False,AspectRatio->1]

Example: A statue

a=30;b=22;c=10;d=25;e=6;
A1={Yellow,Cuboid[{{0,0,-2},{a,a,0}}]};
A2={Blue,Cylinder[{{b,c,0},{0,a,a}},1]};
A3={Red,Sphere[{b,b,d},e]};
A4={Orange,Cuboid[{c,c,c},{b,b,b}]};
A5={Yellow,Sphere[{0,a,a},2]};
A6={Yellow,Sphere[{b,c,0},2]};
S=Show[Graphics3D[{A1,A2,A3,A4,A5,A6}]]

Example: The Penrose triangle

b=N[20/7];d=22.4;f=18.666;h=20;
P1={Yellow,Cuboid[{{0,0,0},{h+b,-b,b}}]};
P2={Yellow,Cuboid[{{0,0,0},{b,-h,b}}]};
P3={Yellow,Cuboid[{{0,-h,0},{b,b-h,f}}]};
P4={Yellow,Polygon[{{b,b-h,f},{b,-h,d},{0,-h,d},{0,b-h,f},{b,b-h,f}}]};
P5={Yellow,Polygon[{{b,-h,f},{b,-h,d},{0,-h,d},{0,-h,f},{b,-h,f}}]};
P6={Yellow,Polygon[{{0,b-h,f},{0,-h,f},{0,-h,d},{0,b-h,f}}]};
P7={Yellow,Polygon[{{b,b-h,f},{b,-h,f},{b,-h,d},{b,b-h,f}}]};
S=Show[Graphics3D[{P1,P2,P3,P4,P5,P6,P7}],PlotRange->All,ViewPoint->{-12.625,-10.9375,14.21},Boxed->False,Axes->False]
Export["triangle.stl",S,"STL"]

Example: Random stuff

S=Graphics3D[Table[{Hue[Random[]],Sphere[20 {Random[],Random[],Random[]},2]},{100}]];

S=Graphics3D[Table[x=20{Random[],Random[],Random[]}; {Hue[Random[]],Rotate[Cuboid[{x,x+{8,8,8}}],2Pi Random[],{Random[]-0.5,Random[]-0.5,Random[]-0.5}]},{200}]]

Example: The earth

Using textures. Unfortunately, this will neither print, nor go to google earth.

s=Import["http://www.math.harvard.edu/~knill/images/earthtexture.png"];
S=SphericalPlot3D[1.2+0.02 Sin[phi]^2 Cos[theta],{phi,0,Pi},{theta,0,2 Pi},Lighting->"Neutral",Mesh->None,PlotPoints->30,TextureCoordinateFunction->({-#5,#4}&),PlotStyle->{Specularity[White,20],Texture[s]},Axes->False,Boxed->False,AspectRatio->1]

Example: Chemical element

ChemicalData[]  lists  all molecules which are implemented. Also this model does not print as given since it is too large. The scaling command unfortunately also makes models unprintable.

S=ChemicalData["Caffein","MoleculePlot"]

Example: Using 3DS models

S=Import["http://www.math.harvard.edu/~knill/images/violin.3ds"]

Example: Menger Sponge

Menger[0,{i_,j_,k_}]:={Cuboid[{{i-0.01,j-0.01,k-0.01},{i+1.01,j+1.01,k+1.01}}]};
Menger[n_,{i_,j_,k_}]:=Module[{s={}},Do[If[Not[u==v==2||v==w==2||u==w==2],s=Union[s,Menger[n-1,3^(n-1)*{u,v,w}+{i,j,k}]]],{u,3},{v,3},{w,3}];s];
S=Show[Graphics3D[Menger[3,{0,0,0}]],Boxed->False]

Example: Metatron, an icon from Sacred Geometry

SetOptions[Graphics3D,{AspectRatio->1,Boxed->False}];

eps=0.1;
circle[PP_,rr_]:=Tube[Table[PP+rr{Cos[t],Sin[t],0},{t,0,2Pi,2Pi/600}],eps];
point[PP_,rr_]:=Tube[{PP+{0,0,2eps},PP-{0,0,2eps}},rr];
line[{x_,y_}]:={Yellow,Tube[{x,y},eps/2]};

A1={Red,circle[{0,0,0},1.2]};
A2={Red,Table[circle[2 {Re[Exp[2 Pi k I/6]],Im[Exp[2 Pi k I/6]],0},1.2],{k,6}]};
A3={Red,Table[circle[4 {Re[Exp[2 Pi k I/6]],Im[Exp[2 Pi k I/6]],0},1.2],{k,6}]};
P=Union[{{0,0,0}},Table[2 {Re[Exp[2 Pi k I/6]],Im[Exp[2 Pi k I/6]],0},{k,6}],Table[4 {Re[Exp[2 Pi k I/6]],Im[Exp[2 Pi k I/6]],0},{k,6}]];
A4={Blue,Table[line[{P[[i]],P[[j]]}],{i,Length[P]},{j,i+1,Length[P]}]};
A5={Green,Table[point[2 {Re[Exp[2 Pi k I/6]],Im[Exp[2 Pi k I/6]],0},0.1],{k,6}]};
A6={Green,Table[point[4 {Re[Exp[2 Pi k I/6]],Im[Exp[2 Pi k I/6]],0},0.1],{k,6}]};
A7={Green,Table[point[{0,0,0},0.1],{k,6}]};
S=Show[Graphics3D[{A1,A2,A3,A4,A5,A6,A7}]]

Exporting Files

Here is an export to STL, which is used in 3D printing. This file format does not support color.

Export["s.stl",S];

Here is an export to WRL, which can also be used in 3D printing. This file format does support color (but does not always work)

Export["s.wrl",S];

It will look as follows:

Import["http://www.math.harvard.edu/~knill/project2012/project1.jpg"]

The 3DS format is used if you want to import your object into Google earth.

Export["s.3ds",S]

Advise

Watch the size of objects. 
For printing Minimal wall thickness: 1mm. 
Surfaces need to be closed. 
For printing: Watch the size. Not more than 64 meg. 
Submit the 3DS or STL file to a printing service like Shapeways to test.
Import to Google earth to see whether it works.

Oliver Knill, November 15, 2013