Experimenting with optimizations

This commit is contained in:
Luke Hubmayer-Werner 2024-04-02 16:06:13 +10:30
parent 011345c68d
commit f176c9576c
1 changed files with 31 additions and 21 deletions

View File

@ -2,12 +2,10 @@ include <common.scad>
include <AluTCommon.scad> include <AluTCommon.scad>
semitone_strings = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "X", "XI"]; semitone_strings = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "X", "XI"];
octave_strings = ["", "˙", "¨", "]; octave_strings = ["", ".", "..", "_"];
octave_scales = [1.1, 1, 0.9, 0.8]; octave_scales = [1.1, 1, 0.9, 0.8];
z_resolution = $preview ? 0.5 : 0.1; z_resolution = $preview ? 0.5 : 0.1;
$fs = $preview ? 1 : 0.01;
$fa = $preview ? 5 : 0.1;
profile_arc_steps_backside = $preview ? 8 : 360; profile_arc_steps_backside = $preview ? 8 : 360;
profile_arc_steps_topside = $preview ? 8 : 60; profile_arc_steps_topside = $preview ? 8 : 60;
@ -93,15 +91,25 @@ module tube(from_fret, to_fret, scale_offset = 0, fingerboard_min_thick = 2.5, f
o = fret_width/2 * sin(fret_angle), o = fret_width/2 * sin(fret_angle),
x0 = f_prev - o, x0 = f_prev - o,
x1 = f_next + o, x1 = f_next + o,
x_mid = (x0+x1)/2,
y0 = fingerboard_min_thick, y0 = fingerboard_min_thick,
y1 = fingerboard_max_thick - (fret_width/2 * cos(fret_angle)), y1 = fingerboard_max_thick - (fret_width/2 * cos(fret_angle)),
pts = [[x0, y1], [x1, y1], [(x0+x1)/2, y0]], pts = [[x0, y1], [x1, y1], [x_mid, y0]],
cc = tri_circumcenter(pts), cc = tri_circumcenter(pts),
r = norm([x0, y1] - cc) r = norm([x0, y1] - cc),
r2 = r^2,
a_start = acos((x0 - cc[0])/r),
a_end = acos((x1 - cc[0])/r),
a_sweep = a_end - a_start,
a_step = a_sweep/10
) { ) {
translate([0,-w/2,0]) // echo(a_start=a_start, x0=x0, cc=cc);
rotate([-90,-90,0]) translate([cc[1], 0, cc[0]])
translate(cc) cylinder(h = w, r = r, $fn=max(8*ceil(r), 32)); rotate([90,0,0])
// cylinder(h = w, r = r, center = true);
linear_extrude(height = w, center = true)
// polygon([for (i = [0:10]) [-r*sin(a_start+i*a_step), r*cos(a_start+i*a_step)]]);
polygon([for (x = [x1-x_mid:0.05:x0-x_mid]) [-sqrt(r2 - x^2), x]]);
} }
} }
@ -129,26 +137,28 @@ module tube(from_fret, to_fret, scale_offset = 0, fingerboard_min_thick = 2.5, f
// color("red") scallops(); // color("red") scallops();
} }
module fret_number_text(fret) {
octave = floor(fret/12);
semitone = fret%12;
octave_scale = octave_scales[octave];
text(semitone_strings[semitone], size=4*octave_scale, halign="center", valign="center", font="Noto Sans", $fa=1, $fs=0.1);
translate([0, 2.5])
text(octave_strings[octave], size=5*octave_scale, halign="center", valign="center", font="Noto Sans", $fa=1, $fs=0.1);
}
module fret_number_markers(engrave_depth=1) { module fret_number_markers(engrave_depth=1) {
color("purple") color("purple")
// for (fret = [from_fret:to_fret]) // for (fret = [from_fret:to_fret])
for (fret = [from_fret+1:to_fret]) { for (fret = [from_fret+1:to_fret]) {
zn = fsl(fret); zn = fsl(fret);
pr = get_desired_profile_radius(get_desired_width_scale(zn)); pr = get_desired_profile_radius(get_desired_width_scale(zn));
octave = floor(fret/12);
semitone = fret%12;
octave_scale = octave_scales[octave];
// translate([-3,-16,zn-z_offset]) rotate([90,25,16]) linear_extrude(100) {
// translate([-3,-16,zn-z_offset]) rotate([90,25,-16+16*(zn/z0)]) linear_extrude(100) {
p_x0 = pr+x_min; p_x0 = pr+x_min;
translate([p_x0, 0, zn-z_offset]) rotate([90,25,-asin((p_x0+2)/pr)]) translate([0, 0, pr-engrave_depth]) linear_extrude(engrave_depth+1) { translate([p_x0, 0, zn-z_offset]) rotate([90,25,-asin((p_x0+2)/pr)])
text(semitone_strings[semitone], size=4*octave_scale, halign="center", valign="center", font="Noto Sans"); translate([0, 0, pr-engrave_depth]) linear_extrude(engrave_depth+1)
text(octave_strings[octave], size=6*octave_scale, halign="center", valign="center", font="Noto Sans"); fret_number_text(fret);
} translate([p_x0, 0, zn-z_offset]) rotate([90,-25,180+asin((p_x0+2)/pr)])
translate([p_x0, 0, zn-z_offset]) rotate([90,-25,180+asin((p_x0+2)/pr)]) translate([0, 0, pr-engrave_depth]) linear_extrude(engrave_depth+1) { translate([0, 0, pr-engrave_depth]) linear_extrude(engrave_depth+1)
text(semitone_strings[semitone], size=4*octave_scale, halign="center", valign="center", font="Noto Sans"); fret_number_text(fret);
text(octave_strings[octave], size=6*octave_scale, halign="center", valign="center", font="Noto Sans");
}
} }
} }