Last active
October 12, 2024 06:36
-
-
Save groovenectar/92174cb1c98c1089347e to your computer and use it in GitHub Desktop.
roundedcube.scad - Fork me and make me better!
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
// More information: https://danielupshaw.com/openscad-rounded-corners/ | |
// Set to 0.01 for higher definition curves (renders slower) | |
$fs = 0.15; | |
module roundedcube(size = [1, 1, 1], center = false, radius = 0.5, apply_to = "all") { | |
// If single value, convert to [x, y, z] vector | |
size = (size[0] == undef) ? [size, size, size] : size; | |
translate_min = radius; | |
translate_xmax = size[0] - radius; | |
translate_ymax = size[1] - radius; | |
translate_zmax = size[2] - radius; | |
diameter = radius * 2; | |
obj_translate = (center == false) ? | |
[0, 0, 0] : [ | |
-(size[0] / 2), | |
-(size[1] / 2), | |
-(size[2] / 2) | |
]; | |
translate(v = obj_translate) { | |
hull() { | |
for (translate_x = [translate_min, translate_xmax]) { | |
x_at = (translate_x == translate_min) ? "min" : "max"; | |
for (translate_y = [translate_min, translate_ymax]) { | |
y_at = (translate_y == translate_min) ? "min" : "max"; | |
for (translate_z = [translate_min, translate_zmax]) { | |
z_at = (translate_z == translate_min) ? "min" : "max"; | |
translate(v = [translate_x, translate_y, translate_z]) | |
if ( | |
(apply_to == "all") || | |
(apply_to == "xmin" && x_at == "min") || (apply_to == "xmax" && x_at == "max") || | |
(apply_to == "ymin" && y_at == "min") || (apply_to == "ymax" && y_at == "max") || | |
(apply_to == "zmin" && z_at == "min") || (apply_to == "zmax" && z_at == "max") | |
) { | |
sphere(r = radius); | |
} else { | |
rotate = | |
(apply_to == "xmin" || apply_to == "xmax" || apply_to == "x") ? [0, 90, 0] : ( | |
(apply_to == "ymin" || apply_to == "ymax" || apply_to == "y") ? [90, 90, 0] : | |
[0, 0, 0] | |
); | |
rotate(a = rotate) | |
cylinder(h = diameter, r = radius, center = true); | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, I'm glad you found that. It's been a while since I've been able to design or print but was aware of some forks... would you say that's the most ideal one to redirect people to when that issue crops up? https://gist.github.com/ggs67/ff6ba8caf5a1871d285c5c758dce0575