surfaceThickness:= 0.2
tubeThickness:=0.15


(* Regions for surfaces *)
ellipsoidRegionFunction:=Function[{x,y,z},-2≤z≤2]
dcRegionFunction:=Function[{x,y,z},-2≤z≤2]
h1SRegionFunction:=Function[{x,y,z},-2≤z≤2]
epRegionFunction:=Function[{x,y,z},0≤z≤4]
hpRegionFunction:=Function[{x,y,z},-2≤x≤2&&-2≤y≤2&&-4≤z≤4]

(* Graphs of surfaces themselves *)
ellipsoid :=ParametricPlot3D[{{x,y,Sqrt[1-x^2-y^2]},{x,y,-Sqrt[1-x^2-y^2]}},{x,-5,5},{y,-4,4},PlotStyle->Thickness[surfaceThickness],RegionFunction->ellipsoidRegionFunction]
doubleCone:= Show[ParametricPlot3D[{{x,y,Sqrt[1.5x^2+y^2]},{x,y,-Sqrt[1.5x^2+y^2]}},{x,-5,5},{y,-4,4},PlotStyle->Thickness[surfaceThickness],RegionFunction->dcRegionFunction],Graphics3D[Cylinder[{{0,0,-0.2},{0,0,0.2}},0.3]]]
hyperboloidOneSheet:= ParametricPlot3D[{{x,y,Sqrt[(x/1.5)^2+y^2-1]},{x,y,-Sqrt[(x/1.5)^2+y^2-1]}},{x,-5,5},{y,-4,4},PlotStyle->Thickness[surfaceThickness],RegionFunction->h1SRegionFunction]
ellipticParaboloid := ParametricPlot3D[{x,y,x^2+2y^2},{x,-2,2},{y,-2,2},PlotStyle->Thickness[surfaceThickness],RegionFunction->epRegionFunction]
hyperbolicParaboloid :=ParametricPlot3D[{x,y,x^2-y^2},{x,-2,2},{y,-2,2},PlotStyle->Thickness[surfaceThickness],RegionFunction->hpRegionFunction]

(* Contour curves *)
xPlaneDC:=ParametricPlot3D[{{1,y,Sqrt[2y^2+3]/Sqrt[2]},{1,y,-Sqrt[2y^2+3]/Sqrt[2]}},{y,-4,4},PlotStyle->Tube[tubeThickness],RegionFunction->dcRegionFunction]
yPlaneDC:=ParametricPlot3D[{{x,1,Sqrt[3x^2+2]/Sqrt[2]},{x,1,-Sqrt[3x^2+2]/Sqrt[2]}},{x,-5,5},PlotStyle->Tube[tubeThickness],RegionFunction->dcRegionFunction]
zPlaneDC:=ParametricPlot3D[{{x,-Sqrt[2-3x^2]/Sqrt[2],1},{x,Sqrt[2-3x^2]/Sqrt[2],1}},{x,-5,5},PlotStyle->Tube[tubeThickness],RegionFunction->dcRegionFunction]
contourCurvesDC:=Show[xPlaneDC,yPlaneDC,zPlaneDC]

xPlaneh1S:=ParametricPlot3D[{{1,y,1/3Sqrt[9y^2-5]},{1,y,-1/3Sqrt[9y^2-5]}},{y,-4,4},PlotStyle->Tube[tubeThickness],RegionFunction->h1SRegionFunction]
yPlaneh1S:=ParametricPlot3D[{{x,1,-2x/3},{x,1,2x/3}},{x,-5,5},PlotStyle->Tube[tubeThickness],RegionFunction->h1SRegionFunction]
zPlaneh1S:=ParametricPlot3D[{{x,-1/3Sqrt[2]Sqrt[9-2x^2],1},{x,1/3Sqrt[2]Sqrt[9-2x^2],1}},{x,-5,5},PlotStyle->Tube[tubeThickness],RegionFunction->h1SRegionFunction]
contourCurvesh1S:=Show[xPlaneh1S,yPlaneh1S,zPlaneh1S]

xPlaneEP := ParametricPlot3D[{1,y,1+2y^2},{y,-2,2},PlotStyle->Tube[tubeThickness],RegionFunction->epRegionFunction]
yPlaneEP := ParametricPlot3D[{x,1,x^2+2},{x,-2,2},PlotStyle->Tube[tubeThickness],RegionFunction->epRegionFunction]
zPlaneEP:=ParametricPlot3D[{{x,-Sqrt[1-x^2]/Sqrt[2],1},{x,Sqrt[1-x^2]/Sqrt[2],1}},{x,-2,2},PlotStyle->Tube[tubeThickness],RegionFunction->epRegionFunction]
contourCurvesEP:= Show[xPlaneEP,yPlaneEP,zPlaneEP]

xPlaneHP:=ParametricPlot3D[{0,y,-y^2},{y,-2,2},RegionFunction->hpRegionFunction,PlotStyle->Tube[tubeThickness]]
yPlaneHP:=ParametricPlot3D[{x,0,x^2},{x,-2,2},RegionFunction->hpRegionFunction,PlotStyle->Tube[tubeThickness]]
zElevatedPlaneHP:=ParametricPlot3D[{{x,-Sqrt[2x^2-3]/Sqrt[2],1.5},{x,Sqrt[2x^2-3]/Sqrt[2],1.5}},{x,-2,2},RegionFunction->hpRegionFunction,PlotStyle->Tube[tubeThickness]]
contourCurvesHP := Show[xPlaneHP,yPlaneHP,zElevatedPlaneHP]

(* Combined Graphs *)
(* There is some black magic here; to make all parts of the graph show up in the final stl file I had to essentially randomly try repairing parts of some of the meshes and mess around with Prinout3D to have a final model repair or not. I could not make sense of the reason why some things worked and some didnlt. *)
outputDC:= Show[doubleCone,RepairMesh[DiscretizeGraphics[contourCurvesDC]]]
outputh1S:= Show[RepairMesh[DiscretizeGraphics[hyperboloidOneSheet]],contourCurvesh1S]
outputEP := Show[RepairMesh[DiscretizeGraphics[ellipticParaboloid]],contourCurvesEP]
outputHP := Show[RepairMesh[DiscretizeGraphics[hyperbolicParaboloid]],contourCurvesHP]

(* Generate STL Files *)

Printout3D[outputDC,NotebookDirectory[]<>"Double Cone.stl",RegionSize->Quantity[{50},"mm"],Method->"SkipModelRepair"]
(*
Printout3D[outputh1S,NotebookDirectory[]<>"Hyperboloid One Sheet.stl",RegionSize->Quantity[{50},"mm"],Method->"SkipModelRepair"]
Printout3D[outputEP,NotebookDirectory[]<>"Elliptic Paraboloid.stl",RegionSize->Quantity[{50},"mm"]]
Printout3D[outputHP,NotebookDirectory[]<>"Hyperbolic Paraboloid.stl",RegionSize->Quantity[{50,50,50},"mm"],Method->"SkipModelRepair"]