KeithFromCanada

Hex Grid Ruler (OpenSCAD)

Jan 10th, 2022
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. //--------------------------------
  2. // Hex Grid Ruler
  3. // Keith Olson
  4. // CC 2022
  5. // OpenSCAD 2021.01
  6. //--------------------------------
  7.  
  8. // Thingiverse Customizer Docs: http://customizer.makerbot.com/docs
  9.  
  10. // OpenSCAD uses millimeters (mm) for units.
  11. // Distance functions are both for conversion and to state plainly that a number is a
  12. // measurement, not just a value.
  13. // Fractions are interpreted as formulas: '1 3/4' = '1+3/4' = 1.75
  14. function mm(x = 1) = x * 1.00000;
  15. function cm(x = 1) = x * 10.00000;
  16. function m(x = 1) = x * 1000.00000;
  17. function inches(x = 1) = x * 25.40000;
  18. function feet(x = 1) = x * 25.40000 * 12;
  19. function yards(x = 1) = x * 25.40000 * 12 * 3;
  20.  
  21. function twice(x = 1) = x * 2.00000;
  22. function half(x = 1) = x * 0.50000;
  23.  
  24. // Segments used for circles/cylinders have their endpoints on the radius. This means that
  25. // cylinders used for holes will be too small; the *midpoints* need to be on the radius,
  26. // not the *endpoints*. This function returns properly sized radjj for holes.
  27. function midpoint_radius (endpoint_radius, num_facets) = endpoint_radius / cos(360/(num_facets*2));
  28.  
  29. // OpenSCAD uses degrees (deg) for units.
  30. // Angle functions are both for conversion and to state plainly that a number is a
  31. // measurement, not just a value.
  32.  
  33. function deg(x = 1) = x;
  34. function rad(x = 1) = x * (180 / _pi);
  35.  
  36. // From current origin, returns the vector pointing to x,y,z.
  37. function rotateto(x=1,y=1,z=1) = [0,acos(z/norm([x,y,z])),atan2(y,x)];
  38.  
  39. draft_quality = 12; // [12:6:360]
  40. final_quality = 72; // [12:6:360]
  41.  
  42. // Automatically chooses quality level depending on if previewing <F5> or rendering <F6>.
  43. smoothness =$preview ? draft_quality : final_quality; // (Circles are divided in $fn line segments.)
  44. // echo($preview,smoothness);
  45. $fn = smoothness;
  46.  
  47. //--------------------------------------------------------------------------------------------
  48. /*/
  49. //*/
  50. ;
  51.  
  52. //(in mm)
  53. Hex_Width = 20; // [1:0.1:2000]
  54. //How many hexes wide (must be an even number)
  55. Hex_Count = 10; // [2:2:200]
  56. //(Should be slightly wider than the tip of the pen you'll be using.)
  57. Slot_Width = 1;
  58. Ruler_Width = Hex_Width * 1.5;
  59. Ruler_Length = Hex_Width * Hex_Count + Hex_Width * 1.5;
  60. Ruler_Thickness = 2;
  61. Hex_Height = twice(tan(60) * (Hex_Width/4));
  62. Hex_Side = half(Hex_Width);
  63.  
  64. Hex_Point_Set = [[0,0,60], // X, Y, L, A
  65. [Hex_Width*0.25,half(Hex_Height),0],
  66. [Hex_Width*0.75,half(Hex_Height),-60],
  67. [Hex_Width*1.00,0,-60],
  68. [Hex_Width*1.25,-half(Hex_Height),0],
  69. [Hex_Width*1.75,-half(Hex_Height),60]];
  70.  
  71. module drawcapsule(capsule_length = 10, capsule_width = 1, capsule_depth = 2)
  72. {
  73. translate([0,0,-half(capsule_depth)]) cylinder(d=capsule_width, h = capsule_depth);
  74. translate([0,-half(capsule_width),-half(capsule_depth)]) cube([capsule_length,capsule_width,capsule_depth]);
  75. translate([capsule_length,0,-half(capsule_depth)]) cylinder(d=capsule_width, h =capsule_depth);
  76. }
  77.  
  78. difference()
  79. {
  80. translate([Hex_Width * 0.75,half(Ruler_Width),0])
  81. difference()
  82. {
  83. translate([-half(Hex_Width * 1.50), -half(Ruler_Width),0])
  84. cube([Ruler_Length, Ruler_Width, Ruler_Thickness]);
  85.  
  86. union()
  87. {
  88. for(ii=[0:2:Hex_Count-1])
  89. {
  90. for(jj=[0:5])
  91. {
  92. translate([ii*Hex_Width+Hex_Point_Set[jj][0], Hex_Point_Set[jj][1], -1])
  93. rotate([0,0,Hex_Point_Set[jj][2]])
  94. drawcapsule(capsule_length = Hex_Side, capsule_width = Slot_Width, capsule_depth = Ruler_Thickness + 20);
  95.  
  96. }
  97. }
  98. }
  99. }
  100. //color("black")
  101. translate([Hex_Width * 0.125,Hex_Width * 0.125,half(Ruler_Thickness)])
  102. linear_extrude(height = Ruler_Thickness)
  103. text(text = str(Hex_Width,"mm"),
  104. font = "Arial:style=Black",
  105. size = Ruler_Width * 0.15);
  106. //color("black")
  107. translate([Hex_Width * 0.125,Hex_Width * 0.45,half(Ruler_Thickness)])
  108. linear_extrude(height = Ruler_Thickness)
  109. text(text = str(Hex_Count,"x"),
  110. font = "Arial:style=Black",
  111. size = Ruler_Width * 0.15);
  112. }
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131. ;
Advertisement
Add Comment
Please, Sign In to add comment