formatting, renamed bezierExtrusion to bezier_extrusion
This commit is contained in:
parent
2d143d6a56
commit
7ab5da4b45
6 changed files with 86 additions and 101 deletions
|
|
@ -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
31
bezier_extrusion.scad
Normal 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);
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use <bezierExtrusion.scad>;
|
use <bezier_extrusion.scad>;
|
||||||
use <headband.scad>;
|
use <headband.scad>;
|
||||||
|
|
||||||
thickness = 2.5;
|
thickness = 2.5;
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
101
hinge.scad
101
hinge.scad
|
|
@ -1,66 +1,53 @@
|
||||||
module hinge(deg, lb, la){
|
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]];
|
|
||||||
|
|
||||||
CutFaces = [
|
cut_points = [[6,0,5.5],
|
||||||
[0,2,4],
|
[6,7,5.5],
|
||||||
[1,5,3],
|
[4.5,0,7],
|
||||||
[0,1,3,2],
|
[4.5,7,7],
|
||||||
[0,4,5,1],
|
[6,0,7],
|
||||||
[2,3,5,4]];
|
[6,7,7]];
|
||||||
|
|
||||||
union(){
|
cut_faces = [[0,2,4],
|
||||||
difference(){
|
[1,5,3],
|
||||||
cube([6,7,6], center = false);
|
[0,1,3,2],
|
||||||
polyhedron(points = CutPoints, faces = CutFaces, convexity = 10);
|
[0,4,5,1],
|
||||||
translate([3,3.5,3.5]){
|
[2,3,5,4]];
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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]){
|
union(){
|
||||||
cube([4,3,4], center = false);
|
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);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cube([6.5,7,1.5], 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([3,3.5,3.5]){
|
translate([4,2,1.5]) cube([4,3,4], center = false);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
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);
|
||||||
}
|
translate([0,10,0]) hinge(30,0,0);
|
||||||
hinge(15,0,0);
|
translate([0,20,0]) hinge(45,0,0);
|
||||||
translate([0,10,0]) hinge(30,0,0);
|
translate([0,30,0]) hinge(60,0,0);
|
||||||
translate([0,20,0]) hinge(45,0,0);
|
translate([0,40,0]) hinge(90,0,0);
|
||||||
translate([0,30,0]) hinge(60,0,0);
|
|
||||||
translate([0,40,0]) hinge(90,0,0);
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue