diff --git a/bezierExtrusion.scad b/bezierExtrusion.scad deleted file mode 100644 index de1da09..0000000 --- a/bezierExtrusion.scad +++ /dev/null @@ -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); \ No newline at end of file diff --git a/bezier_extrusion.scad b/bezier_extrusion.scad new file mode 100644 index 0000000..b11565c --- /dev/null +++ b/bezier_extrusion.scad @@ -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); \ No newline at end of file diff --git a/catears.scad b/catears.scad index 36903ba..beb282d 100644 --- a/catears.scad +++ b/catears.scad @@ -1,4 +1,4 @@ -use ; +use ; use ; thickness = 2.5; @@ -21,7 +21,7 @@ module catear(){ bezier_extrude(ctrl = ctrl_ear1, shape = shape_band, sections = 32); bezier_extrude(ctrl = ctrl_ear2, shape = shape_band, sections = 32); } -} +} module catears(){ union(){ diff --git a/headband.scad b/headband.scad index d656976..f0a6dbf 100644 --- a/headband.scad +++ b/headband.scad @@ -1,4 +1,4 @@ -use ; +use ; module headband(thickness, height){ rake_length = 2.5; @@ -24,8 +24,8 @@ module headband(thickness, height){ rake = function (t) (-cos(64 * 360 * t) > 0.33) ? 1 : 0.1; union(){ - bezier_extrude(ctrl = ctrl_band, shape = shape_band, sections = 128); - mirror([1,0,0]) 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 = 64); 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); diff --git a/hinge.scad b/hinge.scad index b86f58d..9a95024 100644 --- a/hinge.scad +++ b/hinge.scad @@ -1,66 +1,53 @@ module hinge(deg, lb, la){ - CutPoints = [ - [6,0,5.5], - [6,7,5.5], - [4.5,0,7], - [4.5,7,7], - [6,0,7], - [6,7,7]]; + + cut_points = [[6,0,5.5], + [6,7,5.5], + [4.5,0,7], + [4.5,7,7], + [6,0,7], + [6,7,7]]; - CutFaces = [ - [0,2,4], - [1,5,3], - [0,1,3,2], - [0,4,5,1], - [2,3,5,4]]; + cut_faces = [[0,2,4], + [1,5,3], + [0,1,3,2], + [0,4,5,1], + [2,3,5,4]]; - union(){ - difference(){ - cube([6,7,6], center = false); - polyhedron(points = CutPoints, faces = CutFaces, convexity = 10); - translate([3,3.5,3.5]){ - rotate(90, [1,0,0]){ - cylinder(h = 6, r = 2, center = true, $fn = 16); - } + union(){ + difference(){ + cube([6,7,6], center = false); + polyhedron(points = cut_points, faces = cut_faces, convexity = 10); + translate([3,3.5,3.5]){ + rotate(90, [1,0,0]) cylinder(h = 6, r = 2, center = true, $fn = 16); + } + if(deg <= 45){ + translate([3,2,4.75]){ + rotate(-deg,[0,1,0]){ + translate([0,0,-4]){ + cube([4,3,4], center = false); } - if(deg <= 45){ - translate([3,2,4.75]){ - rotate(-deg,[0,1,0]){ - translate([0,0,-4]){ - cube([4,3,4], center = false); - } - } - } - } - else{ - translate([1.75,2,3.5]){ - rotate(-deg,[0,1,0]){ - translate([0,0,-6]){ - cube([6,3,6], center = false); - } - } - } + } + } + } + else{ + translate([1.75,2,3.5]){ + rotate(-deg,[0,1,0]){ + translate([0,0,-6]){ + cube([6,3,6], center = false); } + } + } + } - translate([4,2,1.5]){ - cube([4,3,4], center = false); - } - } - cube([6.5,7,1.5], center = false); - - translate([3,3.5,3.5]){ - rotate(90, [1,0,0]){ - 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([4,2,1.5]) cube([4,3,4], center = false); } + cube([6.5,7,1.5], center = false); + + translate([3,3.5,3.5]){ + rotate(90, [1,0,0]) 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); + } } \ No newline at end of file diff --git a/hingetest.scad b/hingetest.scad index 3b85957..0fd2d4c 100644 --- a/hingetest.scad +++ b/hingetest.scad @@ -1,12 +1,10 @@ use ; union(){ - translate([7,0,0]){ - cube([5,47,6]); - } - hinge(15,0,0); - translate([0,10,0]) hinge(30,0,0); - translate([0,20,0]) hinge(45,0,0); - translate([0,30,0]) hinge(60,0,0); - translate([0,40,0]) hinge(90,0,0); + translate([7,0,0]) cube([5,47,6]); + hinge(15,0,0); + translate([0,10,0]) hinge(30,0,0); + translate([0,20,0]) hinge(45,0,0); + translate([0,30,0]) hinge(60,0,0); + translate([0,40,0]) hinge(90,0,0); } \ No newline at end of file