From 165c80b1d4c5d96347eccbfbfa4d482ec865d8c1 Mon Sep 17 00:00:00 2001 From: djerun Date: Tue, 8 Jul 2025 12:51:04 +0200 Subject: [PATCH] declutter catear_v3 --- catear_headband.scad | 45 +++++++++++++++++++++++--------------------- primitives.scad | 6 ++++++ 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/catear_headband.scad b/catear_headband.scad index a498bee..c3bd260 100644 --- a/catear_headband.scad +++ b/catear_headband.scad @@ -13,33 +13,36 @@ EAR_ANGLE = 42; WITH_RAKE = true; DETAILS = true; +catear_v3_control_points = function (S, sf, bf, mn, a) let (s=S/2, R=rotation_matrix(a)) [ + [ s , 0, 0], + [ S*bf, S*sf*mn, 0] * R, + [-S*bf, S*sf*mn, 0] * R, + [-s , 0, 0], +]; + /** * unsupported parameters: chamfer, chamfer_shape, details, end_caps */ -module catear_v3(height, thickness, fractal=0, side_len=30, bend_factor=0.15, stretch_factor=1.2, debug=false, chamfer=CHAMFER, chamfer_shape=CHAMFER_SHAPE, details=true, end_caps=true, skew=2.0) { - S = side_len; - s = S/2; - sf = stretch_factor; - bf = bend_factor*2; - mn = 1.16; // magic number - f=skew*S*0.2; - - a = skew*10; - R = [[cos(a), -sin(a), 0], - [sin(a), cos(a), 0], - [ 0, 0, 1]]; - - A = [ s , 0, 0]; - B = [ S*bf, S*sf*mn, 0] * R; - C = [-S*bf, S*sf*mn, 0] * R; - D = [-s , 0, 0]; - - curve_vertices = bezier_curve_vertices([A, B, C, D], $fn); +module catear_v3(height, thickness, fractal=0, side_len=30, bend_factor=0.15, stretch_factor=1.2, debug=false, chamfer=CHAMFER, chamfer_shape=CHAMFER_SHAPE, details=true, end_caps=true, skew=2.0, $fn=$fn) { + control_points = catear_v3_control_points( + S=side_len, + sf=stretch_factor, + bf=bend_factor, + mn=1.16, + a=skew*10 + ); + curve_vertices = bezier_curve_vertices(control_points, $fn); if (debug) { - translate([0, 0, 2*height]) rotate(90) bezier_curve_debug([A, B, C, D]); + translate([0, 0, 2*height]) rotate(90) bezier_curve_debug(control_points); echo("curve_vertices: ", curve_vertices); } - rotate(90) render_curve(curve_vertices, width=thickness, height=height, chamfer=chamfer, debug=debug); + rotate(90) render_curve( + curve_vertices, + width=thickness, + height=height, + chamfer=chamfer, + debug=debug + ); } /** diff --git a/primitives.scad b/primitives.scad index 7b4959c..d24e117 100644 --- a/primitives.scad +++ b/primitives.scad @@ -14,6 +14,12 @@ mat_T = function (mat) [ ] ]; +rotation_matrix = function(a) [ + [cos(a), -sin(a), 0], + [sin(a), cos(a), 0], + [ 0, 0, 1] +]; + bezier_matrix = [[1, -3, 3, -1], [0, 3, -6, 3], [0, 0, 3, -3],