Created
February 4, 2025 22:42
-
-
Save derhuerst/bf5374febe2d7c09f0b7651f3160b9c9 to your computer and use it in GitHub Desktop.
cheese grater pattern in build123d
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 logging | |
import math | |
from build123d import * | |
logging.basicConfig(level=logging.WARN) | |
from yacv_server import show | |
# %% | |
hole_diameter = 20 | |
board_x, board_y = 400, 120 | |
board_thickness = hole_diameter * (0.5 + 0.1) | |
board_holes_margin_x, board_holes_margin_y = 60, 20 | |
board = extrude( | |
Rectangle(board_x, board_y), | |
amount=board_thickness, | |
) | |
board_bottom_plane = Plane(board.faces().sort_by(Axis.Z).first) | |
board_top_plane = Plane(board.faces().sort_by(Axis.Z).last) | |
hole_x_spacing = hole_diameter * 23 / 20 | |
hole_y_spacing = hole_diameter * 1.0 | |
holes_x_count = math.floor((board_x - 2 * board_holes_margin_x) / hole_x_spacing) | |
holes_y_count = math.floor((board_y - 2 * board_holes_margin_y) / hole_y_spacing) | |
hole = Sphere(hole_diameter / 2) | |
holes_b_row_x_offset = hole_diameter * 11.5 / 20 | |
holes_b_row_y_offset = hole_diameter | |
def HolesCenters(plane, x_count = holes_x_count, y_count = holes_y_count): | |
holes_centers_a = [ | |
plane | |
* hole_center | |
for hole_center in GridLocations( | |
x_spacing=hole_x_spacing, | |
y_spacing=hole_y_spacing * 2, | |
x_count=x_count, | |
y_count=math.ceil(y_count / 2), | |
align=(Align.MIN, Align.MIN) | |
) | |
] | |
holes_centers_b = [ | |
plane | |
* Pos(holes_b_row_x_offset, holes_b_row_y_offset, 0) | |
* hole_center | |
for hole_center in GridLocations( | |
x_spacing=hole_x_spacing, | |
y_spacing=hole_y_spacing * 2, | |
x_count=x_count, | |
y_count=math.floor(y_count / 2), | |
align=(Align.MIN, Align.MIN) | |
) | |
] | |
return holes_centers_a + holes_centers_b | |
holes_top_x_offset = board_x * -.5 + board_holes_margin_x + hole_x_spacing * .5 | |
holes_top_y_offset = board_y * -.5 + board_holes_margin_y + hole_y_spacing * .5 | |
holes_top_plane = board_top_plane.move(Pos( | |
holes_top_x_offset, | |
holes_top_y_offset, | |
0 | |
)) | |
top_holes = [ | |
hole_center | |
* hole | |
for hole_center in HolesCenters(holes_top_plane) | |
] | |
holes_bottom_x_offset = holes_top_x_offset - holes_b_row_x_offset | |
holes_bottom_y_offset = holes_top_y_offset - hole_diameter * 7 / 20 | |
holes_bottom_z_offset = hole_diameter * 12 / 20 | |
holes_bottom_plane = board_top_plane.move(Pos( | |
holes_bottom_x_offset, | |
holes_bottom_y_offset, | |
-holes_bottom_z_offset, | |
)) | |
bottom_holes = [ | |
hole_center | |
* hole | |
for hole_center in HolesCenters(holes_bottom_plane, holes_x_count + 1, holes_y_count + 1) | |
] | |
model = board - top_holes - bottom_holes | |
show(model) | |
# %% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment