My self-made 3D-printable designs, mainly in OpenSCAD
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

roundedcube.scad 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Higher definition curves
  2. $fs = 0.01;
  3. module roundedcube(size = [1, 1, 1], center = false, radius = 0.5, apply_to = "all") {
  4. // If single value, convert to [x, y, z] vector
  5. size = (size[0] == undef) ? [size, size, size] : size;
  6. translate_min = radius;
  7. translate_xmax = size[0] - radius;
  8. translate_ymax = size[1] - radius;
  9. translate_zmax = size[2] - radius;
  10. diameter = radius * 2;
  11. module build_point(type = "sphere", rotate = [0, 0, 0]) {
  12. if (type == "sphere") {
  13. sphere(r = radius);
  14. } else if (type == "cylinder") {
  15. rotate(a = rotate)
  16. cylinder(h = diameter, r = radius, center = true);
  17. }
  18. }
  19. obj_translate = (center == false) ?
  20. [0, 0, 0] : [
  21. -(size[0] / 2),
  22. -(size[1] / 2),
  23. -(size[2] / 2)
  24. ];
  25. translate(v = obj_translate) {
  26. hull() {
  27. for (translate_x = [translate_min, translate_xmax]) {
  28. x_at = (translate_x == translate_min) ? "min" : "max";
  29. for (translate_y = [translate_min, translate_ymax]) {
  30. y_at = (translate_y == translate_min) ? "min" : "max";
  31. for (translate_z = [translate_min, translate_zmax]) {
  32. z_at = (translate_z == translate_min) ? "min" : "max";
  33. translate(v = [translate_x, translate_y, translate_z])
  34. if (
  35. (apply_to == "all") ||
  36. (apply_to == "xmin" && x_at == "min") || (apply_to == "xmax" && x_at == "max") ||
  37. (apply_to == "ymin" && y_at == "min") || (apply_to == "ymax" && y_at == "max") ||
  38. (apply_to == "zmin" && z_at == "min") || (apply_to == "zmax" && z_at == "max")
  39. ) {
  40. build_point("sphere");
  41. } else {
  42. rotate =
  43. (apply_to == "xmin" || apply_to == "xmax" || apply_to == "x") ? [0, 90, 0] : (
  44. (apply_to == "ymin" || apply_to == "ymax" || apply_to == "y") ? [90, 90, 0] :
  45. [0, 0, 0]
  46. );
  47. build_point("cylinder", rotate);
  48. }
  49. }
  50. }
  51. }
  52. }
  53. }
  54. }