ParaScript
workspace.para
Language
RUN SOLVER
DOWNLOAD STL
setup { name: "M3 screw", units: "mm", coordinate_system: "Z-up" } // M3x16 hexagon-head screw. A measurement from a standard sits in the group // named for that standard. The head is an ISO 4017 hexagon with a vertex on // the Y axis. The shank follows the ISO 68-1 M3 coarse basic profile: // 60 degrees, major diameter 3 mm, minor diameter 2.459 mm. // The head sits on z = 0 and the tip is one length below it. // Each turn is its own face. One face for the whole shank would be sampled // too coarsely to show the pitch. parameters { head: { iso_4017: { across_flats: 5.5, height: 2.0, length: 16.0 }, flat: iso_4017.across_flats / 2.0, // Distance from the axis to a vertex. The angle is pi / 6, with the pi bound below. corner: flat / cos(rad: 3.14159265359 / 6.0) }, thread: { iso_68_1: { pitch: 0.5 }, tip: 0.0 - $head.iso_4017.length, // Closure of the shank inside the head, so the hex underside stays a solid face. bury: 0.05, // Cosine series of the ISO 68-1 external basic profile. // Phase 0 is the crest. The series stays within 0.01 mm of that profile. c0: 1.347769, c1: 0.143114, c2: 0.015512, c3: 0.0 - 0.003163, c4: 0.005484, c5: 0.0 - 0.003825 } } // pi is a value the whole script shares. def pi = 3.14159265359 // Radius at a seam, where the helical phase collapses to the angle around the shank. def end_radius = u => $thread.c0 + $thread.c1 * cos(rad: u) + $thread.c2 * cos(rad: 2.0 * u) + $thread.c3 * cos(rad: 3.0 * u) + $thread.c4 * cos(rad: 4.0 * u) + $thread.c5 * cos(rad: 5.0 * u) // One pitch of the helix. Clockwise in u so the wall faces outward. def wall = coords => index => Surface2D( max_u: 2.0 * pi, min_v: u => $thread.tip + index * $thread.iso_68_1.pitch, max_v: u => $thread.tip + index * $thread.iso_68_1.pitch + $thread.iso_68_1.pitch, formula: u => v => Vector(coords: coords, x: ($thread.c0 + $thread.c1 * cos(rad: 1.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c2 * cos(rad: 2.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c3 * cos(rad: 3.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c4 * cos(rad: 4.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c5 * cos(rad: 5.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u))) * cos(rad: u), y: ($thread.c0 + $thread.c1 * cos(rad: 1.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c2 * cos(rad: 2.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c3 * cos(rad: 3.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c4 * cos(rad: 4.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c5 * cos(rad: 5.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u))) * (0.0 - sin(rad: u)), z: v ) ) def tip_cap = coords => Surface2D( max_u: 2.0 * pi, min_v: u => 0.0, max_v: end_radius, formula: u => v => Vector(coords: coords, x: v * cos(rad: u), y: v * (0.0 - sin(rad: u)), z: $thread.tip ) ) // Short collar and cap buried in the head. They close the shank without showing. def collar = coords => Surface2D( max_u: 2.0 * pi, min_v: u => 0.0, max_v: u => $thread.bury, formula: u => v => Vector(coords: coords, x: ($thread.c0 + $thread.c1 * cos(rad: 1.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c2 * cos(rad: 2.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c3 * cos(rad: 3.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c4 * cos(rad: 4.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c5 * cos(rad: 5.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u))) * cos(rad: u), y: ($thread.c0 + $thread.c1 * cos(rad: 1.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c2 * cos(rad: 2.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c3 * cos(rad: 3.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c4 * cos(rad: 4.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u)) + $thread.c5 * cos(rad: 5.0 * (2.0 * pi * v / $thread.iso_68_1.pitch - u))) * (0.0 - sin(rad: u)), z: v ) ) def shank_cap = coords => Surface2D( max_u: 2.0 * pi, min_v: u => 0.0, max_v: u => $thread.c0 + $thread.c1 * cos(rad: 1.0 * (2.0 * pi * $thread.bury / $thread.iso_68_1.pitch - u)) + $thread.c2 * cos(rad: 2.0 * (2.0 * pi * $thread.bury / $thread.iso_68_1.pitch - u)) + $thread.c3 * cos(rad: 3.0 * (2.0 * pi * $thread.bury / $thread.iso_68_1.pitch - u)) + $thread.c4 * cos(rad: 4.0 * (2.0 * pi * $thread.bury / $thread.iso_68_1.pitch - u)) + $thread.c5 * cos(rad: 5.0 * (2.0 * pi * $thread.bury / $thread.iso_68_1.pitch - u)), formula: u => v => Vector(coords: coords, x: v * cos(rad: u), y: v * sin(rad: u), z: $thread.bury ) ) // One flat of the hexagon. index 0 starts at 30 degrees and each step is 60 degrees. // u runs from the higher-angle vertex back to this one so the flat faces outward. def side = coords => index => Surface2D( max_u: 1.0, min_v: u => 0.0, max_v: u => $head.iso_4017.height, formula: u => v => Vector(coords: coords, x: (1.0 - u) * $head.corner * cos(rad: index * pi / 3.0 + pi / 6.0 + pi / 3.0) + u * $head.corner * cos(rad: index * pi / 3.0 + pi / 6.0), y: (1.0 - u) * $head.corner * sin(rad: index * pi / 3.0 + pi / 6.0 + pi / 3.0) + u * $head.corner * sin(rad: index * pi / 3.0 + pi / 6.0), z: v ) ) def head_top = coords => index => Surface2D( max_u: 1.0, min_v: u => 0.0, max_v: u => 1.0, formula: u => v => Vector(coords: coords, x: u * ((1.0 - v) * $head.corner * cos(rad: index * pi / 3.0 + pi / 6.0 + pi / 3.0) + v * $head.corner * cos(rad: index * pi / 3.0 + pi / 6.0)), y: u * ((1.0 - v) * $head.corner * sin(rad: index * pi / 3.0 + pi / 6.0 + pi / 3.0) + v * $head.corner * sin(rad: index * pi / 3.0 + pi / 6.0)), z: $head.iso_4017.height ) ) def head_bottom = coords => index => Surface2D( max_u: 1.0, min_v: u => 0.0, max_v: u => 1.0, formula: u => v => Vector(coords: coords, x: u * ((1.0 - v) * $head.corner * cos(rad: index * pi / 3.0 + pi / 6.0) + v * $head.corner * cos(rad: index * pi / 3.0 + pi / 6.0 + pi / 3.0)), y: u * ((1.0 - v) * $head.corner * sin(rad: index * pi / 3.0 + pi / 6.0) + v * $head.corner * sin(rad: index * pi / 3.0 + pi / 6.0 + pi / 3.0)), z: 0.0 ) ) def M3Screw = Component( solid: coords => Solid3D(faces: [ tip_cap(coords: coords), collar(coords: coords), shank_cap(coords: coords), side(coords: coords, index: 0.0), side(coords: coords, index: 1.0), side(coords: coords, index: 2.0), side(coords: coords, index: 3.0), side(coords: coords, index: 4.0), side(coords: coords, index: 5.0), head_top(coords: coords, index: 0.0), head_top(coords: coords, index: 1.0), head_top(coords: coords, index: 2.0), head_top(coords: coords, index: 3.0), head_top(coords: coords, index: 4.0), head_top(coords: coords, index: 5.0), head_bottom(coords: coords, index: 0.0), head_bottom(coords: coords, index: 1.0), head_bottom(coords: coords, index: 2.0), head_bottom(coords: coords, index: 3.0), head_bottom(coords: coords, index: 4.0), head_bottom(coords: coords, index: 5.0), wall(coords: coords, index: 0.0), wall(coords: coords, index: 1.0), wall(coords: coords, index: 2.0), wall(coords: coords, index: 3.0), wall(coords: coords, index: 4.0), wall(coords: coords, index: 5.0), wall(coords: coords, index: 6.0), wall(coords: coords, index: 7.0), wall(coords: coords, index: 8.0), wall(coords: coords, index: 9.0), wall(coords: coords, index: 10.0), wall(coords: coords, index: 11.0), wall(coords: coords, index: 12.0), wall(coords: coords, index: 13.0), wall(coords: coords, index: 14.0), wall(coords: coords, index: 15.0), wall(coords: coords, index: 16.0), wall(coords: coords, index: 17.0), wall(coords: coords, index: 18.0), wall(coords: coords, index: 19.0), wall(coords: coords, index: 20.0), wall(coords: coords, index: 21.0), wall(coords: coords, index: 22.0), wall(coords: coords, index: 23.0), wall(coords: coords, index: 24.0), wall(coords: coords, index: 25.0), wall(coords: coords, index: 26.0), wall(coords: coords, index: 27.0), wall(coords: coords, index: 28.0), wall(coords: coords, index: 29.0), wall(coords: coords, index: 30.0), wall(coords: coords, index: 31.0) ]), expose: coords => {} ) export(M3Screw)
Model
Solid sides
Drag to turn. Pinch to zoom. Two fingers pan.