Last active
April 13, 2023 21:10
-
-
Save RagingRoosevelt/61150d0830d1952b99dd8225b76722da to your computer and use it in GitHub Desktop.
fan grill with hexagon cut pattern
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
if "show_object" not in locals(): | |
from cq_server.ui import ui, show_object | |
from fnmatch import translate | |
from os import link | |
import cadquery as cq | |
from math import cos, sin, tan, radians as rad, floor, ceil | |
from collections import namedtuple | |
DimsCube = namedtuple('DimsCube', ['l', 'w', 't']) | |
DimsCirc = namedtuple('DimsCirc', ['d', 't']) | |
DimsScrew = namedtuple('DimsScrew',['d','l','h_d','h_l']) | |
overall_size = 60 | |
d_hole_spacing = 50 | |
d_padding = (overall_size-d_hole_spacing)/2 | |
d_screw = DimsScrew(3.5,30,7,10) | |
d_box = DimsCube(d_hole_spacing+d_screw.d+2*d_padding,d_hole_spacing+d_screw.d+2*d_padding,2) | |
d_hex = 2.4 | |
d_hex_pad = 1.2 | |
# http://blog.ruslans.com/2011/02/hexagonal-grid-math.html | |
_hex_s = (3/2) * (d_hex+d_hex_pad)/2 | |
_hex_h = (d_hex+d_hex_pad)/2 * (3**0.5) | |
hex_pos = lambda r,c: (c*_hex_s, r*_hex_h if c%2==0 else r*_hex_h+_hex_h/2) | |
num_mesh_holes = 0.5*d_hole_spacing/d_hex | |
mesh = ( | |
cq | |
.Workplane("top") | |
.box(d_box.l,d_box.w,d_box.t,centered=(True,True,False)) | |
.pushPoints([ | |
(x*d_hole_spacing/2,y*d_hole_spacing/2) | |
for x,y in [(1,1),(-1,1),(1,-1),(-1,-1)] | |
]) | |
.circle(d_screw.d/2) | |
.cutThruAll() | |
.edges('|Y') | |
.fillet(d_screw.h_d) | |
) | |
hex_grid = ( | |
cq | |
.Workplane("top") | |
.box(100,100,3,centered=(True,True,False)) | |
.pushPoints([ | |
hex_pos(r,c) | |
for r in range(-floor(num_mesh_holes),ceil(num_mesh_holes)) | |
for c in range(-floor(num_mesh_holes),ceil(num_mesh_holes)) | |
]) | |
.polygon(6,d_hex) | |
.cutThruAll() | |
# .cutThruAll() | |
) | |
hex_grid = ( | |
cq | |
.Workplane("top") | |
.box(d_hole_spacing-d_padding,d_hole_spacing-d_padding,d_box.t, centered=(True,True,False)) | |
.edges('|Y') | |
.fillet(d_screw.d) | |
.cut(hex_grid) | |
) | |
mesh = ( | |
mesh | |
.cut(hex_grid) | |
.edges('(>Y) or (<Y)') | |
.chamfer(0.3) | |
) | |
show_object(mesh) | |
cq.exporters.export( | |
mesh, | |
f"fan_grill_{overall_size}mm.stl" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment