forked from adrianschlatter/threadlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
threadlib.scad
93 lines (79 loc) · 3.51 KB
/
threadlib.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
threadlib
+++++++++
Create threads easily.
:Author: Adrian Schlatter and contributors
:Date: 2023-04-02
:License: 3-Clause BSD. See LICENSE.
*/
function __THREADLIB_VERSION() = 0.5;
use <thread_profile.scad>
include <THREAD_TABLE.scad>
//examples
//table is organized as follow:
//["thread name", [pitch,//distance crete a crete
// Rrot, //internanl radius thread
//Dsupport, //diameter bolt ?? same as Rrot, no?
//[[r0, z0], [r1, z1], ..., [rn, zn]]]] //radius, zpos to draw shape of teeth
bolt("M4", length= 5, unit = "turns", higbee_arc = 30);
translate([15,0,0]) bolt("G1/2",length= 5, unit = "turns", higbee_arc = 30);
translate([40,0,0]) bolt("G1/2",length= 5, unit = "turns", higbee_arc = 30);
translate([-15,0,0])nut("M12x0.5", length= 10, unit = "turns", Douter=16);
translate([-50,0,0])nut("G1/2", length= 10, unit = "turns", Douter=40);
translate([-50,50,0])nut("G1/2", length= 10, unit = "turns", Douter=40);
function thread_specs(designator, table=THREAD_TABLE) =
/* Returns thread specs of thread-type 'designator' as a vector of
[pitch, Rrotation, Dsupport, section_profile] */
// first lookup designator in table inside a let() statement:
let (specs = table[search([designator], table, num_returns_per_match=1,
index_col_num=0)[0]][1])
// verify that we found something and return it:
assert(!is_undef(specs), str("Designator: '", designator, "' not found")) specs;
module thread(designator, length, unit = "turns", higbee_arc=20, fn=120, table=THREAD_TABLE)
{
specs = thread_specs(designator, table=table);
P = specs[0]; Rrotation = specs[1]; section_profile = specs[3];
turns = (unit == "turns")? length:length/P-1;
straight_thread(
section_profile=section_profile,
higbee_arc=higbee_arc,
r=Rrotation,
turns=turns,
fn=fn,
pitch=P);
}
module bolt(designator, length, unit = "turns",higbee_arc=20, fn=120, table=THREAD_TABLE) {
union() {
specs = thread_specs(str(designator, "-ext"), table=table);
P = specs[0]; Dsupport = specs[2];
H = (unit == "turns")? (length + 1) * P:length ;
thread(str(designator, "-ext"), length=length, unit=unit,higbee_arc=higbee_arc, fn=fn, table=table);
translate([0, 0, -P / 2])
cylinder(h=H, d=Dsupport, $fn=fn);
};
};
module nut(designator, length, unit = "turns", Douter, higbee_arc=20, fn=120, table=THREAD_TABLE) {
union() {
specs = thread_specs(str(designator, "-int"), table=table);
P = specs[0]; Dsupport = specs[2];
H = (unit == "turns")? (length + 1) * P:length ;
thread(str(designator, "-int"), length=length, unit=unit, higbee_arc=higbee_arc, fn=fn, table=table);
translate([0, 0, -P / 2])
difference() {
cylinder(h=H, d=Douter, $fn=fn);
translate([0, 0, -0.1])
cylinder(h=H+0.2, d=Dsupport, $fn=fn);
};
};
};
module tap(designator, length, unit = "turns", higbee_arc=20, fn=120, table=THREAD_TABLE) {
difference() {
specs = thread_specs(str(designator, "-int"), table=table);
P = specs[0]; Dsupport = specs[2];
H = (unit == "turns")? (length + 1) * P:length ;
translate([0, 0, -P / 2]) {
cylinder(h=H, d=Dsupport, $fn=fn);
};
thread(str(designator, "-int"), length = length, unit=unit, higbee_arc=higbee_arc, fn=fn, table=table);
};
}