Created
January 16, 2024 01:07
-
-
Save lf94/b09ea73281a6497f403c4da53fb8ad4a to your computer and use it in GitHub Desktop.
weird.py
This file contains hidden or 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 as cq | |
# Parameters for the cylinder | |
cylinder_height = 50.0 | |
cylinder_radius = 20.0 | |
# Parameters for the rectangular cutouts | |
cutout_width = 5.0 | |
cutout_height = 10.0 | |
cutout_depth = 10.0 | |
# Create the base cylinder | |
cylinder = cq.Workplane("XY").cylinder(cylinder_height, cylinder_radius) | |
# Define a function to create a single rectangular cutout | |
def make_cutout(workplane, width, height, depth, offset_angle): | |
# Create a rectangular prism for the cutout | |
cutout = ( | |
workplane | |
.workplane(offset=cylinder_height/2 - depth/2) | |
.transformed(rotate=(0, 0, offset_angle)) | |
.center(cylinder_radius, 0) | |
.rect(width, height) | |
.extrude(depth, True) | |
) | |
return cutout | |
# Create four cutouts at 0, 90, 180, and 270 degrees | |
for angle in range(0, 360, 90): | |
cutout = make_cutout(cq.Workplane("XY"), cutout_width, cutout_height, cutout_depth, angle) | |
cylinder = cylinder.cut(cutout) | |
# Final result | |
result = cylinder | |
# Export the result to a STEP file | |
cq.exporters.export(result, "/tmp/bed89d2d-cdf2-4d0b-9879-4740a28f732c.step") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment