-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvn-lib.scad
73 lines (66 loc) · 1.95 KB
/
vn-lib.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
/*
Basic shapes library: vn-lib.scad
(C) 2023 Marek Wodzinski <[email protected]> https://majek.sh
This library is licensed under a Creative Commons
Attribution-ShareAlike 4.0 International License.
You should have received a copy of the license along with this work.
If not, see <http://creativecommons.org/licenses/by-sa/4.0/>
*/
/* diamond
dim - [x,y,z]
dim.x - width of diamond
dim.y - height of diamond
dim.z - thickness of extruded diamond
*/
module diamond(dim){
linear_extrude(dim.z) polygon([ [0,dim.y/2], [dim.x/2,0], [dim.x,dim.y/2], [dim.x/2,dim.y] ]);
}
/*
extruded square triangle
a - side size
h - height/lenght of element
*/
module triangle(a,h){
translate([0,0,-h/2]) linear_extrude(h) polygon([[0,0], [a,0], [0,a]]);
}
/* cube minus quarter of cylinder
r - size of rectangle
h - height/lenght of element
eps - offset for difference to look nice in preview (default=0.01)
*/
module round_corner(r,h,eps=0.01){
difference(){
cube([r,r,h]);
translate([r,r,-eps]) cylinder(r=r,h=h+2*eps);
}
}
/* hull between 2 cylinders
d - diameter of cylinders
h - height of cylinders
l - space between centers of cylinders
*/
module slot(d,h,l){
hull(){
cylinder(d=d,h=h);
translate([l,0,0]) cylinder(d=d,h=h);
}
}
/* 'extrude' along path
parameters - [ step_definition, step_definition, ... ], eps
step_definition - [ translation, rotation, shape ]
translation - argument to translate()
rotation - argument to rotate()
shape - argument to polygon()
eps - height of extrude of shape (default=0.01)
*/
module path_extrude(trs,offset=0,eps=0.01){
for (cc=[0:len(trs)-2]) {
hull(){
translate(trs[cc][0]) rotate(trs[cc][1]) linear_extrude(eps) offset(delta=offset) polygon(trs[cc][2]);
translate(trs[cc+1][0]) rotate(trs[cc+1][1]) linear_extrude(eps) offset(delta=offset) polygon(trs[cc+1][2]);
}
}
}
/* return points of square
*/
function square_points(x,y) = [[0,0],[x,0],[x,y],[0,y]];