-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathscrew-stand.scad
173 lines (157 loc) · 5.47 KB
/
screw-stand.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
/*
* Copyright (c) 2019, Gilles Bouissac
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
*
* Description: Screw stands library
* Author: Gilles Bouissac
*/
use <agentscad/printing.scad>
use <agentscad/mx-screw.scad>
// ----------------------------------------
// API
// ----------------------------------------
// x: hole x position from center
// y: hole y position from center
// s: screw (ex: M3())
// l: total length of head and drill stands
// d: drill stand length
// h: hollow between top and bottom stands (default: h=gap())
// i: incrusted length of head in its stand
// t: stands thickness
// o: orientation (default top->down, see standOrientation... functions )
function newScrewStand ( x, y, s, l, d, h=undef, i=0, t=WALL_T, o=undef ) =
let (
hollow = is_undef(h)?gap():h,
lhead = l-d-hollow,
lo = is_undef(o)?O_TD:o
) [ x, y, s, l, d, lhead, hollow, i, t, lo ];
IS_X = 0;
IS_Y = 1;
IS_S = 2;
IS_L = 3;
IS_LD = 4;
IS_LH = 5;
IS_H = 6;
IS_I = 7;
IS_T = 8;
IS_O = 9;
O_TD = 0; // Orientation Top->Down
O_DT = 1; // Orientation Down->Top
function getScrewStandX(p) = p[IS_X];
function getScrewStandY(p) = p[IS_Y];
function getScrewStandScrew(p) = p[IS_S];
function getScrewStandL(p) = p[IS_L];
function getScrewStandLD(p) = p[IS_LD];
function getScrewStandLH(p) = p[IS_LH];
function getScrewStandH(p) = p[IS_H];
function getScrewStandI(p) = p[IS_I];
function getScrewStandT(p) = p[IS_T];
function getScrewStandO(p) = p[IS_O];
function standOrientationTopDown() = O_TD;
function standOrientationDownTop() = O_DT;
// Screw head stand
module screwStandHead ( params ) {
difference() {
screwStandHeadShape ( params );
screwStandHeadHollow ( params );
}
}
// Screw drill stand
module screwStandDrill ( params ) {
difference() {
screwStandDrillShape ( params );
screwStandDrillHollow ( params );
}
}
module screwStandHeadShape ( params ) {
stands = is_num(params[0]) ? [params] : params ;
for ( stand=stands ) {
translate( [stand[IS_X],stand[IS_Y],stand[IS_L]/2] )
rotate( [stand[IS_O]==O_DT?180:0,0,0] )
translate( [0,0,stand[IS_L]/2] )
{
scale( [1,1,-1] )
cylinder(
r=mxGetAllenHeadD(stand[IS_S])/2+gap()+stand[IS_T],
h=stand[IS_T]+stand[IS_I]
);
scale( [1,1,-1] )
cylinder(
r=mxGetThreadDP(stand[IS_S])/2+stand[IS_T],
h=stand[IS_LH]
);
}
}
}
module screwStandHeadHollow( params ) {
screwStandBoltHollow ( params );
}
module screwStandDrillShape ( params ) {
stands = is_num(params[0]) ? [params] : params ;
for (stand=stands) {
translate( [stand[IS_X],stand[IS_Y],stand[IS_L]/2] )
rotate( [stand[IS_O]==O_DT?180:0,0,0] )
translate( [0,0,-stand[IS_L]/2] )
cylinder( r=mxGetThreadDP(stand[IS_S])/2+stand[IS_T], h=stand[IS_LD] );
}
}
module screwStandDrillHollow ( params ) {
screwStandBoltHollow ( params );
}
// ----------------------------------------
// Implementation
// ---------------------------------------
WALL_T = 1.2;
module screwStandBoltHollow ( params ) {
stands = is_num(params[0]) ? [params] : params ;
for (stand=stands) {
translate( [stand[IS_X],stand[IS_Y],stand[IS_L]/2] )
rotate( [stand[IS_O]==O_DT?180:0,0,0] )
translate( [0,0,stand[IS_L]/2-stand[IS_I]] )
scale( [1,1,-1] )
mxBoltAllenPassage(mxClone(stand[IS_S],tlp=stand[IS_LH]-stand[IS_I]));
}
}
// ----------------------------------------
// Showcase
// ----------------------------------------
PRECISION = 100;
SEPARATION = 0;
module showScrewStands( part=0, cut=undef, cut_rotation=undef ) {
screw = M3(tl=16);
stands = [
newScrewStand ( -10, -5, screw, 20, 4, i=1, h=0.4 ),
newScrewStand ( -20, -5, screw, 20, 4, i=1, h=0.4, o=standOrientationDownTop() ),
newScrewStand ( -10, +5, screw, 20, 9, i=1, h=5 ),
newScrewStand ( -20, +5, screw, 20, 9, i=1, h=5, o=standOrientationDownTop() ),
newScrewStand ( +10, +5, mxClone(screw,tl=10), 30, 12, i=1, h=0.4 ),
newScrewStand ( +20, +5, mxClone(screw,tl=10), 30, 12, i=1, h=0.4, o=standOrientationDownTop() )
];
if ( part==0 ) {
intersection () {
union() {
screwStandHead ( stands );
screwStandDrill ( stands );
%screwStandBoltHollow ( stands );
}
color ( "#fff",0.1 )
rotate( [0,0,is_undef(cut_rotation)?0:cut_rotation] )
translate( [-500,is_undef(cut)?-500:cut,-500] )
cube( [1000,1000,1000] );
}
}
if ( part==1 ) {
screwStandDrill( stands );
}
if ( part==2 ) {
screwStandHead( stands );
}
}
// 0: all
// 1: drill stand
// 2: head stand
showScrewStands ( 0, undef, 0, $fn=PRECISION );