Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeicor committed Jan 8, 2024
1 parent 3116071 commit b3963b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Prepare the stem_wrapper
with BuildPart() as stem_wrapper:
with BuildSketch(Plane.front): # as cross_section
RectangleRounded(stem_width + 2 * wall, stem_height + 2 * wall, wall)
RectangleRounded(stem_width + 2 * wall, stem_height + 2 * wall, wall/2 - eps)
RectangleRounded(stem_width, stem_height, stem_fillet - wall, mode=Mode.SUBTRACT)
extrude(amount=stem_length/2, both=True)
fillet(faces().filter_by(Plane.XY).edges(), wall/2 - eps)
Expand All @@ -25,7 +25,7 @@
# Prepare the screw hole adapter
screw_hole_base = ScrewableCylinder()
bb = screw_hole_base.bounding_box()
eps_offset_loft = 0.01
eps_offset_loft = 0.1 # Causes broken geometry if too small
RigidJoint("left", screw_hole_base, Location((bb.min.X - eps_offset_loft, bb.center().Y, bb.center().Z), (0, 90, 0)))

with BuildPart() as core:
Expand All @@ -46,24 +46,27 @@
del loft_screw_hole_face, loft_stem_face, screw_hole_base

# Make it 3D printable by adding top and bottom supports
for face_side in [-1, 1]: # Top and bottom
face = faces().group_by(Axis.Z)[0 if face_side < 0 else -1].face()
for face_side in [-1, 1]: # Bottom and top
face_search = 0 if face_side < 0 else -1
face = faces().group_by(Axis.Z)[face_search].face()
extreme = stem_wrapper.bounding_box().min if face_side < 0 else stem_wrapper.bounding_box().max
extreme.Z += face_side * -(wall - eps_offset_loft*10) # Ignore fillet
extreme.Z -= face_side * wall/2 # Ignore fillet
max_extrude = face.center().Z - extreme.Z
extrude(face, amount=abs(max_extrude))
assert core.part.is_valid()
del extreme
# Prepare a cut plane
max_offset = face.bounding_box().size.X
cut_plane_angle = degrees(atan2(max_offset, max_extrude))
cut_plane_angle = degrees(atan2(max_extrude, max_offset))
print(cut_plane_angle)
bb = face.bounding_box()
cut_plane = Plane(Location((bb.max.X, bb.center().Y, bb.center().Z), (0, -cut_plane_angle, 0)))
split(bisect_by=cut_plane, keep=Keep.TOP)
split(bisect_by=cut_plane, keep=Keep.TOP if face_side < 0 else Keep.BOTTOM)
assert core.part.is_valid()
assert len(core.part.solids()) == 1
del face, cut_plane
# Fillet some edges of supports
fillet(faces().group_by(Axis.Z)[face_search].edges() - edges().group_by(Axis.X)[0], wall/2.01)

# Mirror to the other side
mirror(about=Plane.YZ)
Expand Down
2 changes: 1 addition & 1 deletion src/screwable_cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@dataclass(kw_only=True)
class ScrewableCylinder(BasePartObject):
screw_length: float = 8
screw_length: float = 12
screw_diameter: float = 5 # M5
screw_head_diameter: float = 8.5 # M5
screw_head_height: float = 5 # M5
Expand Down

0 comments on commit b3963b1

Please sign in to comment.