screwThreadsTest.frink

View or download screwThreadsTest.frink in plain text format


/** This is a test of the screwThreads.frink library to make screw threads for
    3-d printing.

    This test creates a male and female garden hose fitting with threads
    as defined by the standard ASME B1.20.8-1991 (reaffirmed 1998).
*/


use screwThreads.frink

res = 254/inch

pitch = inch/11.5
//minorRadius = 0.9495 in / 2
threadHeight = .05648 in
// Male minor radius.  This is the average of the allowed min and max pitch
// diameter (table 2) minus half the thread height.
minorRadius = (1.0060+0.9975) in /2 / 2 - threadHeight/2
turns = 4.25
pilot = 1/8 in - pitch/2

// Female major radius
//  This is the average of the allowed min and max pitch
// diameter (table 3) minus half the thread height.
femaleRadius = (1.0160 + 1.0245) in / 2 / 2 - threadHeight/2

println["threadHeight is " + format[threadHeight, "mm", 2]]
println["minorDiameter is " + format[2 minorRadius, "in", 4]]
println["majorDiameter is " + format[2 minorRadius + 2 threadHeight, "in", 4]]
println["femaleDiameter is " + format[2 femaleRadius + 2 threadHeight, "in", 4]]
println["gap is " + format[femaleRadius - minorRadius, "mm", 2]]

tool = makeDoubleConeTool[pitch/2, threadHeight, res]
maleThread = makeThreads[minorRadius, pitch, 0 deg, turns * 2 pi, 0, tool, res]
malePipeOuter = callJava["frink.graphics.VoxelArray", "makeCylinder", [0,0,-1/4 in res,0,0,(turns pitch + pilot) res, minorRadius res]]
malePipeInner = callJava["frink.graphics.VoxelArray", "makeCylinder", [0,0,-1/4 in res,0,0,(turns pitch + pilot) res, (minorRadius-2.4 mm) res]]
male = maleThread.union[malePipeOuter]
male.remove[malePipeInner]

femaleThread = makeThreads[femaleRadius, pitch, 0 deg, (turns+1) * 2 pi, 0, tool, res]
femalePipeOuter = callJava["frink.graphics.VoxelArray", "makeCylinder", [0,0,-1/4 in res,0,0,(turns pitch) res, (femaleRadius + 2.4 mm) res]]
femalePipeInner = callJava["frink.graphics.VoxelArray", "makeCylinder", [0,0,-1/4 in res,0,0,(turns pitch) res, femaleRadius res]]
femalePipeOuter.remove[femalePipeInner]
femalePipeOuter.remove[femaleThread]
female = femalePipeOuter

male.projectX[undef].show["X"]
male.projectY[undef].show["Y"]
male.projectZ[undef].show["Z"]

female.projectX[undef].show["X"]
female.projectY[undef].show["Y"]
female.projectZ[undef].show["Z"]

filename = "screwThreadsMale.obj"
print["Writing $filename..."]
w = new Writer[filename]
w.println[male.toObjFormat["male", 1/(res mm)]]
w.close[]
println["done."]

filename = "screwThreadsFemale.obj"
print["Writing $filename..."]
w = new Writer[filename]
w.println[female.toObjFormat["female", 1/(res mm)]]
w.close[]
println["done."]


View or download screwThreadsTest.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 19092 days, 9 hours, 25 minutes ago.