Created
November 6, 2024 20:55
-
-
Save niteria/6e16fd2efb703b405893caed489e297f to your computer and use it in GitHub Desktop.
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
from build123d import * | |
from build123d_draft import * | |
import math | |
def make_hinge(center, # hinge around this point | |
dia, # outer diameter of the hinge round part | |
total_height, # | |
pin_dia=None, # diameter of the hinge pin | |
vertical_clearance=0.5, # clearance in Z axis | |
horizontal_clearance = 0.5, # clearance in X, Y axes | |
side_cut=5, # extra material to cut from the side of the hinge | |
no_pin=False, # create with out a pin | |
inner_flaps = 1 # determines number of total layers: 1 + 2*inner_flaps | |
): | |
if pin_dia is None: | |
pin_dia = dia / 2 | |
slice_height = (total_height - 2 * inner_flaps * vertical_clearance) / (1 + 2 *inner_flaps) | |
def rounded_with_pin(topf, height=slice_height): | |
with BuildSketch(topf) as sketch: | |
Rectangle(dia/2+horizontal_clearance, dia+horizontal_clearance+side_cut, | |
align=(Align.MAX, Align.CENTER)) | |
extrude(to_extrude=sketch.sketch, amount=height, mode=Mode.SUBTRACT) | |
with BuildSketch(topf) as sketch: | |
Circle(d=dia) | |
return extrude(to_extrude=sketch.sketch, amount=height) | |
def pin_only(topf, height=vertical_clearance): | |
with BuildSketch(topf) as sketch: | |
Rectangle(dia+horizontal_clearance*2, dia+horizontal_clearance*2+10) | |
extrude(to_extrude=sketch.sketch, amount=height, mode=Mode.SUBTRACT) | |
with BuildSketch(topf) as sketch: | |
Circle(d=pin_dia) | |
return extrude(to_extrude=sketch.sketch, amount=height) | |
def rotating_around_pin(topf, height=slice_height): | |
with BuildSketch(topf) as sketch: | |
Rectangle(dia/2+horizontal_clearance, dia+horizontal_clearance+side_cut, | |
align=(Align.MIN, Align.CENTER)) | |
extrude(to_extrude=sketch.sketch, amount=height, mode=Mode.SUBTRACT) | |
with BuildSketch(topf) as sketch: | |
Circle(d=dia) | |
extrude(to_extrude=sketch.sketch, amount=height) | |
with BuildSketch(topf) as sketch: | |
Circle(d=pin_dia+horizontal_clearance) | |
extrude(to_extrude=sketch.sketch, amount=height, mode=Mode.SUBTRACT) | |
with BuildSketch(topf) as sketch: | |
Circle(d=pin_dia) | |
return extrude(to_extrude=sketch.sketch, amount=height) | |
# first layer | |
r = rounded_with_pin(Plane.XY.shift_origin(center)) | |
for _ in range(0, inner_flaps): | |
# second layer (pin) | |
r = pin_only(r.faces().sort_by(Axis.Z)[-1]) | |
# third layer | |
r = rotating_around_pin(r.faces().sort_by(Axis.Z)[-1]) | |
# fourth layer (same as 2nd) | |
r = pin_only(r.faces().sort_by(Axis.Z)[-1]) | |
# 5th layer (same as 1st) | |
r = rounded_with_pin(r.faces().sort_by(Axis.Z)[-1]) | |
if no_pin: | |
with BuildSketch() as sketch: | |
with Locations(center): | |
Circle(d=pin_dia) | |
extrude(to_extrude=sketch.sketch, amount=total_height, mode=Mode.SUBTRACT) | |
w, h, l = 20, 20, 80 | |
with BuildPart() as part: | |
with BuildSketch() as sketch: | |
Rectangle(l, w) | |
extrude(amount=h) | |
make_hinge((0, 0), dia=w, total_height=h, inner_flaps=2) | |
show_object(part.part) |
Author
niteria
commented
Nov 6, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment