-
Notifications
You must be signed in to change notification settings - Fork 3
/
debug-helpers.scad
60 lines (54 loc) · 1.53 KB
/
debug-helpers.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
module vector(v, length, r=.5) {
x = v.x;
y = v.y;
z = v.z;
length_ = norm(v);
length = is_undef(length) ? length_ : length;
if (length_ > 0) {
theta = atan2(x, -y); // equator angle around z-up axis
phi = acos( min( max(z / length_, -1), 1) ); // polar angle
rotate([0, 0, theta])
rotate([phi, 0, 0]) {
cylinder(r1=r, r2=r * .8, h=length * .95);
translate([0, 0, length * .95])
cylinder(r1=r * .8, r2=0, h=length * .05);
}
}
}
/**
* A nice XYZ axis indicator to clarify a transformation matrix's orientation.
*/
module axes(length=30) {
color("coral") vector([1, 0, 0] * length);
color("mediumseagreen") vector([0, 1, 0] * length);
color("blue") vector([0, 0, 1] * length);
}
_debug_colors = [
"tomato",
"peachpuff",
"rosybrown",
"yellowgreen",
"mediumseagreen",
"skyblue",
"steelblue",
"mediumorchid",
"slategray"
];
/**
* Debug complex hull groups by assigning a different colour to each child.
*
* Each child module should be preceeded by `debug(i)` where `i` is the child's
* index, and somewhere in the context of using `debug()` the special variable
* `$debug` must be set and evaluate to a non-false value.
*
* @param Integer i - child index, used to assign a colour in the debug colour sequence.
* @param Boolean [$debug=false] - toggle (at a higher context) whether to actually apply debug colouring.
*/
module debug(i) {
if (!is_undef($debug) && $debug != false) {
color(_debug_colors[i % len(_debug_colors)])
children();
} else {
children();
}
}