-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.scad
138 lines (122 loc) · 4.75 KB
/
main.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
include <lib/airfoil.scad>
include <lib/grid.scad>
// ----- Wing settings -----
$wing_length = 150;
$naca_airfoil = 4412;
$wing_chord_length = 150;
$rib_grid_distance = $wing_chord_length / 4 / sqrt(2);
$airfoil_cutoff_chord_fraction = 0.98;
// ----- Structure settings -----
// For ribs running all the way through the wing, set this value very high (greater than then chord length).
$rib_thickness = 1.5;
$rib_center_support_cones_enabled = true;
$rib_center_support_cone_inersection_diameter = 3;
$rib_center_support_cone_angle = 40; //degrees
// ----- Spar settings -----
$spar_enabled = true;
$spar_diameter = 10.4;
// Not _really_ required, but having this as a multiple of the rib_grid_distance / 2 fraction is ideal
$spar_position_chord_fraction = 1 / 4 / 2 * 3;
$spar_holding_structure_height_chord_fraction = 0.055;
// ----- Nitty gritty details -----
$center_gap = 0.9;
$rib_width = 0.1;
$wing_x_offset_chord_fraction = 0.002;
// Make the grid as high as the chord length, so every thickness of wing up to a circular profile is acceptable
$grid_height = $wing_chord_length;
$rib_center_support_sections_length = $wing_chord_length;
// ----- Code -----
/// Structure grid
module generateStructureGrid() {
$grid_diagonal_distance = $rib_grid_distance * sqrt(2);
union()
grid(ceil($wing_chord_length / $grid_diagonal_distance), ceil($wing_length / $grid_diagonal_distance) + 1, $grid_diagonal_distance)
rotate([0, 45, 0])
translate([0, -$grid_height / 2, 0])
difference() {
cube([$rib_grid_distance + $rib_width / 2, $grid_height, $rib_grid_distance + $rib_width / 2]);
translate([$rib_width / 2, 0, $rib_width / 2])
cube([$rib_grid_distance - $rib_width / 2, $grid_height, $rib_grid_distance - $rib_width / 2]);
}
}
/// Wing
module generateWing2D() {
intersection() {
translate([0, -$wing_chord_length])
square([$airfoil_cutoff_chord_fraction * $wing_chord_length, $wing_chord_length * 2]);
airfoil_poly($wing_chord_length, $naca_airfoil);
}
}
module generateWing() {
linear_extrude(height = $wing_length)
generateWing2D();
}
/// Spar
module generateSparStructureGap() {
if ($spar_enabled)
translateToMclPoint($wing_chord_length, $naca_airfoil, $spar_position_chord_fraction)
linear_extrude(height = $wing_length)
union() {
offset(delta = 1)
circle(d=$spar_diameter, $fn=30);
square(size = [2, $wing_chord_length*2], center=true);
}
}
module generateSparStructure() {
if ($spar_enabled)
translateToMclPoint($wing_chord_length, $naca_airfoil, $spar_position_chord_fraction)
linear_extrude(height = $wing_length)
union() {
circle(d=$spar_diameter, $fn=30);
translate([0, -0.5, 0])
translateFromMclToSurface($wing_chord_length, $naca_airfoil, $spar_position_chord_fraction)
translate([0, - $wing_chord_length, 0])
square(size = [0.1, $wing_chord_length*2], center=true);
}
}
/// Structure
module generateInnerStructureSupportCones() {
// The / 2 causes every grid intersection to have a cone
$grid_diagonal_distance = $rib_grid_distance * sqrt(2) / 2;
if ($rib_center_support_cones_enabled)
mclFollowingGrid(
$wing_chord_length,
$naca_airfoil,
ceil($wing_chord_length / $grid_diagonal_distance),
ceil($wing_length / $grid_diagonal_distance) + 1,
$grid_diagonal_distance
)
rotate([90, 0, 0])
union() {
mirror([0, 0 ,1])
translate([0, 0, -$rib_center_support_sections_length])
cylinder(h = $rib_center_support_sections_length, d1 = $rib_center_support_cone_inersection_diameter + 2 * tan($rib_center_support_cone_angle) * $rib_center_support_sections_length, d2 = $rib_center_support_cone_inersection_diameter, center = false);
translate([0, 0, -$rib_center_support_sections_length])
cylinder(h = $rib_center_support_sections_length, d1 = $rib_center_support_cone_inersection_diameter + 2 * tan($rib_center_support_cone_angle) * $rib_center_support_sections_length, d2 = $rib_center_support_cone_inersection_diameter, center = false);
}
}
module generateInnerStructureCutout() {
difference() {
linear_extrude(height = $wing_length)
offset(delta = -$rib_thickness)
generateWing2D();
generateInnerStructureSupportCones();
}
}
module generateInnerStructure() {
difference() {
intersection() {
generateWing();
generateStructureGrid();
}
generateInnerStructureCutout();
generateSparStructureGap();
linear_extrude(height = $wing_length)
mcl_poly($wing_chord_length, $naca_airfoil, $center_gap);
}
}
difference() {
generateWing();
generateInnerStructure();
generateSparStructure();
}