/[qspeakers]/branches/qtcharts/bandpassbox_template.scad
ViewVC logotype

Contents of /branches/qtcharts/bandpassbox_template.scad

Parent Directory Parent Directory | Revision Log Revision Log


Revision 298 - (show annotations)
Wed Nov 25 13:12:53 2020 UTC (6 months, 2 weeks ago) by ben
File size: 4314 byte(s)
Fixup openSCAD templates.

1 /* loudspeaker __MODEL__ */
2 loudspeaker_number = __NUMBER__;
3 margin = __MARGIN__; /* cm */
4 loudspeaker_diameter = __DIAMETER__; /* cm */
5 internal_closed_box_volume = __SEALEDBOXVOLUME__; /* dm³ (Liter) */
6 internal_ported_box_volume = __PORTEDBOXVOLUME__; /* dm³ (Liter) */
7 wood_thick = __WOODTHICK__; /* cm */
8 wood_color = "wheat";
9
10 /* sealed box dimensions */
11 internal_closed_box_width = loudspeaker_diameter + margin; /* cm (x)*/
12 internal_closed_box_height = max((loudspeaker_diameter + margin) * loudspeaker_number, 1.618 * internal_closed_box_width); /* cm (z)*/
13 internal_closed_box_depth = internal_closed_box_volume * 1000 / (internal_closed_box_width * internal_closed_box_height); /* cm (y)*/
14
15 /* ported box dimensions */
16 internal_ported_box_width = internal_closed_box_width; /* cm (x)*/
17 internal_ported_box_height = internal_closed_box_height; /* cm (z)*/
18 internal_ported_box_depth = internal_ported_box_volume * 1000 / (internal_ported_box_width * internal_ported_box_height); /* cm (y)*/
19
20 /* other ported enclosure declarations */
21 ported_box_port_number = __PORTEDBOXPORTNUMBER__;
22 ported_box_port_slot_activated = __PORTEDBOXPORTSLOTACTIVATED__;
23 ported_box_port_slot_width = __PORTEDBOXPORTSLOTWIDTH__;
24 ported_box_port_slot_height = __PORTEDBOXPORTSLOTHEIGHT__;
25 ported_box_port_diameter = __PORTEDBOXPORTDIAMETER__;
26 ported_box_port_length = __PORTEDBOXPORTLENGTH__;
27
28 vertical_center = (internal_closed_box_height + (2 * wood_thick)) / 2;
29 horizontal_center = (internal_closed_box_width + (2 * wood_thick)) / 2;
30
31 module speaker_hole(diameter, x, z)
32 {
33 translate([x, 0, z]) {
34 rotate([90, 0, 0]) {
35 color("black") {
36 cylinder($fn=360, h = 2 * wood_thick, r1 = diameter / 2, r2 = diameter / 2, center=true);
37 }
38 }
39 }
40 }
41
42 module closed_enclosure(width, height, depth)
43 {
44
45 difference() {
46 /* external dimentions */
47 color(wood_color) {
48 cube([width + (2 * wood_thick), depth + (2 * wood_thick), height + (2 * wood_thick)]);
49 }
50
51 /* internal dimentions */
52 translate([wood_thick, wood_thick, wood_thick]) {
53 color(wood_color) {
54 cube([width, depth, height]);
55 }
56 }
57 }
58 }
59
60 /* now draw the sealed enclosure with the loudspeaker(s) */
61 difference() {
62 closed_enclosure(internal_closed_box_width, internal_closed_box_height,internal_closed_box_depth);
63 for (i = [0:loudspeaker_number-1]) {
64 speaker_hole(loudspeaker_diameter, horizontal_center, margin + (loudspeaker_diameter / 2) + i * (loudspeaker_diameter + margin));
65 }
66 }
67
68 module port_hole(diameter, slot, width, height, x, z)
69 {
70 if (ported_box_port_slot_activated == true) {
71 translate([x, 0, z]) {
72 color("black") {
73 cube([width, 2 * wood_thick, height]);
74 }
75 }
76 } else {
77 translate([x, 0, z]) {
78 rotate([90, 0, 0]) {
79 color("black") {
80 cylinder($fn=360, h = 2 * wood_thick, r1 = diameter / 2, r2 = diameter / 2, center=true);
81 }
82 }
83 }
84 }
85 }
86
87 module ported_enclosure(width, height, depth)
88 {
89 difference() {
90 /* external dimentions without internal face */
91 color(wood_color) {
92 cube([width + (2 * wood_thick), depth, height + (2 * wood_thick)]);
93 }
94
95 /* internal dimentions */
96 translate([wood_thick, wood_thick, wood_thick]) {
97 color(wood_color) {
98 cube([width, depth, height]);
99 }
100 }
101 }
102 }
103
104 /* now, draw ported enclosure part with the port(s), beside the sealed enclosure */
105 translate([internal_closed_box_width + (2 * wood_thick) + margin, 0, 0]) {
106 difference() {
107 ported_enclosure(internal_ported_box_width, internal_ported_box_height, internal_ported_box_depth);
108
109 /* calculate ports distribition */
110 port_placing = (internal_ported_box_width + (2 * wood_thick)) / ( ported_box_port_number + 1);
111 for (i = [1:ported_box_port_number]) {
112 if (ported_box_port_slot_activated == false) {
113 /* circular ports, center is used */
114 port_hole(ported_box_port_diameter, ported_box_port_slot_activated, ported_box_port_slot_width, ported_box_port_slot_height, i * port_placing, wood_thick + margin + ported_box_port_diameter / 2);
115 } else {
116 /* slot ports, left corner is used */
117 port_hole(ported_box_port_diameter, ported_box_port_slot_activated, ported_box_port_slot_width, ported_box_port_slot_height, (i * port_placing) - (ported_box_port_slot_width / 2), wood_thick);
118 }
119 }
120 }
121 }

  ViewVC Help
Powered by ViewVC 1.1.26