150 lines
4.2 KiB
OpenSCAD
150 lines
4.2 KiB
OpenSCAD
|
|
include <BOSL2/std.scad>;
|
|
|
|
section=20;
|
|
height=800;
|
|
depth=560;
|
|
width=563;
|
|
|
|
|
|
side_length = 20; // Length of each side of the square
|
|
thickness = 3; // Thickness of the material
|
|
|
|
$fn=32;
|
|
|
|
module miter_profile(length=200,height=30,depth=20) {
|
|
delta=1;
|
|
difference() {
|
|
cuboid([length,depth,height],anchor=CENTER,rounding=1);
|
|
miter(); // Right Miter
|
|
xflip() miter(); // Left Miter
|
|
}
|
|
module miter() {
|
|
translate([length/2, 0, -height/2])
|
|
yrot(-45)
|
|
color([0.5,0.5,0,0.5])
|
|
cube([height, depth+2*delta, height*sqrt(2)+2],anchor=CENTER+LEFT+BOT);
|
|
}
|
|
|
|
}
|
|
|
|
module miter_tube(length=200,height=30,depth=20,rounding=2,wall=1.5) {
|
|
delta=1;
|
|
|
|
translate([length,0,0])
|
|
//union() {
|
|
difference() {
|
|
left(length/2)
|
|
yrot(90)
|
|
rect_tube(size=[height,depth], wall=wall, h=length,rounding=rounding
|
|
//,anchor=F
|
|
,anchor=[1,0,0]
|
|
);
|
|
miter(-45); // Right Miter
|
|
//xflip() miter(); // Left Miter
|
|
translate([-length,0,0]) zrot(180) miter(-45); // Left Miter
|
|
}
|
|
module miter(rot) {
|
|
//translate([ length/2, 0, -height/2 ])
|
|
translate([0,0,0])
|
|
yrot(rot)
|
|
color([0.5,0.5,0,0.5])
|
|
cube([height, depth+2*delta, height*sqrt(2)+2],anchor=CENTER+LEFT+BOT);
|
|
}
|
|
|
|
}
|
|
|
|
// Visualize one piece
|
|
if (false )miter_profile();
|
|
|
|
if (false) {
|
|
// ydistribute(50)
|
|
translate([0,depth/2,0])
|
|
xrot(90) miter_tube(length=width,height=section,depth=section);
|
|
|
|
translate([0,-depth/2,0])
|
|
xrot(-90) miter_tube(length=width,height=section,depth=section);
|
|
|
|
}
|
|
|
|
/**
|
|
* Miter Tubes
|
|
*
|
|
*/
|
|
module miter_tubes(sections,height,depth,unfold=false){
|
|
echo(sections);
|
|
cumul=cumsum(sections);
|
|
moves=rotSlide(sections,unfold);
|
|
echo("moves",moves);
|
|
//assert(moves[0] ==[0,0,0,0,0,0], concat("Move 0 is wrong",moves[0]));
|
|
//assert(moves[1] ==[400,0,0,90,1,0], concat("Move 1 is wrong",moves[1]));
|
|
//assert(moves[2] ==[400,0,500,180,0,1], concat("Move 2 is wrong",moves[2]));
|
|
|
|
//assert(moves[1] ==[400,0,500,180,0], concat("Move 1 is wrong",moves[1]));
|
|
|
|
|
|
for (index = [0:len(sections)-1]) {
|
|
|
|
//if (index< 1) {
|
|
length = sections[index]; // Access the value at index i
|
|
slide = index == 0 ? 0: cumsum(sections)[index-1];
|
|
//m = index==0 ? [0,0,0,0] : moves[index-1];
|
|
m = moves[index];
|
|
x=m[0];
|
|
y=m[1];
|
|
z=m[2];
|
|
r=m[3];
|
|
echo("------------");
|
|
echo(concat("- tube",length," -"));
|
|
echo("------------");
|
|
echo("x",x,"y",y,"z",z,"r",r,"length",length);
|
|
translate([x,y, z])
|
|
yrot(-r)
|
|
//translate([0,40*index,0])
|
|
miter_tube(length=length,height=height,depth=depth);
|
|
//}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function rotSlide(v,unfold=false) =
|
|
v==[] ? [] : assert(is_consistent(v), "The input is not consistent." )
|
|
[
|
|
for (
|
|
//x = v[0],
|
|
x = 0,
|
|
y = 0,
|
|
z = 0,
|
|
r = 0,
|
|
|
|
xFactor = 0,
|
|
zFactor = 0,
|
|
idx = 0;
|
|
|
|
|
|
idx < len(v);
|
|
|
|
|
|
xFactor = r == 0 ? 1 : (r == 180 ? -1 : 0),
|
|
zFactor = r == 90 ? 1 : (r == 270 ? -1 : 0),
|
|
//echo("test"),
|
|
//x = i<len(v)+1 && r == 0 ? x+v[i]*xFactor : x,
|
|
x = idx < len(v) ? x+v[idx]*xFactor : x,
|
|
//y = i<len(v)+1 && r == 90 ? y+v[i]*yFactor : y,
|
|
|
|
//y = i < len(v) ? y+v[i]*yFactor : y ,
|
|
//z=0,
|
|
y = 0,
|
|
z = idx > 0 && idx < len(v) ? z+v[idx]*zFactor: z ,
|
|
r = r+(unfold ? 0 : 90),
|
|
idx = idx+1
|
|
)
|
|
[x,y,z,r,xFactor,zFactor]];
|
|
|
|
|
|
|
|
miter_tubes([400,500,600,700,800],30,20);
|
|
//echo ("rotSlide",rotSlide([400,500,600,500]));
|
|
|