forked from nophead/NopSCADlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpillar.scad
More file actions
100 lines (85 loc) · 3.97 KB
/
pillar.scad
File metadata and controls
100 lines (85 loc) · 3.97 KB
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
//
// NopSCADlib Copyright Chris Palmer 2018
// nop.head@gmail.com
// hydraraptor.blogspot.com
//
// This file is part of NopSCADlib.
//
// NopSCADlib is free software: you can redistribute it and/or modify it under the terms of the
// GNU General Public License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// NopSCADlib is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with NopSCADlib.
// If not, see <https://www.gnu.org/licenses/>.
//
//
//! Threaded pillars. Each end can be male or female.
//
include <../utils/core/core.scad>
use <../utils/thread.scad>
function pillar_name(type) = type[1]; //! Name of part
function pillar_thread(type) = type[2]; //! Thread diameter
function pillar_height(type) = type[3]; //! Body height
function pillar_od(type) = type[4]; //! Outer diameter of body
function pillar_id(type) = type[5]; //! Inner diameter of metal part
function pillar_ofn(type) = type[6]; //! Outer number of sides, 6 for hex, 0 for smooth cylinder
function pillar_ifn(type) = type[7]; //! Inner number of sides, 6 for hex, 0 for smooth cylinder
function pillar_o_colour(type) = type[8]; //! Colour of the outer part
function pillar_i_colour(type) = type[9]; //! Colour of the inner part
function pillar_top_thread(type) = type[10]; //! Top thread length, + for male, - for female
function pillar_bot_thread(type) = type[11]; //! Bottom thread length, + for male, - for female
module pillar(type) { //! Draw specified pillar
function sex(thread) = thread > 0 ? "M" : "F";
function fn(n) = n ? n : $fn;
sex = str(sex(pillar_bot_thread(type)),"/", sex(pillar_top_thread(type)));
height = pillar_height(type);
thread_d = pillar_thread(type);
bot_thread_l = pillar_bot_thread(type);
top_thread_l = pillar_top_thread(type);
thread_colour = pillar_i_colour(type);
pitch = metric_coarse_pitch(thread_d);
vitamin(str("pillar(", type[0], "): Pillar ", pillar_name(type), " ", sex, " M", thread_d, "x", height));
if(bot_thread_l > 0)
translate_z(-bot_thread_l + eps)
if(show_threads)
male_metric_thread(thread_d, pitch, bot_thread_l, false, top = 0, colour = thread_colour);
else
color(thread_colour)
cylinder(h = bot_thread_l, d = thread_d);
if(top_thread_l > 0)
translate_z(height - eps)
if(show_threads)
male_metric_thread(thread_d, pitch, top_thread_l, false, bot = 0, colour = thread_colour);
else
color(thread_colour)
cylinder(h = top_thread_l, d = thread_d);
color(pillar_i_colour(type)) {
linear_extrude(height = height)
difference() {
circle(d = pillar_id(type), $fn = fn(pillar_ifn(type)));
circle(d = thread_d);
}
top = height + min(top_thread_l, 0);
bot = -min(bot_thread_l, 0);
translate_z(bot)
cylinder(h = top - bot, d = thread_d + eps);
}
if(show_threads) {
if(top_thread_l < 0)
translate_z(height)
vflip()
female_metric_thread(thread_d, pitch, -top_thread_l, false, colour = thread_colour);
if(bot_thread_l < 0)
female_metric_thread(thread_d, pitch, -bot_thread_l, false, colour = thread_colour);
}
if(pillar_od(type) > pillar_id(type))
color(pillar_o_colour(type)) linear_extrude(height = height)
difference() {
circle(d = pillar_od(type), $fn = fn(pillar_ofn(type)));
circle(d = pillar_id(type), $fn = fn(pillar_ifn(type)));
}
}