-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnuts-bolts.scad
227 lines (208 loc) · 8.34 KB
/
nuts-bolts.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//
// NUT AND BOLTS
// by ISC 2021-09
//
// rough visual representation only
// accurate measurement/holes for product design
//
// boltProfile = BoltProfile( ... ) - create profile
// Bolt( boltProfile ) - draw 3D
// BoltPanelPanelHole( boltProfile ) - draw 2D panel holes
//
// nutProfile = NutProfile( ... ) - create profile
// Nut( nutProfile ) - draw 3D
//
include <KVTree.scad>
include <utility.scad>
//
// DEMO
//
// run me!!!
//NutsAndBolts_Demo();
module NutsAndBolts_Demo() {
//$fn=30;
boltProfile = BoltProfile(
shape = "hex", // "hex" | "square" | "round"
feature = "none", // "none" | "minus" | "plus" | "hex"
shaftDiameter = 5,
length = 20,
headDiameter = 10,
headThickness = 3 );
Bolt( boltProfile );
translate( [0,-15,0] )
linear_extrude( 3 )
difference() {
square( [10,10], center=true );
BoltPanelHole( boltProfile );
}
translate( [30,0,0] ) {
featureVariation( "hex" );
translate( [20,0,0] ) featureVariation( "square" );
translate( [40,0,0] ) featureVariation( "round" );
}
nut1 = NutProfile( shape="hex", boltDiameter=5, nutDiameter=8, thickness=3 );
nut2 = NutProfile( shape="square", boltDiameter=5, nutDiameter=8, thickness=3 );
nut3 = NutProfile( shape="round", boltDiameter=5, nutDiameter=8, thickness=3 );
translate( [0,-40,0] ) {
Nut( nut1 );
translate( [10,0,0] ) Nut( nut2 );
translate( [20,0,0] ) Nut( nut3 );
}
kvEchoAligned( boltProfile );
kvEchoAligned( nut1 );
module featureVariation( shape ) {
b1 = BoltProfile( shape=shape, shaftDiameter=3, length=15, headDiameter=6, headThickness=3 );
Bolt( b1 );
//generateBoltAndPanel( b1 );
translate( [0,15,0] ) {
b2 = BoltProfile( shape=shape, feature="minus", shaftDiameter=3, length=15, headDiameter=6, headThickness=3 );
Bolt( b2 );
//generateBoltAndPanel( b2 );
}
translate( [0,30,0] ) {
b3 = BoltProfile( shape=shape, feature="plus", shaftDiameter=3, length=15, headDiameter=6, headThickness=3 );
Bolt( b3 );
//generateBoltAndPanel( b3 );
}
translate( [0,45,0] ) {
b4 = BoltProfile( shape=shape, feature="hex", shaftDiameter=3, length=15, headDiameter=6, headThickness=3 );
Bolt( b4 );
//generateBoltAndPanel( b4 );
}
}
module generateBoltAndPanel( profile ) {
Bolt( profile );
translate( [0,-10,-3] )
linear_extrude( 3 )
difference() {
square( [10,10], center=true );
BoltPanelHole( profile );
}
}
}
//
// BOLT
//
function BoltProfile(
model = "",
shape = "hex", // "hex" | "square" | "round"
feature = "none", // "none" | "minus" | "plus" | "hex"
shaftDiameter = undef,
length = undef,
headDiameter = undef,
headThickness = undef
) = let (
e1=ErrorIf( shape!="hex" && shape!="square" && shape!="round", "invalid shape [hex|square|round]" ),
e2=ErrorIf( feature!="none" && feature!="minus" && feature!="plus" && feature!="hex", "invalid feature [none|minus|plus|hex]" ),
e3=ErrorIf( shaftDiameter==undef, "shaft diameter missing" ),
e4=ErrorIf( length ==undef, "length missing" ),
e5=ErrorIf( headDiameter ==undef, "head diameter missing" ),
e6=ErrorIf( headThickness==undef, "head thickness missing" )
) KVTree([
"type" , "bolt",
"model" , model,
"diameter", shaftDiameter,
"length" , length,
"head" , KVTree([ "shape", shape, "diameter", headDiameter, "thickness", headThickness, "feature" , feature ])
]);
module Bolt( profile ) {
t = kvSearch(profile,"type");
ExitIf( t!="bolt", "Bolt(): invalid profile" );
go();
module go() {
shaftDiameter = kvGet(profile, "diameter" );
length = kvGet(profile, "length" );
shape = kvGet(profile, "head.shape" );
feature = kvGet(profile, "head.feature" );
headSize = kvGet(profile, "head.diameter" );
headThickness = kvGet(profile, "head.thickness" );
difference() {
if ( shape == "square" )
linear_extrude( headThickness )
square( [headSize,headSize], center=true );
else if ( shape == "round" )
linear_extrude( headThickness )
circle( d=headSize );
else if ( shape == "hex" )
linear_extrude( headThickness )
circle( d=headSize/0.866, $fn = 6 ); // sin(60)=0.866
else
echo( "Bolt(): there's literally 3 options dude!");
translate( [0,0,0.05] )
if ( feature == "minus" ) {
translate( [0,0,headThickness/2] )
linear_extrude( headThickness/2 ) {
square( [headSize*1.2,headSize*0.2], center=true );
}
} else if ( feature == "plus" ) {
translate( [0,0,headThickness/2] )
linear_extrude( headThickness/2 ) {
square( [headSize*0.8,headSize*0.2], center=true );
square( [headSize*0.2,headSize*0.8], center=true );
}
} else if ( feature == "hex" ) {
translate( [0,0,headThickness/2] )
cylinder( headThickness/2, d=headSize*0.6, $fn=6 );
}
}
translate( [0,0,-length] )
cylinder( length, d=shaftDiameter );
}
}
module BoltPanelHole( profile, enlarge=1 ) {
t = kvSearch(profile,"type");
ExitIf( t!="bolt", "BoltPanelHole(): invalid profile" );
go();
module go() {
shaftDiameter = kvGet(profile, "diameter" );
circle( d=shaftDiameter+enlarge );
}
}
//
// NUT
//
function NutProfile(
model = "",
shape = "hex", // "hex", "square", "round"
boltDiameter = undef,
nutDiameter = undef,
thickness = undef
) = let (
e1=ErrorIf( shape!="hex" && shape!="square" && shape!="round", "invalid shape [hex|square|round]" ),
e2=ErrorIf( boltDiameter==undef, "bolt diameter missing" ),
e3=ErrorIf( nutDiameter ==undef, "nut diameter missing" ),
e4=ErrorIf( thickness ==undef, "thickness missing" )
) KVTree([
"type" , "nut",
"model" , model,
"shape" , shape,
"boltDiameter", boltDiameter,
"nutDiameter" , nutDiameter,
"thickness" , thickness
]);
module Nut( profile ) {
t = kvSearch(profile,"type");
ExitIf( t!="nut", "Nut(): invalid profile" );
go();
module go() {
shape = kvGet(profile, "shape" );
boltDiameter = kvGet(profile, "boltDiameter" );
nutDiameter = kvGet(profile, "nutDiameter" );
thickness = kvGet(profile, "thickness" );
difference() {
if ( shape == "hex" )
linear_extrude( thickness )
circle( d=nutDiameter/0.866, $fn = 6 ); // sin(60)=0.866
else if ( shape == "square" )
linear_extrude( thickness )
square( [nutDiameter,nutDiameter], center=true );
else if ( shape == "round" )
linear_extrude( thickness )
circle( d=nutDiameter );
else
echo( "Nut(): there's literally 3 options dude!");
translate( [0,0,-1] )
cylinder( thickness+2, d=boltDiameter );
}
}
}