GuitarModels/common.scad

60 lines
2.0 KiB
OpenSCAD
Raw Normal View History

2025-01-01 22:33:40 +10:30
Fender_Scale_mm = 648; // Actually 25.5inch = 647.7mm
Classical_Normal_Scale_mm = 650; // about 25.59inch
Classical_Short_Scale_mm = 635; // = 25inch
2025-01-03 18:20:30 +10:30
Gibson_Scale_mm = 630; // 24.75inch = 628.65mm
2025-01-01 22:33:40 +10:30
Guitar_Scale_Length_mm = Fender_Scale_mm;
2024-04-01 17:56:22 +10:30
ln2 = ln(2);
function log2(x) = ln(x)/ln2;
2023-06-13 21:21:33 +09:30
function fret_scale_length(n) = Guitar_Scale_Length_mm * 2^(-n/12);
2024-04-01 17:56:22 +10:30
function mm_to_fret_number(mm) = -log2(mm/Guitar_Scale_Length_mm)*12;
2023-06-13 21:21:33 +09:30
function lerp(start, end, amount) = start + (end-start)*amount;
2024-12-22 01:07:14 +10:30
function clamp(minimum, value, maximum) = min(max(minimum, value), maximum);
2025-01-03 18:20:30 +10:30
function flatten(l) = [ for (a = l) for (b = a) b];
2024-12-22 01:07:14 +10:30
function tri_circumcenter(pts) =
let(
v0 = pts[1] - pts[0],
v1 = pts[2] - pts[1],
d0 = (pts[1] + pts[0])/2 * v0,
d1 = (pts[2] + pts[1])/2 * v1,
det = -cross(v0, v1)
)
[cross([d1, d0], [v1.y, v0.y]), cross([d0, d1], [v0.x, v1.x])] / det;
// Create a circle containing all 3 points, then plot the arc between the first two points
function arc_points(tri_points, fragments_per_mm=5) =
let(
cc = tri_circumcenter(tri_points),
r = norm(tri_points[0] - cc),
steps = ceil((norm(tri_points[2] - tri_points[0]) + norm(tri_points[2] - tri_points[1]))*fragments_per_mm),
normalized0 = (tri_points[0] - cc)/r,
normalized1 = (tri_points[1] - cc)/r,
a_start = atan2(normalized0[1], normalized0[0]),
a_end = atan2(normalized1[1], normalized1[0]),
a_sweep = a_end - a_start,
a_step = a_sweep/steps
)
[for (i = [0:steps]) r*[cos(a_start+i*a_step), sin(a_start+i*a_step)] + cc];
2024-12-28 13:43:39 +10:30
module round_cube(size, r) {
translate([r, r, r]) minkowski() {
cube(size-[r*2,r*2,r*2]);
sphere(r=r, $fn=72);
}
}
2025-01-03 18:20:30 +10:30
module rotate_around(angles, pt) {
translate(pt)
rotate(angles)
translate(-pt)
children();
}
2024-12-22 01:07:14 +10:30
// We can't use Droid Sans Japanese because the rendering library is really dumb and will pick the wrong Droid Sans. CJK fonts must be singular files.
JP_Serif_Font = "New Tegomin";
JP_Sans_Font = "Yuji Boku";
JP_Fat_Sans_Font = ["Potta One", "Yusei Magic"];
JP_Light_Sans_Fonts = ["Hachi Maru Pop", "MotoyaLMaru", "Rounded MPlus 1c"];