@@ -24,11 +24,17 @@ def thread( outline_pts, inner_rad, pitch, length, segments_per_rot=32,
2424 outline_pts: a list of points (NOT an OpenSCAD polygon) that define the cross
2525 section of the thread
2626
27- inner_rad:
28- length:
29- segments_per_rot:
30- neck_in_degrees:
31- neck_out_degrees:
27+ inner_rad: radius of cylinder the screw will wrap around
28+ pitch: height for one revolution
29+ length: distance from bottom-most point of screw to topmost
30+ segments_per_rot: segments per rotatio
31+ neck_in_degrees: degrees through which the outer edge of the screw thread will move from
32+ a thickness of zero (inner_rad) to its full thickness
33+ neck_out_degrees: degrees through which outer edge of the screw thread will move from
34+ full thickness back to zero
35+
36+ NOTE: if pitch is less than the height of each tooth (outline_pts), OpenSCAD will likely
37+ crash, since the resulting screw would self-intersect all over the place
3238 '''
3339 a = union ()
3440 rotations = float (length )/ pitch
@@ -46,6 +52,7 @@ def thread( outline_pts, inner_rad, pitch, length, segments_per_rot=32,
4652 # Figure out how wide the tooth profile is
4753 min_bb , max_bb = bounding_box ( outline_pts )
4854 outline_w = max_bb [0 ] - min_bb [0 ]
55+ outline_h = max_bb [1 ] - min_bb [1 ]
4956
5057 min_rad = max ( 0 , inner_rad - outline_w - EPSILON )
5158
@@ -85,29 +92,30 @@ def thread( outline_pts, inner_rad, pitch, length, segments_per_rot=32,
8592 if i < total_steps - 1 :
8693 ind = i * poly_sides
8794 for j in range ( ind , ind + poly_sides - 1 ):
88- all_tris .append ( [ j , j + poly_sides , j + 1 ])
89- all_tris .append ( [ j + 1 , j + poly_sides , j + poly_sides + 1 ])
90- all_tris .append ( [ ind + poly_sides - 1 , ind + poly_sides - 1 + poly_sides , ind ])
91- all_tris .append ( [ ind , ind + poly_sides - 1 + poly_sides , ind + poly_sides ])
95+ all_tris .append ( [ j , j + 1 , j + poly_sides ])
96+ all_tris .append ( [ j + 1 , j + poly_sides + 1 , j + poly_sides ])
97+ all_tris .append ( [ ind , ind + poly_sides - 1 + poly_sides , ind + poly_sides - 1 ])
98+ all_tris .append ( [ ind , ind + poly_sides , ind + poly_sides - 1 + poly_sides ])
9299
93100 # End triangle fans for beginning and end
94101 last_loop = len (all_points ) - poly_sides
95102 for i in range ( poly_sides - 2 ):
96- all_tris .append ( [ 0 , i + 1 , i + 2 ])
97- all_tris .append ( [ last_loop , last_loop + i + 2 , last_loop + i + 1 ])
103+ all_tris .append ( [ 0 , i + 2 , i + 1 ])
104+ all_tris .append ( [ last_loop , last_loop + i + 1 , last_loop + i + 2 ])
98105
99106
100107 # Make the polyhedron
101108 a = polyhedron ( points = all_points , triangles = all_tris )
102109
103110 # Subtract the center, to remove the neck-in pieces
104111 # subtract above and below to make sure the entire screw fits within height 'length'
105- cube_side = 2 * (inner_rad + EPSILON + outline_w )
112+ cube_side = 2 * (inner_rad + outline_w )
106113 subs = union ()(
107- cylinder ( inner_rad , length ),
114+ down ( outline_h / 2 )( cylinder ( inner_rad , length + outline_h ) ),
108115 down ( cube_side / 2 )( cube ( cube_side , center = True )),
109116 up ( cube_side / 2 + length )( cube ( cube_side , center = True ))
110117 )
118+
111119 return render ()(a - subs )
112120
113121def default_thread_section ( tooth_height , tooth_depth ):
0 commit comments