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

Contents of /branches/qtcharts/portedbox_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: 3491 byte(s)
Fixup openSCAD templates.

1 /* loudspeaker __MODEL__ */
2 loudspeaker_number = __NUMBER__;
3 margin = __MARGIN__; /* cm */
4 loudspeaker_diameter = __DIAMETER__; /* cm */
5 internal_ported_box_volume = __PORTEDBOXVOLUME__; /* dmĀ³ (Liter) */
6 ported_box_port_number = __PORTEDBOXPORTNUMBER__;
7 ported_box_port_slot_activated = __PORTEDBOXPORTSLOTACTIVATED__;
8 ported_box_port_slot_width = __PORTEDBOXPORTSLOTWIDTH__;
9 ported_box_port_slot_height = __PORTEDBOXPORTSLOTHEIGHT__;
10 ported_box_port_diameter = __PORTEDBOXPORTDIAMETER__;
11 ported_box_port_length = __PORTEDBOXPORTLENGTH__;
12 wood_thick = __WOODTHICK__; /* cm */
13 wood_color = "wheat";
14
15 internal_ported_box_width = loudspeaker_diameter + margin; /* cm (x)*/
16 internal_ported_box_height = max((ported_box_port_diameter + margin) + ((loudspeaker_diameter + margin) * loudspeaker_number), 1.618 * internal_ported_box_width); /* cm (z)*/
17 internal_ported_box_depth = internal_ported_box_volume * 1000 / (internal_ported_box_width * internal_ported_box_height); /* cm (y)*/
18
19 vertical_center = (internal_ported_box_height + (2 * wood_thick)) / 2;
20 horizontal_center = (internal_ported_box_width + (2 * wood_thick)) / 2;
21
22 module speaker_hole(diameter, x, z)
23 {
24 translate([x, 0, z]) {
25 rotate([90, 0, 0]) {
26 color("black") {
27 cylinder($fn=360, h = 2 * wood_thick, r1 = diameter / 2, r2 = diameter / 2, center=true);
28 }
29 }
30 }
31 }
32
33 module port_hole(diameter, slot, width, height, x, z)
34 {
35 if (ported_box_port_slot_activated == true) {
36 translate([x, 0, z]) {
37 color("black") {
38 cube([width, 2 * wood_thick, height]);
39 }
40 }
41 } else {
42 translate([x, 0, z]) {
43 rotate([90, 0, 0]) {
44 color("black") {
45 cylinder($fn=360, h = 2 * wood_thick, r1 = diameter / 2, r2 = diameter / 2, center=true);
46 }
47 }
48 }
49 }
50 }
51
52 module closed_enclosure(width, height, depth)
53 {
54
55 difference() {
56 /* external dimentions */
57 color(wood_color) {
58 cube([width + (2 * wood_thick), depth + (2 * wood_thick), height + (2 * wood_thick)]);
59 }
60
61 /* internal dimentions */
62 translate([wood_thick, wood_thick, wood_thick]) {
63 color(wood_color) {
64 cube([width, depth, height]);
65 }
66 }
67 }
68 }
69
70 difference() {
71 closed_enclosure(internal_ported_box_width, internal_ported_box_height, internal_ported_box_depth);
72
73 /* calculate ports distribition */
74 port_placing = (internal_ported_box_width + (2 * wood_thick)) / (ported_box_port_number + 1);
75 for (i = [1:ported_box_port_number]) {
76 if (ported_box_port_slot_activated == false) {
77 /* circular ports, center is used */
78 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);
79 } else {
80 /* slot ports, left corner is used */
81 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);
82 }
83 }
84
85 /* loudpeakers distribution */
86 for (i = [0:loudspeaker_number-1]) {
87 if (ported_box_port_slot_activated == false) {
88 speaker_hole(loudspeaker_diameter, horizontal_center, margin + (loudspeaker_diameter / 2) + (ported_box_port_diameter + margin) + i * (loudspeaker_diameter + margin));
89 } else {
90 speaker_hole(loudspeaker_diameter, horizontal_center, margin + (loudspeaker_diameter / 2) + ported_box_port_slot_height + i * (loudspeaker_diameter + margin));
91 }
92 }
93 }

  ViewVC Help
Powered by ViewVC 1.1.26