-
Notifications
You must be signed in to change notification settings - Fork 28
/
technical_drawing.scad
125 lines (103 loc) · 3.21 KB
/
technical_drawing.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
// Helper modules for parametric technical drawing
//
// (c) 2013 Metamáquina <http://www.metamaquina.com.br/>
//
// Author:
// * Felipe C. da S. Sanches <[email protected]>
//
// This program 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.
//
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
module roundline(x1,y1,x2,y2, color="black", thickness=0.3){
color(color){
hull(){
translate([x1,y1])
circle(r=thickness/2, $fn=20);
translate([x2,y2])
circle(r=thickness/2, $fn=20);
}
}
}
module line(x1,y1,x2,y2, color="black", thickness=1){
angle = atan2(y2-y1, x2-x1);
length = sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
color(color){
translate([x1,y1]){
rotate([0,0,angle])
translate([0,-thickness/2])
square([length,thickness]);
}
}
}
module Square(x1,y1,x2,y2){
roundline(x1,y1,x2,y1);
roundline(x2,y1,x2,y2);
roundline(x2,y2,x1,y2);
roundline(x1,y2,x1,y1);
}
module RegularPolygon(N,r, even_odd=false){
if (even_odd){
for (i=[1:N/2])
roundline(r*cos(2*i*360/N), r*sin(2*i*360/N),
r*cos((2*i+1)*360/N), r*sin((2*i+1)*360/N));
} else {
for (i=[1:N])
roundline(r*cos(i*360/N), r*sin(i*360/N),
r*cos((i+1)*360/N), r*sin((i+1)*360/N));
}
}
module Hexagon(r){
RegularPolygon(6,r);
}
module Circle(r, even_odd=false){
RegularPolygon(60,r, even_odd=even_odd);
}
module glyph(char, fontsize){
scale(fontsize/12){
import("font.dxf", layer=char);
}
}
module dimension_label(x, y, string, spacing=0.7, fontsize=2){
//draw dimension text at coordinate x,y
text_length = (len(string)+1) * spacing*fontsize;
translate([x - text_length/2,y + fontsize/3]){
for (i=[0:len(string)-1]){
translate([spacing*fontsize*i,0]) glyph(string[i], fontsize);
}
translate([len(string)*spacing*fontsize, 0]) glyph("mm", fontsize);
}
}
module arrow(x,y,angle, thickness=0.1){
length = 10*thickness;
width = 4*thickness;
translate([x,y])
rotate([0,0,angle])
hull(){
circle(r=thickness, $fn=20);
translate([length, width/2])
circle(r=thickness, $fn=20);
translate([length, -width/2])
circle(r=thickness, $fn=20);
}
}
module dimension(x1,y1, x2,y2, color="blue", line_thickness=1, fontsize=2){
length = round(1000*sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)))/1000.0;
angle = atan2(y2-y1, x2-x1);
color(color){
arrow(x1,y1, 0, thickness=line_thickness);
roundline(x1,y1+1, x1,y1-6, thickness=line_thickness);
arrow(x2,y2, -180, thickness=line_thickness);
roundline(x2,y2+1, x2,y2-6, thickness=line_thickness);
roundline(x1,y1, x2,y2, thickness=line_thickness);
dimension_label((x1+x2)/2, (y1+y2)/2, str(length), fontsize=fontsize);
}
}