From 0c97fa8e0a8070458c27d024bc74b8a8a3cb4e9e Mon Sep 17 00:00:00 2001 From: tessaK9 Date: Fri, 13 Mar 2026 23:42:04 +0100 Subject: [PATCH] unified bezier_extrude_partial with bezier_extrude --- bezier_extrusion.scad | 43 ++++++++++++------------------------------- headband.scad | 4 ++-- 2 files changed, 14 insertions(+), 33 deletions(-) diff --git a/bezier_extrusion.scad b/bezier_extrusion.scad index 9c125e6..b59ec2d 100644 --- a/bezier_extrusion.scad +++ b/bezier_extrusion.scad @@ -8,14 +8,7 @@ module extrusion(points){ polyhedron(points = points_new, faces = faces, convexity = 10); } -module slice(points){ - k = len(points[0]); - points_new = [for(L = points) for(p = L) p]; - faces = concat([[for(i = [0 : k-1]) i], [for(i = [1 : k]) 2*k-i], [0,k-1,(2*k)-1,k]], [for (i = [0 : k-2]) [i+1, i, k+i, k+i+1]]); - polyhedron(points = points_new, faces = faces, convexity = 10); -} - -module bezier_extrude_partial(ctrl, shape, merlon = 1, gap = 1, mod = function (t) 1, mod_x = function(t) 1, mod_y = function (t) 1, sections = 128){ +module bezier_extrude(ctrl, shape, mod = function (t) 1, mod_x = function(t) 1, mod_y = function (t) 1, partial = false, merlon = 1, gap = 1, sections = 128){ B_0 = ctrl[0]; B_1 = 3*(-ctrl[0] + ctrl[1]); B_2 = 3*(ctrl[0] - 2*ctrl[1] + ctrl[2]); @@ -30,30 +23,18 @@ module bezier_extrude_partial(ctrl, shape, merlon = 1, gap = 1, mod = function slices = [for (i = [0 : sections]) let (t = i/sections, p = bezier(t), normal = normal(t), n = normal/norm(normal)) [for (v = shape) [p.x+(mod(t) * mod_x(t) * n.x * v.x),p.y+(mod(t) * mod_x(t) * n.y * v.x), mod(t) * mod_y(t) * v.y]]]; - for(i = [0 : 1+gap : sections-merlon]){ - slice([slices[i],slices[i+merlon]]); + if(partial){ + for(i = [0 : merlon+gap : sections-merlon]){ + extrusion([slices[i],slices[i+merlon]]); + } + } + else{ + extrusion(slices); } } -module bezier_extrude(ctrl, shape, mod = function (t) 1, mod_x = function(t) 1, mod_y = function (t) 1, sections = 128){ - B_0 = ctrl[0]; - B_1 = 3*(-ctrl[0] + ctrl[1]); - B_2 = 3*(ctrl[0] - 2*ctrl[1] + ctrl[2]); - B_3 = -ctrl[0] + 3*(ctrl[1] - ctrl[2]) + ctrl[3]; - function bezier(t) = B_0 + t*B_1 + (t^2)*B_2 + (t^3)*B_3; - - Bn_0 = [B_1.y,-B_1.x]; - Bn_1 = [2*B_2.y,(-2)*B_2.x]; - Bn_2 = [3*B_3.y,(-3)*B_3.x]; - function normal(t) = Bn_0 + t*Bn_1 + (t^2)*Bn_2; - - slices = [for (i = [0 : sections]) - let (t = i/sections, p = bezier(t), normal = normal(t), n = normal/norm(normal)) - [for (v = shape) [p.x+(mod(t) * mod_x(t) * n.x * v.x),p.y+(mod(t) * mod_x(t) * n.y * v.x), mod(t) * mod_y(t) * v.y]]]; - extrusion(slices); -} - shape = [[0,0.5],[0.8,0],[0.5,-1],[-0.5,-1],[-0.8,0]]; -ctrl = [[0,0],[20,10],[0,20],[10,0]]; -wave = function (x) 0.75+0.25*cos(3*360*x); -bezier_extrude_partial(ctrl = ctrl, shape = shape, mod = wave, sections = 32); \ No newline at end of file +ctrl = [[0,0],[0,20],[20,20],[20,0]]; +wave1 = function (x) 0.75+0.25*cos(8*360*x); +wave2 = function (x) 0.75+0.25*sin(8*360*x); +bezier_extrude(ctrl = ctrl, shape = shape, mod_x = wave1, mod_y = wave2, partial = true, merlon = 3, gap = 1, sections = 128); \ No newline at end of file diff --git a/headband.scad b/headband.scad index 840e319..8723246 100644 --- a/headband.scad +++ b/headband.scad @@ -37,9 +37,9 @@ module headband(thickness, height){ } mirror([1,0,0]) bezier_extrude(ctrl = ctrl_end, shape = shape_band, sections = 16); translate([-17,-8]){ - rotate_extrude(convexity = 10, $fn = 16) polygon(shape_halfband); + rotate_extrude(convexity = 10, $fn = 9) polygon(shape_halfband); } - bezier_extrude_partial(ctrl = ctrl_rake, shape = shape_rake, merlon = 2, gap = 3, sections = 5*42+1 ); + bezier_extrude(ctrl = ctrl_rake, shape = shape_rake, partial = true, merlon = 2, gap = 3, sections = 5*42+1 ); } }