/** This contains routines for making screw threads for 3-D printing. */ use parametric3D.frink /** Makes a single-pixel tool for testing. This returns a VoxelArray with a single pixel at [0,0,0] */ makeSinglePixelTool[] := { return newJava["frink.graphics.VoxelArray", [0,1,0,1,0,1,true]] } /** Makes a spherical tool. This returns a VoxelArray with a sphere of the specified radius and resolution centered at (0,0,0) */ makeSphereTool[radius, res] := { return callJava["frink.graphics.VoxelArray", "makeSphere", [radius res]] } /** Makes a double-cone tool suitable for simple screw threads. This returns a VoxelArray with a double cone of the specified height and radius and resolution centered at (0,0,0). The cone is oriented with the points pointing along the Z axis. */ makeDoubleConeTool[halfHeight, radius, res] := { t1 = callJava["frink.graphics.VoxelArray", "makeTaperedCylinder", [0,0,0,0,0,halfHeight res, radius res, 0]] t2 = callJava["frink.graphics.VoxelArray", "makeTaperedCylinder", [0,0,0,0,0,-halfHeight res, radius res, 0]] return t1.union[t2] } /** Makes a double-cone with flat sides tool suitable for simple screw threads. This returns a VoxelArray with a double cone of the specified height and radius and resolution centered at (0,0,0). The cone is oriented with the points pointing along the Z axis. */ makeDoubleConeTool[coneHeight, radius, flatHeight, res] := { t1 = callJava["frink.graphics.VoxelArray", "makeTaperedCylinder", [0,0,flatHeight/2 res,0,0,(coneHeight+flatHeight/2) res, radius res, 0]] t2 = callJava["frink.graphics.VoxelArray", "makeTaperedCylinder", [0,0,-flatHeight/2 res,0,0,-(coneHeight + flatHeight/2) res, radius res, 0]] flat = callJava["frink.graphics.VoxelArray", "makeCylinder", [0,0,flatHeight/2 res,0,0,-flatHeight/2 res, radius res]] return t1.union[t2].union[flat] } /** Calculates a helical tool path. This returns a frink.graphics.Point3DIntList which specifies 3-D integer coordinates where the tool should pass through. The tool's path can be instantiated into a 3-D model using VoxelArray.paintAlongPath */ makeHelicalToolPath[radius, pitch, angle0, angle1, t0, res] := { // These functions are defined in parametric3D.frink return calculatePath[getFunction["helix",2], [radius, pitch, t0], angle0, angle1, res] } /** Makes threads with the specified radius, pitch, angles, resolution, and tool. The tool should probably be centered at [0,0,0] */ makeThreads[radius, pitch, angle0, angle1, t0, tool, res] := { path = makeHelicalToolPath[radius, pitch, angle0, angle1, t0, res] v = callJava["frink.graphics.VoxelArray", "paintAlongPath", [path, tool, 0,0,0]] return v }