Last active
September 18, 2017 12:32
-
-
Save fragmuffin/266bee4babd9a25aea2d53c739144ee3 to your computer and use it in GitHub Desktop.
CadQuery thread (method not recommended)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cadquery | |
from Helpers import show | |
helical_radius = 6.0 | |
core_radius = 4.0 | |
pitch = 2.0 # length per revolution | |
length = 12.0 | |
def helical_path(p, l, r): | |
wire = cadquery.Wire.makeHelix(p, l, r, angle=0) | |
shape = cadquery.Wire.combine([wire]) | |
path = cadquery.Workplane("XY").newObject([shape]) | |
return path | |
# Inverted Thread profile | |
# FIXME: thread model must extend past helical_radius to make a clean cut | |
points = [ | |
(0.5 * pitch, helical_radius * 1.01), | |
(0, core_radius), | |
(-0.5 * pitch, helical_radius * 1.01), | |
] | |
# Inverted Thread: a single turn, around world origin | |
single_turn = helical_path(pitch, pitch, helical_radius).translate((0, 0, -pitch / 2)) | |
inv_thread = cadquery.Workplane("ZX").center(-pitch / 2., 0) \ | |
.moveTo(*points[0]).polyline(points[1:]).close() \ | |
.sweep(single_turn, isFrenet=True) | |
# cross-section face of thread (at origin) | |
cross_section = cadquery.Workplane("XY").workplane(offset=-pitch / 2.) \ | |
.circle(helical_radius).extrude(pitch / 2.) \ | |
.cut(inv_thread).faces(">Z") | |
cross_section_face = cross_section.val() # cadquery.Face | |
cross_section_wire = cross_section_face.Wires().pop() # cadquery.Wire | |
cross_section_wire.forConstruction = False | |
# Thread created from profile sweep | |
full_helix = helical_path(pitch, length, helical_radius) | |
my_model = cadquery.Workplane("XY").box(1,1,1) | |
my_model._addPendingWire(cross_section_wire) # FIXME: using private function | |
my_model.sweep(full_helix, isFrenet=True) | |
# Use the following to render your model with grey RGB and no transparency | |
#show(cross_section) | |
show(my_model, (204, 204, 204, 0.5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@dcowden: my reply in #195