Advertisement
sinned6915

thread library

Mar 9th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.39 KB | None | 0 0
  1.  
  2. function norm(vector) = sqrt(vector[0]*vector[0]+vector[1]*vector[1]+vector[2]*vector[2]);
  3.  
  4. function unitVector(vector) = vector / norm ( vector );
  5.  
  6. function barycenter(vector1, vector2, ratio) = (vector1*ratio + vector2*(1-ratio) );
  7.  
  8. module slice(
  9. AShaftBottom,
  10. AShaftTop,
  11. BShaftBottom,
  12. BShaftTop,
  13. ABottom,
  14. ATop,
  15. BBottom,
  16. BTop,
  17. AThreadDepth,
  18. AThreadRatio=0.5,
  19. AThreadPosition=0.5,
  20. AThreadAngle=20,
  21. BThreadDepth,
  22. BThreadRatio=0.5,
  23. BThreadPosition=0.5,
  24. BThreadAngle=20,
  25. showVertices=false
  26. )
  27. {
  28. polyPoints=[
  29. AShaftBottom,
  30. AShaftTop,
  31. ATop,
  32. barycenter(ATop,ABottom,AThreadPosition+AThreadRatio/2) + unitVector(ATop-ABottom)*AThreadDepth/2*tan(AThreadAngle),
  33. barycenter(ATop,ABottom,AThreadPosition+AThreadRatio/2) - unitVector(ATop-ABottom)*AThreadDepth/2*tan(AThreadAngle) + unitVector(ATop-AShaftTop)*AThreadDepth,
  34. barycenter(ATop,ABottom,AThreadPosition),
  35. barycenter(ATop,ABottom,AThreadPosition-AThreadRatio/2) + unitVector(ATop-ABottom)*AThreadDepth/2*tan(AThreadAngle) + unitVector(ATop-AShaftTop)*AThreadDepth,
  36. barycenter(ATop,ABottom,AThreadPosition-AThreadRatio/2) - unitVector(ATop-ABottom)*AThreadDepth/2*tan(AThreadAngle),
  37. ABottom,
  38. BTop,
  39. barycenter(BTop,BBottom,BThreadPosition+BThreadRatio/2) + unitVector(BTop-BBottom)*BThreadDepth/2*tan(BThreadAngle),
  40. barycenter(BTop,BBottom,BThreadPosition+BThreadRatio/2) - unitVector(BTop-BBottom)*BThreadDepth/2*tan(BThreadAngle) + unitVector(BTop-BShaftTop)*BThreadDepth,
  41. barycenter(BTop,BBottom,BThreadPosition),
  42. barycenter(BTop,BBottom,BThreadPosition-BThreadRatio/2) + unitVector(BTop-BBottom)*BThreadDepth/2*tan(BThreadAngle) + unitVector(BTop-BShaftTop)*BThreadDepth,
  43. barycenter(BTop,BBottom,BThreadPosition-BThreadRatio/2) - unitVector(BTop-BBottom)*BThreadDepth/2*tan(BThreadAngle),
  44. BBottom,
  45. BShaftBottom,
  46. BShaftTop
  47. ];
  48.  
  49. polyTriangles=[
  50. [ 0,1,5], [1,2,3], [1,3,5], [0,5,7], [0,7,8], //A side of shaft
  51. [1,0,12], [1,10,9], [1,12,10], [0,14,12], [0,15,14], // B side of shaft
  52. [0,8,15], // bottom of shaft
  53. [1,9,2], // top of shaft
  54. [3,2,10], [2,9,10], [4,3,10], [10,11,4], // top of thread
  55. [6,4,11], [11,13,6], // tip of thread
  56. [7,6,13], [13,14,7], [8,7,14], [14,15,8], // bottom of thread
  57. [3,4,5], [5,4,6], [5,6,7], // A side of thread
  58. [11,10,12], [11,12,13], [12,14,13] // B side of thread
  59. ];
  60.  
  61. if (showVertices==true) for (i=[0:15]) translate(polyPoints[i]) color([1,0.5,0.5]) cube(0.25,true);
  62.  
  63. polyhedron( polyPoints, polyTriangles );
  64. }
  65.  
  66. module trapezoidThread(
  67. length=45, // axial length of the threaded rod
  68. pitch=10, // axial distance from crest to crest
  69. pitchRadius=10, // radial distance from center to mid-profile
  70. threadHeightToPitch=0.5, // ratio between the height of the profile and the pitch
  71. // std value for Acme or metric lead screw is 0.5
  72. profileRatio=0.5, // ratio between the lengths of the raised part of the profile and the pitch
  73. // std value for Acme or metric lead screw is 0.5
  74. threadAngle=30, // angle between the two faces of the thread
  75. // std value for Acme is 29 or for metric lead screw is 30
  76. RH=true, // true/false the thread winds clockwise looking along shaft, i.e.follows the Right Hand Rule
  77. clearance=0.1, // radial clearance, normalized to thread height
  78. backlash=0.1, // axial clearance, normalized to pitch
  79. stepsPerTurn=24, // number of slices to create per turn,
  80. showVertices=false
  81. )
  82. {
  83.  
  84. numberTurns=length/pitch-1;
  85.  
  86. steps=stepsPerTurn*numberTurns;
  87.  
  88. startLength=0.25; // number of turns for profile to reach full height
  89.  
  90. function profileRatio(i)= profileRatio*(1-backlash);
  91.  
  92. function threadAngle(i)= threadAngle;
  93.  
  94. function threadPosition(i)= ( profileRatio(i) + threadHeightToPitch*(1+clearance)*tan( threadAngle(i) ) )/2;
  95.  
  96. function threadHeight(i)= pitch*threadHeightToPitch*(1+clearance);
  97.  
  98. function pitchRadius(i)= pitchRadius;
  99. function minorRadius(i)= pitchRadius(i)-(0.5+clearance)*pitch*threadHeightToPitch;
  100.  
  101. function ShaftX(i)= 0;
  102. function ShaftY(i)= 0;
  103. function ShaftZ(i)= pitch*numberTurns*i;
  104.  
  105. function X(i)= ShaftX(i)+minorRadius(i)*cos(i*360*numberTurns);
  106. function Y(i)= ShaftY(i)+minorRadius(i)*sin(i*360*numberTurns);
  107. function Z(i)= ShaftZ(i);
  108.  
  109. if (RH==true)
  110. for (i=[0:steps-1])
  111. {
  112. slice(
  113. AShaftBottom= [ShaftX(i/steps), ShaftY(i/steps), ShaftZ(i/steps) ],
  114. AShaftTop= [ShaftX((i+stepsPerTurn)/steps), ShaftY((i+stepsPerTurn)/steps), ShaftZ((i+stepsPerTurn)/steps) ],
  115. BShaftBottom= [ShaftX((i+1)/steps), ShaftY((i+1)/steps), ShaftZ((i+1)/steps) ],
  116. BShaftTop= [ShaftX((i+1+stepsPerTurn)/steps), ShaftY((i+1+stepsPerTurn)/steps), ShaftZ((i+1+stepsPerTurn)/steps) ],
  117. ABottom= [X(i/steps), Y(i/steps), Z(i/steps) ],
  118. ATop= [X((i+stepsPerTurn)/steps), Y((i+stepsPerTurn)/steps), Z((i+stepsPerTurn)/steps) ],
  119. BBottom= [X((i+1)/steps), Y((i+1)/steps), Z((i+1)/steps) ],
  120. BTop= [X((i+1+stepsPerTurn)/steps), Y((i+1+stepsPerTurn)/steps), Z((i+1+stepsPerTurn)/steps) ],
  121.  
  122. AThreadDepth= min(min(i,steps-i)/stepsPerTurn/startLength,1)*threadHeight(i),
  123. AThreadRatio= min(min(i,steps-i)/stepsPerTurn/startLength,1)*profileRatio(i),
  124. AThreadPosition= threadPosition(i),
  125. AThreadAngle= threadAngle(i),
  126.  
  127. BThreadDepth= min(min(i+1,steps-i-1)/stepsPerTurn/startLength,1)*threadHeight(i+1),
  128. BThreadRatio= min(min(i+1,steps-i-1)/stepsPerTurn/startLength,1)*profileRatio(i+1),
  129. BThreadPosition= threadPosition(i),
  130. BThreadAngle= threadAngle(i+1),
  131. showVertices=showVertices
  132. );
  133. }
  134.  
  135. if (RH==false)
  136. mirror([0,1,0])
  137. for (i=[0:steps-1])
  138. {
  139. slice(
  140. AShaftBottom= [ShaftX(i/steps), ShaftY(i/steps), ShaftZ(i/steps) ],
  141. AShaftTop= [ShaftX((i+stepsPerTurn)/steps), ShaftY((i+stepsPerTurn)/steps), ShaftZ((i+stepsPerTurn)/steps) ],
  142. BShaftBottom= [ShaftX((i+1)/steps), ShaftY((i+1)/steps), ShaftZ((i+1)/steps) ],
  143. BShaftTop= [ShaftX((i+1+stepsPerTurn)/steps), ShaftY((i+1+stepsPerTurn)/steps), ShaftZ((i+1+stepsPerTurn)/steps) ],
  144. ABottom= [X(i/steps), Y(i/steps), Z(i/steps) ],
  145. ATop= [X((i+stepsPerTurn)/steps), Y((i+stepsPerTurn)/steps), Z((i+stepsPerTurn)/steps) ],
  146. BBottom= [X((i+1)/steps), Y((i+1)/steps), Z((i+1)/steps) ],
  147. BTop= [X((i+1+stepsPerTurn)/steps), Y((i+1+stepsPerTurn)/steps), Z((i+1+stepsPerTurn)/steps) ],
  148.  
  149. AThreadDepth= min(min(i,steps-i)/stepsPerTurn/startLength,1)*threadHeight(i),
  150. AThreadRatio= min(min(i,steps-i)/stepsPerTurn/startLength,1)*profileRatio(i),
  151. AThreadPosition= threadPosition(i),
  152. AThreadAngle= threadAngle(i),
  153.  
  154. BThreadDepth= min(min(i+1,steps-i-1)/stepsPerTurn/startLength,1)*threadHeight(i+1),
  155. BThreadRatio= min(min(i+1,steps-i-1)/stepsPerTurn/startLength,1)*profileRatio(i+1),
  156. BThreadPosition= threadPosition(i),
  157. BThreadAngle= threadAngle(i+1),
  158. showVertices=showVertices
  159. );
  160. }
  161.  
  162. rotate([0,0,180/stepsPerTurn])
  163. cylinder(
  164. h=pitch,
  165. r1=0.999*pitchRadius-(0.5+clearance)*pitch*threadHeightToPitch,
  166. r2=0.999*pitchRadius-(0.5+clearance)*pitch*threadHeightToPitch,$fn=stepsPerTurn);
  167.  
  168. translate([0,0,length-pitch])
  169. rotate([0,0,180/stepsPerTurn])
  170. cylinder(
  171. h=pitch,
  172. r1=0.999*pitchRadius-(0.5+clearance)*pitch*threadHeightToPitch,
  173. r2=0.999*pitchRadius-(0.5+clearance)*pitch*threadHeightToPitch,$fn=stepsPerTurn);
  174. }
  175.  
  176. module trapezoidThreadNegativeSpace(
  177. length=45, // axial length of the threaded rod
  178. pitch=10, // axial distance from crest to crest
  179. pitchRadius=10, // radial distance from center to mid-profile
  180. threadHeightToPitch=0.5, // ratio between the height of the profile and the pitch
  181. // std value for Acme or metric lead screw is 0.5
  182. profileRatio=0.5, // ratio between the lengths of the raised part of the profile and the pitch
  183. // std value for Acme or metric lead screw is 0.5
  184. threadAngle=30, // angle between the two faces of the thread
  185. // std value for Acme is 29 or for metric lead screw is 30
  186. RH=true, // true/false the thread winds clockwise looking along shaft, i.e.follows the Right Hand Rule
  187. countersunk=0, // depth of 45 degree chamfered entries, normalized to pitch
  188. clearance=0.1, // radial clearance, normalized to thread height
  189. backlash=0.1, // axial clearance, normalized to pitch
  190. stepsPerTurn=24 // number of slices to create per turn
  191. )
  192. {
  193.  
  194. translate([0,0,-countersunk*pitch])
  195. cylinder(
  196. h=2*countersunk*pitch,
  197. r2=pitchRadius+clearance*pitch+0.25*pitch,
  198. r1=pitchRadius+clearance*pitch+0.25*pitch+2*countersunk*pitch,
  199. $fn=24
  200. );
  201.  
  202. translate([0,0,countersunk*pitch])
  203. translate([0,0,-pitch])
  204. trapezoidThread(
  205. length=length+2*pitch, // axial length of the threaded rod
  206. pitch=pitch, // axial distance from crest to crest
  207. pitchRadius=pitchRadius+clearance*pitch, // radial distance from center to mid-profile
  208. threadHeightToPitch=threadHeightToPitch, // ratio between the height of the profile and the pitch
  209. // std value for Acme or metric lead screw is 0.5
  210. profileRatio=profileRatio, // ratio between the lengths of the raised part of the profile and the pitch
  211. // std value for Acme or metric lead screw is 0.5
  212. threadAngle=threadAngle, // angle between the two faces of the thread
  213. // std value for Acme is 29 or for metric lead screw is 30
  214. RH=RH, // true/false the thread winds clockwise looking along shaft
  215. // i.e.follows Right Hand Rule
  216. clearance=-clearance, // radial clearance, normalized to thread height
  217. backlash=-backlash, // axial clearance, normalized to pitch
  218. stepsPerTurn=stepsPerTurn // number of slices to create per turn
  219. );
  220.  
  221. translate([0,0,length-countersunk*pitch])
  222. cylinder(
  223. h=2*countersunk*pitch,
  224. r1=pitchRadius+clearance*pitch+0.25*pitch,
  225. r2=pitchRadius+clearance*pitch+0.25*pitch+2*countersunk*pitch,$fn=24,
  226. $fn=24
  227. );
  228. }
  229.  
  230. module trapezoidNut(
  231. length=45, // axial length of the threaded rod
  232. radius=25, // outer radius of the nut
  233. pitch=10, // axial distance from crest to crest
  234. pitchRadius=10, // radial distance from center to mid-profile
  235. threadHeightToPitch=0.5, // ratio between the height of the profile and the pitch
  236. // std value for Acme or metric lead screw is 0.5
  237. profileRatio=0.5, // ratio between the lengths of the raised part of the profile and the pitch
  238. // std value for Acme or metric lead screw is 0.5
  239. threadAngle=30, // angle between the two faces of the thread
  240. // std value for Acme is 29 or for metric lead screw is 30
  241. RH=true, // true/false the thread winds clockwise looking along shaft, i.e.follows the Right Hand Rule
  242. countersunk=0, // depth of 45 degree chamfered entries, normalized to pitch
  243. clearance=0.1, // radial clearance, normalized to thread height
  244. backlash=0.1, // axial clearance, normalized to pitch
  245. stepsPerTurn=24 // number of slices to create per turn
  246. )
  247. {
  248. difference()
  249. {
  250. cylinder(
  251. h=length,
  252. r1=radius,
  253. r2=radius,
  254. $fn=6
  255. );
  256.  
  257. trapezoidThreadNegativeSpace(
  258. length=length, // axial length of the threaded rod
  259. pitch=pitch, // axial distance from crest to crest
  260. pitchRadius=pitchRadius, // radial distance from center to mid-profile
  261. threadHeightToPitch=threadHeightToPitch, // ratio between the height of the profile and the pitch
  262. // std value for Acme or metric lead screw is 0.5
  263. profileRatio=profileRatio, // ratio between the lengths of the raised part of the profile and the pitch
  264. // std value for Acme or metric lead screw is 0.5
  265. threadAngle=threadAngle, // angle between the two faces of the thread
  266. // std value for Acme is 29 or for metric lead screw is 30
  267. RH=true, // true/false the thread winds clockwise looking along shaft
  268. // i.e.follows Right Hand Rule
  269. countersunk=countersunk, // depth of 45 degree countersunk entries, normalized to pitch
  270. clearance=clearance, // radial clearance, normalized to thread height
  271. backlash=backlash, // axial clearance, normalized to pitch
  272. stepsPerTurn=stepsPerTurn // number of slices to create per turn
  273. );
  274. }
  275. }
  276. module trapezoidNut2(
  277. length=45, // axial length of the threaded rod
  278. radius=25, // outer radius of the nut
  279. pitch=10, // axial distance from crest to crest
  280. pitchRadius=10, // radial distance from center to mid-profile
  281. threadHeightToPitch=0.5, // ratio between the height of the profile and the pitch
  282. // std value for Acme or metric lead screw is 0.5
  283. profileRatio=0.5, // ratio between the lengths of the raised part of the profile and the pitch
  284. // std value for Acme or metric lead screw is 0.5
  285. threadAngle=30, // angle between the two faces of the thread
  286. // std value for Acme is 29 or for metric lead screw is 30
  287. RH=true, // true/false the thread winds clockwise looking along shaft, i.e.follows the Right Hand Rule
  288. countersunk=0, // depth of 45 degree chamfered entries, normalized to pitch
  289. clearance=0.1, // radial clearance, normalized to thread height
  290. backlash=0.1, // axial clearance, normalized to pitch
  291. stepsPerTurn=24 // number of slices to create per turn
  292. )
  293. {
  294. difference()
  295. {
  296. cylinder(
  297. h=length,
  298. r1=radius,
  299. r2=radius,
  300. $fn=nut_sides
  301. );
  302.  
  303. trapezoidThreadNegativeSpace(
  304. length=length, // axial length of the threaded rod
  305. pitch=pitch, // axial distance from crest to crest
  306. pitchRadius=pitchRadius, // radial distance from center to mid-profile
  307. threadHeightToPitch=threadHeightToPitch, // ratio between the height of the profile and the pitch
  308. // std value for Acme or metric lead screw is 0.5
  309. profileRatio=profileRatio, // ratio between the lengths of the raised part of the profile and the pitch
  310. // std value for Acme or metric lead screw is 0.5
  311. threadAngle=threadAngle, // angle between the two faces of the thread
  312. // std value for Acme is 29 or for metric lead screw is 30
  313. RH=true, // true/false the thread winds clockwise looking along shaft
  314. // i.e.follows Right Hand Rule
  315. countersunk=countersunk, // depth of 45 degree countersunk entries, normalized to pitch
  316. clearance=clearance, // radial clearance, normalized to thread height
  317. backlash=backlash, // axial clearance, normalized to pitch
  318. stepsPerTurn=stepsPerTurn // number of slices to create per turn
  319. );
  320. }
  321. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement