Documentation
This commit is contained in:
parent
618cee124f
commit
c7a0fb7b2d
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.DS_Store
|
32
Readme.md
32
Readme.md
@ -3,4 +3,36 @@
|
||||
Libraries for Metal makers
|
||||
|
||||
|
||||
## Miter tubes module
|
||||
|
||||
|
||||
This module generates a sequence of mitered tubes based on the provided section lengths, with options for customizing their dimensions and unfolding their arrangement.
|
||||
|
||||
Parameters:
|
||||
- `sections` (array): An array of section lengths, each specifying the length of an individual tube.
|
||||
Example: `[10, 20, 30]` will create three tubes of lengths 10, 20, and 30 units respectively.
|
||||
|
||||
- `height` (number): The height of each tube. This value defines the dimension perpendicular
|
||||
to the tube's length and depth.
|
||||
|
||||
- `depth` (number): The depth of each tube. This value defines the dimension perpendicular
|
||||
to the tube's length and height.
|
||||
|
||||
- `unfold` (boolean, optional): Determines whether the sequence of tubes should be unfolded
|
||||
for easier visualization or fabrication. When `true`, the tubes are laid out in a flat arrangement.
|
||||
Defaults to `false`.
|
||||
|
||||
As an example let's create metalon arch :
|
||||
```python
|
||||
include <BOSL2/std.scad>;
|
||||
include <Metalib/metalib.scad>;
|
||||
|
||||
yrot(-90)
|
||||
miter_tubes([400,500,400],30,20,start=false,end=false);
|
||||
``
|
||||
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
|
195
metalib.scad
195
metalib.scad
@ -1,6 +1,7 @@
|
||||
|
||||
include <BOSL2/std.scad>;
|
||||
|
||||
/*
|
||||
section=20;
|
||||
height=800;
|
||||
depth=560;
|
||||
@ -9,7 +10,7 @@ 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) {
|
||||
@ -25,27 +26,83 @@ module miter_profile(length=200,height=30,depth=20) {
|
||||
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) {
|
||||
|
||||
|
||||
/**
|
||||
* Miter Tubes Module
|
||||
*
|
||||
* This module generates a sequence of mitered tubes based on the provided section lengths,
|
||||
* with options for customizing their dimensions and unfolding their arrangement.
|
||||
*
|
||||
* Parameters:
|
||||
* - `sections` (array): An array of section lengths, each specifying the length of an individual tube.
|
||||
* Example: `[10, 20, 30]` will create three tubes of lengths 10, 20, and 30 units respectively.
|
||||
*
|
||||
* - `height` (number): The height of each tube. This value defines the dimension perpendicular
|
||||
* to the tube's length and depth.
|
||||
*
|
||||
* - `depth` (number): The depth of each tube. This value defines the dimension perpendicular
|
||||
* to the tube's length and height.
|
||||
*
|
||||
* - `unfold` (boolean, optional): Determines whether the sequence of tubes should be unfolded
|
||||
* for easier visualization or fabrication. When `true`, the tubes are laid out in a flat arrangement.
|
||||
* Defaults to `false`.
|
||||
*
|
||||
* Internal Variables and Process:
|
||||
* - `moves` (array): Computed positions and rotations for each tube, determined by the `rotSlide`
|
||||
* function applied to the `sections` and `unfold` parameters.
|
||||
*
|
||||
* - Loop: Iterates through the `sections` array to position and render each tube with the following steps:
|
||||
* 1. Extracts the length of the current tube.
|
||||
* 2. Retrieves the computed translation and rotation values for the tube from the `moves` array.
|
||||
* 3. Logs debugging information about the current tube's dimensions and transformations.
|
||||
* 4. Translates and rotates the coordinate system to align with the tube's placement.
|
||||
* 5. Calls the `miter_tube` submodule to render the individual tube with specified dimensions.
|
||||
*
|
||||
* Submodules:
|
||||
* - `miter_tube`: A separate submodule (not defined here) that handles the actual geometry creation
|
||||
* for each tube, based on its length, height, and depth.
|
||||
*
|
||||
* Usage:
|
||||
* ```
|
||||
* miter_tubes([10, 20, 30], height=5, depth=3, unfold=true);
|
||||
* ```
|
||||
*/
|
||||
module miter_tubes( sections, height, depth, start=true,end=true,unfold=false){
|
||||
for (index = [0:len(sections)-1]) {
|
||||
length = sections[index];
|
||||
m = computeSectionPositions( sections, unfold )[index];
|
||||
translate([m[0],m[1], m[2]])
|
||||
yrot(-m[3])
|
||||
miter_tube( length, height, depth, start = index==0 ? start : true,end = index==len(sections)-1 ? end : true );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a mitered tube with specified dimensions, wall thickness, and rounding.
|
||||
*
|
||||
* Parameters:
|
||||
* - `length` (number): The length of the tube along its main axis (default: 200).
|
||||
* - `height` (number): The height of the rectangular cross-section (default: 30).
|
||||
* - `depth` (number): The depth of the rectangular cross-section (default: 20).
|
||||
* - `rounding` (number): The rounding radius of the tube's edges (default: 2).
|
||||
* - `wall` (number): The thickness of the tube walls (default: 1.5).
|
||||
* - `start` (boolean): TRue if a miter cut should be done at the start position
|
||||
* - `end` (boolean): TRue if a miter cut should be done at the end position
|
||||
*/
|
||||
module miter_tube(length=200,height=30,depth=20,rounding=2,wall=1.5,start=true,end=true) {
|
||||
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
|
||||
rect_tube(size=[height,depth], wall=wall, h=length,rounding=rounding, anchor=[1,0,0]);
|
||||
if ( end ) miter(-45); // Right Miter
|
||||
if ( start ) 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])
|
||||
@ -54,96 +111,44 @@ module miter_tube(length=200,height=30,depth=20,rounding=2,wall=1.5) {
|
||||
|
||||
}
|
||||
|
||||
// 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
|
||||
* Computes the positions and rotations for sections of a tube structure.
|
||||
*
|
||||
* Parameters:
|
||||
* - `v` (array): An array of section lengths. Each element represents the length of a tube segment.
|
||||
* - `unfold` (boolean, optional): If true, the structure is laid flat, skipping rotation increments.
|
||||
* Defaults to `false`.
|
||||
*
|
||||
* Returns:
|
||||
* - An array of 4-element arrays, each representing the position and rotation of a section in the form [x, y, z, r]:
|
||||
* - `x`, `y`, `z`: The computed coordinates for the section.
|
||||
* - `r`: The rotation angle for the section.
|
||||
*
|
||||
* Example:
|
||||
* computeSectionPositions([10, 20, 30], unfold=false);
|
||||
* // Returns computed positions and rotations for each section.
|
||||
*/
|
||||
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." )
|
||||
[
|
||||
|
||||
function computeSectionPositions(sections, unfold=false) =
|
||||
sections == [] ? [] :
|
||||
assert(is_consistent(sections), "Input array 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 = 0, y = 0, z = 0, r = 0, idx = 0;
|
||||
idx < len(sections);
|
||||
xFactor = r == 0 ? 1 : (r == 180 ? -1 : 0),
|
||||
zFactor = r == 90 ? 1 : (r == 270 ? -1 : 0),
|
||||
x = x + sections[idx] * xFactor,
|
||||
z = z + sections[idx] * zFactor,
|
||||
r = r + (unfold ? 0 : 90),
|
||||
idx = idx + 1
|
||||
)
|
||||
[x,y,z,r,xFactor,zFactor]];
|
||||
|
||||
[x, y, z, r]
|
||||
];
|
||||
|
||||
|
||||
|
||||
miter_tubes([400,500,600,700,800],30,20);
|
||||
//miter_tubes([400,500,600,700,800],30,20);
|
||||
//echo ("rotSlide",rotSlide([400,500,600,500]));
|
||||
|
||||
|
BIN
resources/arch.png
Normal file
BIN
resources/arch.png
Normal file
Binary file not shown.
After ![]() (image error) Size: 28 KiB |
Loading…
x
Reference in New Issue
Block a user