UltimateCodeWarrior

Untitled

Sep 11th, 2024
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. // Load the threads-scad library
  2. include <threads-scad/threads.scad>;
  3.  
  4.  
  5. $fn = $preview ? 64:360;
  6.  
  7. //$fn = 100; // Increase to smooth the sphere and cylinder
  8.  
  9. // Parameters
  10. sphere_radius = 100; // Radius of the main sphere
  11. cut_percentage = 0.3; // 30% cut for Part B
  12. thread_depth = 150; // Depth of the thread in Part B (15 cm)
  13. thread_pitch = 20; // Pitch for the threads
  14. cylinder_height = 150; // Height of the cylinder in Part A (15 cm)
  15. wall_thickness = 50; // Minimum wall thickness of Part B (5 cm)
  16.  
  17.  
  18. // Bezel Threads
  19. bezel_diameter = 170;
  20. bezel_thread_length = 15;
  21. bezel_thread_pitch = 5;
  22. bezel_pipe_diameter = bezel_diameter-30;
  23.  
  24.  
  25.  
  26.  
  27. // Part A: Solid sphere with a cut for the threaded cylinder
  28. module part_A() {
  29. difference() {
  30. // Full solid sphere
  31. sphere(r = sphere_radius);
  32.  
  33. // Cut off the front 30% of the sphere for Part B
  34. translate([0, 0, -sphere_radius * (1 - cut_percentage)])
  35. cylinder(h = sphere_radius * 2 * cut_percentage, r = sphere_radius + 1, center = true);
  36.  
  37. sphere (r = sphere_radius-15);
  38.  
  39. }
  40. // Add threaded cylinder petruding from spere
  41. translate([0, 0, -50])
  42. threaded_cylinder();
  43. }
  44.  
  45. // Part B: Front 30% of the sphere, with an internal thread
  46. module part_B() {
  47. // Cut-away part of the sphere with internal threading
  48. difference() {
  49. // Front 30% of the sphere
  50. translate([0, 0, -sphere_radius * cut_percentage])
  51. sphere(r = sphere_radius);
  52.  
  53. // Hollow out the inside, maintaining a 5 cm wall thickness
  54. translate([0, 0, -sphere_radius * cut_percentage])
  55. sphere(r = sphere_radius - wall_thickness);
  56.  
  57. // Cut off the back of the bezel so that only 30% of the sphere is left
  58. translate([0, 0, -sphere_radius * (1 - cut_percentage)])
  59. cube([sphere_radius * 2, sphere_radius * 2, sphere_radius * 2], center = true);
  60.  
  61. // Carve the threads into Part B
  62. translate([0, 0, 0])
  63. threaded_hole();
  64. }
  65. }
  66.  
  67. // Module to create the threaded cylinder that protrudes from Part A
  68. module threaded_cylinder() {
  69. // Outer threaded cylinder
  70. difference() {
  71. RodStart(bezel_diameter, 0,bezel_thread_length,bezel_diameter,bezel_thread_pitch);
  72. // Hollow interior of the cylinder
  73. translate([0, 0, -25])
  74. cylinder(h = 50, r = bezel_pipe_diameter/2, center = false);
  75. }
  76. }
  77.  
  78.  
  79.  
  80. // Module to create internal threads in Part B
  81. module threaded_hole() {
  82. RodEnd(bezel_diameter+20,bezel_thread_length,bezel_thread_length,bezel_diameter,bezel_thread_pitch);
  83. }
  84.  
  85. // Render the final model
  86. translate([-150, 0, 0]) part_A(); // Move Part A to the left
  87. translate([150, 0, 0]) part_B(); // Move Part B to the right
  88.  
  89.  
  90.  
  91. //module RodStart(diameter, height, thread_len=0, thread_diam=0, thread_pitch=0)
  92. translate([70, -10, 0])
  93. RodStart(bezel_diameter, 0,bezel_thread_length,bezel_diameter,bezel_thread_pitch);
  94. translate([250, 20, 0])
  95. RodEnd(bezel_diameter+20,bezel_thread_length,bezel_thread_length,bezel_diameter,bezel_thread_pitch);
  96.  
  97.  
Tags: Turret
Advertisement
Add Comment
Please, Sign In to add comment