(*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).*)

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

Ruling[t_,v_] := {t,v/((1+t^2)^0.5),t*v/((1+t^2)^0.5)};

scale = 16;
radius = 1;

RadiusCylinder=2;

numPoints=100;

NumRulings=16;

tmin=-RadiusCylinder;
tmax=RadiusCylinder;

curvesRuling = Table[scale*Ruling[i,v],{i,tmin,tmax,(tmax-tmin)/(NumRulings)}];

curveDirectrix =  Table[scale*Ruling[t,j],{j,0,0}];

tubesRuling =ParametricPlot3D[curvesRuling,{v,-2*RadiusCylinder,2*RadiusCylinder},
RegionFunction->Function[{x,y,z},  x^2+y^2 ≤ (scale*RadiusCylinder)^2],PlotStyle->Tube[radius],PlotPoints->numPoints,PlotRange->All];

tubeDirectrix = ParametricPlot3D[curveDirectrix,{t,-RadiusCylinder,RadiusCylinder},
RegionFunction->Function[{x,y,z},  x^2+y^2 ≤ (scale*RadiusCylinder)^2],PlotStyle->Tube[radius],PlotPoints->numPoints,PlotRange->All];

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


output=Show[ tubesIntersect,tubesRuling, tubeDirectrix ]

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