Skip to content

Commit edea386

Browse files
fix for issue SolidCode#92; neck_out_degrees wasn't used properly, and could cause division by zero
1 parent dbd1991 commit edea386

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

solid/examples/screw_thread_example.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717

1818
def assembly():
1919
section = screw_thread.default_thread_section(tooth_height=10, tooth_depth=5)
20-
s = screw_thread.thread(outline_pts=section, inner_rad=inner_rad,
21-
pitch=screw_height, length=screw_height, segments_per_rot=SEGMENTS)
22-
#, neck_in_degrees=90, neck_out_degrees=90)
20+
s = screw_thread.thread(outline_pts=section,
21+
inner_rad=inner_rad,
22+
pitch=screw_height,
23+
length=screw_height,
24+
segments_per_rot=SEGMENTS,
25+
neck_in_degrees=90,
26+
neck_out_degrees=90)
2327

2428
c = cylinder(r=inner_rad, h=screw_height)
2529
return s + c

solid/screw_thread.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
solid.patch_euclid.run_patch()
1515

1616

17-
def thread(outline_pts, inner_rad, pitch, length, external=True, segments_per_rot=32, neck_in_degrees=0, neck_out_degrees=0):
17+
def thread(outline_pts, inner_rad, pitch, length, external=True,
18+
segments_per_rot=32, neck_in_degrees=0, neck_out_degrees=0):
1819
'''Sweeps outline_pts (an array of points describing a closed polygon in XY)
1920
through a spiral.
2021
@@ -51,7 +52,7 @@ def thread(outline_pts, inner_rad, pitch, length, external=True, segments_per_ro
5152
doing to make the neck-in work as well. Not sure how the two approaches
5253
compare in terms of render-time. -ETJ 16 Mar 2011
5354
54-
NOTE: if pitch is less than the or equal to the height of each tooth (outline_pts),
55+
NOTE: if pitch is less than or equal to the height of each tooth (outline_pts),
5556
OpenSCAD will likely crash, since the resulting screw would self-intersect
5657
all over the place. For screws with essentially no space between
5758
threads, (i.e., pitch=tooth_height), I use pitch= tooth_height+EPSILON,
@@ -107,9 +108,9 @@ def thread(outline_pts, inner_rad, pitch, length, external=True, segments_per_ro
107108
int_ext_mult = 1 if external else -1
108109
neck_in_rad = min_rad if external else max_rad
109110

110-
if angle < neck_in_degrees:
111+
if neck_in_degrees != 0 and angle < neck_in_degrees:
111112
rad = neck_in_rad + int_ext_mult * angle / neck_in_degrees * outline_w
112-
elif angle > total_angle - neck_in_degrees:
113+
elif neck_out_degrees != 0 and angle > total_angle - neck_out_degrees:
113114
rad = neck_in_rad + int_ext_mult * (total_angle - angle) / neck_out_degrees * outline_w
114115

115116
elev_vec = Vector3(rad, 0, elevation)

0 commit comments

Comments
 (0)