(*This Mathematica code was written by John Zweck (zweck@utdallas.edu) and generates a mathematical curve/surface that can be printed using a 3D printer. This model can (probably) be printed by Shapeways.*)

(*If you evaluate this Mathematica notebook,the curve/surface will be rendered using computer graphics.*)

(*If you uncomment the export line at the end of the code and set the directory path appropriately for your system you will obtain an STL file that can be sent to a 3D printer.*)

(*The STL file can also be viewed using the open source software Meshlab.*)

(*You may modify this code in any way you like.*)

(*This project was supported by the National Science Foundation through a Supplement to the UTeach Dallas Robert Noyce Scholarship Program (DUE 1544159).*)

(* This surface and SaddleSurfaceLevelCurves fit together to form the boundary of a volume 
that can be integrated in cylindrical corrdinated *)

Surface[u_,v_]:={(8-u)^0.5*Cos[v],((8-u)/3)^0.5*Sin[v],u};

intersectionCylin[r_,t_]={r*(Cos[t]),r*(Sin[t]),r^2*((Cos[t])^2-(Sin[t])^2)};

scale = 16;            (*Height is 4*scale mm and largest diameter is 4*scale mm, with scale =25 get 8 cm *)
radius = 1;           (*Diameter of tubes is 2r in mm *)
numPoints=100;  (*Number of sides of cross section of polygonal tube*)
gridstepsParabolas=8;
umin=-4;
umax=8;
vmin=0;
vmax=2*Pi;

NumLevelCurves=20;

RadiusCylinder=2;

curvesParabolas=Table[scale*Surface[u,j],{j, vmin, vmax,(vmax-vmin)/gridstepsParabolas}];

curvesCircles=Table[scale*Surface[i,v],{i,umin,umax, (umax-umin)/NumLevelCurves}];

tubesParabolas=ParametricPlot3D[curvesParabolas,{u,umin,umax},RegionFunction->Function[{x,y,z},x^2+y^2<(scale*RadiusCylinder)^2],
 PlotStyle->Tube[radius,PlotPoints->numPoints],PlotRange->All];

tubesCircles=ParametricPlot3D[curvesCircles,{v,vmin,vmax},
RegionFunction->Function[{x,y,z},x^2+y^2<(scale*RadiusCylinder)^2],
PlotStyle->Tube[radius,PlotPoints->numPoints],PlotRange->All];

tubesIntersect=ParametricPlot3D[scale*intersectionCylin[RadiusCylinder,t],{t,0,2*Pi},PlotStyle->Tube[radius,PlotPoints->numPoints],PlotRange->All];

output=Show[tubesParabolas,tubesCircles,tubesIntersect]

(*Export["EllipticalParaboloidLevelCurves.stl",output];*)