formatting, renamed bezierExtrusion to bezier_extrusion

This commit is contained in:
tessaK9 2026-03-12 13:30:51 +01:00
commit 7ab5da4b45
6 changed files with 86 additions and 101 deletions

View file

@ -1,31 +0,0 @@
module extrusion(points){
//points[0] must have its points ordered clockwise
n = len(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]) (n*k)-i]], concat([for (i = [0 : n-2]) for (j = [0 : k-2]) [(i*k)+j+1, (i*k)+j, ((i+1)*k)+j, ((i+1)*k)+j+1]], [for (i = [0 : n-2]) [i*k,(i+1)*k-1,((i+2)*k)-1,(i+1)*k]]));
polyhedron(points = points_new, faces = faces, convexity = 10);
}
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(ctrl = ctrl, shape = shape, mod = wave, sections = 8192);

31
bezier_extrusion.scad Normal file
View file

@ -0,0 +1,31 @@
module extrusion(points){
//points[0] must have its points ordered clockwise
n = len(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]) (n*k)-i]], concat([for (i = [0 : n-2]) for (j = [0 : k-2]) [(i*k)+j+1, (i*k)+j, ((i+1)*k)+j, ((i+1)*k)+j+1]], [for (i = [0 : n-2]) [i*k,(i+1)*k-1,((i+2)*k)-1,(i+1)*k]]));
polyhedron(points = points_new, faces = faces, convexity = 10);
}
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(ctrl = ctrl, shape = shape, mod = wave, sections = 8192);

View file

@ -1,4 +1,4 @@
use <bezierExtrusion.scad>; use <bezier_extrusion.scad>;
use <headband.scad>; use <headband.scad>;
thickness = 2.5; thickness = 2.5;

View file

@ -1,4 +1,4 @@
use <bezierExtrusion.scad>; use <bezier_extrusion.scad>;
module headband(thickness, height){ module headband(thickness, height){
rake_length = 2.5; rake_length = 2.5;
@ -24,8 +24,8 @@ module headband(thickness, height){
rake = function (t) (-cos(64 * 360 * t) > 0.33) ? 1 : 0.1; rake = function (t) (-cos(64 * 360 * t) > 0.33) ? 1 : 0.1;
union(){ union(){
bezier_extrude(ctrl = ctrl_band, shape = shape_band, sections = 128); bezier_extrude(ctrl = ctrl_band, shape = shape_band, sections = 64);
mirror([1,0,0]) bezier_extrude(ctrl = ctrl_band, shape = shape_band, sections = 128); mirror([1,0,0]) bezier_extrude(ctrl = ctrl_band, shape = shape_band, sections = 64);
bezier_extrude(ctrl = ctrl_end, shape = shape_band, mod_x = fillet, sections = 16); bezier_extrude(ctrl = ctrl_end, shape = shape_band, mod_x = fillet, sections = 16);
mirror([1,0,0]) bezier_extrude(ctrl = ctrl_end, shape = shape_band, mod_x = fillet, sections = 16); mirror([1,0,0]) bezier_extrude(ctrl = ctrl_end, shape = shape_band, mod_x = fillet, sections = 16);
bezier_extrude(ctrl = ctrl_rake, shape = shape_rake, mod_x = rake, sections = 512); bezier_extrude(ctrl = ctrl_rake, shape = shape_rake, mod_x = rake, sections = 512);

View file

@ -1,14 +1,13 @@
module hinge(deg, lb, la){ module hinge(deg, lb, la){
CutPoints = [
[6,0,5.5], cut_points = [[6,0,5.5],
[6,7,5.5], [6,7,5.5],
[4.5,0,7], [4.5,0,7],
[4.5,7,7], [4.5,7,7],
[6,0,7], [6,0,7],
[6,7,7]]; [6,7,7]];
CutFaces = [ cut_faces = [[0,2,4],
[0,2,4],
[1,5,3], [1,5,3],
[0,1,3,2], [0,1,3,2],
[0,4,5,1], [0,4,5,1],
@ -17,11 +16,9 @@ module hinge(deg, lb, la){
union(){ union(){
difference(){ difference(){
cube([6,7,6], center = false); cube([6,7,6], center = false);
polyhedron(points = CutPoints, faces = CutFaces, convexity = 10); polyhedron(points = cut_points, faces = cut_faces, convexity = 10);
translate([3,3.5,3.5]){ translate([3,3.5,3.5]){
rotate(90, [1,0,0]){ rotate(90, [1,0,0]) cylinder(h = 6, r = 2, center = true, $fn = 16);
cylinder(h = 6, r = 2, center = true, $fn = 16);
}
} }
if(deg <= 45){ if(deg <= 45){
translate([3,2,4.75]){ translate([3,2,4.75]){
@ -42,25 +39,15 @@ module hinge(deg, lb, la){
} }
} }
translate([4,2,1.5]){ translate([4,2,1.5]) cube([4,3,4], center = false);
cube([4,3,4], center = false);
}
} }
cube([6.5,7,1.5], center = false); cube([6.5,7,1.5], center = false);
translate([3,3.5,3.5]){ translate([3,3.5,3.5]){
rotate(90, [1,0,0]){ rotate(90, [1,0,0]) cylinder(h = 4.5, r = 1.25, center = true, $fn = 16);
cylinder(h = 4.5, r = 1.25, center = true, $fn = 16);
}
}
translate([3,2.5,2.25]){
cube([4,2,2.5], center = false);
}
translate([-lb,0,0]){
cube([lb,7,6], center = false);
}
translate([7,0,0]){
cube([la,7,6], center = false);
} }
translate([3,2.5,2.25]) cube([4,2,2.5], center = false);
translate([-lb,0,0]) cube([lb,7,6], center = false);
translate([7,0,0]) cube([la,7,6], center = false);
} }
} }

View file

@ -1,9 +1,7 @@
use <hinge.scad>; use <hinge.scad>;
union(){ union(){
translate([7,0,0]){ translate([7,0,0]) cube([5,47,6]);
cube([5,47,6]);
}
hinge(15,0,0); hinge(15,0,0);
translate([0,10,0]) hinge(30,0,0); translate([0,10,0]) hinge(30,0,0);
translate([0,20,0]) hinge(45,0,0); translate([0,20,0]) hinge(45,0,0);