discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Lib for linear extrusion with curvy profile?

A
amundsen
Fri, Jun 26, 2020 2:14 PM

Hello,

I am trying to extrude shapes linearly but with a curvy profile, not a
linear one.

Currently, I've succeeded globally by stacking linear extrusions and using a
2d vector for the embedded scaling but it's a bit complicated.

http://forum.openscad.org/file/t2715/curvy_extrusion.jpg

I couldn't find a good library to achieve this but maybe I haven't looked at
the right place...

--
Sent from: http://forum.openscad.org/

Hello, I am trying to extrude shapes linearly but with a curvy profile, not a linear one. Currently, I've succeeded globally by stacking linear extrusions and using a 2d vector for the embedded scaling but it's a bit complicated. <http://forum.openscad.org/file/t2715/curvy_extrusion.jpg> I couldn't find a good library to achieve this but maybe I haven't looked at the right place... -- Sent from: http://forum.openscad.org/
A
adrianv
Fri, Jun 26, 2020 4:21 PM

It's a little bit unclear what exactly you want to do.  But there's likely
already existing libraries that do it.

Several libraries have a sweep operation of some sort that constructs a
solid by linking together transformations of an initial polygon.

Some that I'm aware of are the original list-comprehension-demos, dotSCAD
and BOSL2.  The first one is old and has some issues with the latest version
of openscad.  A basic sweep concept is to take a polygon and "sweep" it
along a curved path, line a linear extrude that follows a nonlinear path.
(There's quite a bit of hidden complexity having to do with orientation of
the polygon, however.)  The most general sweep concept is to use a series of
arbitrary transformation operators to define a sequence of polygons.

Another operation is to link together a sequence of polygons that might be
unrelated, so a square could morph into a circle, or perhaps a hexagon.
List-comprehension-demos included a skin() operator which does this (sort
of) and BOSL2 includes code that can handle polygons with dissimilar numbers
of vertices.

BOSL2 also includes offset_sweep which constructs a polyhedron by a sequence
of offset operations.  This is useful for creating a shape with a constant
wall thickness.

For BOSL2 skin, sweep and path_sweep see:
https://github.com/revarbat/BOSL2/wiki/skin.scad

And for offset_sweep:
https://github.com/revarbat/BOSL2/wiki/rounding.scad#offset_sweep

Other references:

https://github.com/RonaldoCMP/list-comprehension-demos
https://github.com/JustinSDK/dotSCAD

--
Sent from: http://forum.openscad.org/

It's a little bit unclear what exactly you want to do. But there's likely already existing libraries that do it. Several libraries have a sweep operation of some sort that constructs a solid by linking together transformations of an initial polygon. Some that I'm aware of are the original list-comprehension-demos, dotSCAD and BOSL2. The first one is old and has some issues with the latest version of openscad. A basic sweep concept is to take a polygon and "sweep" it along a curved path, line a linear extrude that follows a nonlinear path. (There's quite a bit of hidden complexity having to do with orientation of the polygon, however.) The most general sweep concept is to use a series of arbitrary transformation operators to define a sequence of polygons. Another operation is to link together a sequence of polygons that might be unrelated, so a square could morph into a circle, or perhaps a hexagon. List-comprehension-demos included a skin() operator which does this (sort of) and BOSL2 includes code that can handle polygons with dissimilar numbers of vertices. BOSL2 also includes offset_sweep which constructs a polyhedron by a sequence of offset operations. This is useful for creating a shape with a constant wall thickness. For BOSL2 skin, sweep and path_sweep see: https://github.com/revarbat/BOSL2/wiki/skin.scad And for offset_sweep: https://github.com/revarbat/BOSL2/wiki/rounding.scad#offset_sweep Other references: https://github.com/RonaldoCMP/list-comprehension-demos https://github.com/JustinSDK/dotSCAD -- Sent from: http://forum.openscad.org/
A
amundsen
Fri, Jun 26, 2020 6:44 PM

I 've tried with sweep but I've had some issues so I have finally tried with
a for loop and linear_extrude.

I've just managed to do it.

Happy!

// essai scale linear_extrude
length = 100;
width = 40;
height = 10;
edge_thickn = 10;
// length and width at bottom
start_l = length - 2 * edge_thickn;
start_w = width - 2 * edge_thickn;
// difference between top and bottom (delta)
diff_l = length - start_l;
diff_w = width - start_w;
steps = 50;

for(i = [0:steps-1]) {
z_pos = i/steps * height;
step_height = height/steps;
local_start_l = i/steps * diff_l + start_l;
local_start_w = i/steps * diff_w + start_w;
local_target_l = (i+1)/steps * diff_l + start_l;
local_target_w = (i+1)/steps * diff_w + start_w;
local_l_factor = local_start_l/local_target_l;
local_w_factor = local_start_w/local_target_w;

color( c = [sqrt(1 - i/(steps- 1)), sqrt(i/(steps-1)), sqrt(i/(steps-1)),

1.])
translate([0,0,z_pos])
linear_extrude(step_height, convexity = 10, slices = 1, scale =
[1/local_l_factor, 1/local_w_factor])
resize([local_target_l * local_l_factor, local_target_w * local_w_factor,
1]) square([1, 1], center = true);
}

--
Sent from: http://forum.openscad.org/

I 've tried with sweep but I've had some issues so I have finally tried with a for loop and linear_extrude. I've just managed to do it. Happy! // essai scale linear_extrude length = 100; width = 40; height = 10; edge_thickn = 10; // length and width at bottom start_l = length - 2 * edge_thickn; start_w = width - 2 * edge_thickn; // difference between top and bottom (delta) diff_l = length - start_l; diff_w = width - start_w; steps = 50; for(i = [0:steps-1]) { z_pos = i/steps * height; step_height = height/steps; local_start_l = i/steps * diff_l + start_l; local_start_w = i/steps * diff_w + start_w; local_target_l = (i+1)/steps * diff_l + start_l; local_target_w = (i+1)/steps * diff_w + start_w; local_l_factor = local_start_l/local_target_l; local_w_factor = local_start_w/local_target_w; color( c = [sqrt(1 - i/(steps- 1)), sqrt(i/(steps-1)), sqrt(i/(steps-1)), 1.]) translate([0,0,z_pos]) linear_extrude(step_height, convexity = 10, slices = 1, scale = [1/local_l_factor, 1/local_w_factor]) resize([local_target_l * local_l_factor, local_target_w * local_w_factor, 1]) square([1, 1], center = true); } -- Sent from: http://forum.openscad.org/
A
adrianv
Fri, Jun 26, 2020 8:31 PM

Is this all about the color?  Because the geometry in your example has no
curves and can be produced by a single linear_extrude call:

linear_extrude(height=height, scale = [length/start_l, width/start_w])
translate(-[start_l,start_w]/2)square([start_l, start_w]);

--
Sent from: http://forum.openscad.org/

Is this all about the color? Because the geometry in your example has no curves and can be produced by a single linear_extrude call: linear_extrude(height=height, scale = [length/start_l, width/start_w]) translate(-[start_l,start_w]/2)square([start_l, start_w]); -- Sent from: http://forum.openscad.org/
C
caterpillar
Sat, Jun 27, 2020 2:32 AM

You want this?

use <bezier_curve.scad>;
use <hull_polyline3d.scad>;
use <sweep.scad>;
use <paths2sections.scad>;

t_step = 0.1;
width = 2;

p0 = [50, 10, 0];
p1 = [45, 5, 7.5];
p2 = [45, 5, 15];

curvy_profile1 = bezier_curve(t_step, [p0, p1, p2]);
curvy_profile2 = [for(p = curvy_profile1) [-p[0], p[1], p[2]]];
curvy_profile3 = [for(p = curvy_profile1) [-p[0], -p[1], p[2]]];
curvy_profile4 = [for(p = curvy_profile1) [p[0], -p[1], p[2]]];

sections = paths2sections([
    curvy_profile1,
    curvy_profile2,
    curvy_profile3,
    curvy_profile4
]); 

#hull_polyline3d(curvy_profile1, width);  

sweep(sections);

http://forum.openscad.org/file/t1825/demo.jpg


https://openhome.cc

Sent from: http://forum.openscad.org/

You want this? use <bezier_curve.scad>; use <hull_polyline3d.scad>; use <sweep.scad>; use <paths2sections.scad>; t_step = 0.1; width = 2; p0 = [50, 10, 0]; p1 = [45, 5, 7.5]; p2 = [45, 5, 15]; curvy_profile1 = bezier_curve(t_step, [p0, p1, p2]); curvy_profile2 = [for(p = curvy_profile1) [-p[0], p[1], p[2]]]; curvy_profile3 = [for(p = curvy_profile1) [-p[0], -p[1], p[2]]]; curvy_profile4 = [for(p = curvy_profile1) [p[0], -p[1], p[2]]]; sections = paths2sections([ curvy_profile1, curvy_profile2, curvy_profile3, curvy_profile4 ]); #hull_polyline3d(curvy_profile1, width); sweep(sections); <http://forum.openscad.org/file/t1825/demo.jpg> ----- https://openhome.cc -- Sent from: http://forum.openscad.org/
RP
Ronaldo Persiano
Sat, Jun 27, 2020 5:01 AM

Em sex., 26 de jun. de 2020 às 19:44, amundsen roald.baudoux@brutele.be
escreveu:

I 've tried with sweep but I've had some issues so I have finally tried
with
a for loop and linear_extrude.

I've just managed to do it.

Your Idea is good but there is no curvature in the rising edges.

I guess your intention might be something like this:

// any increasing function such that
//  f(0) = 0 and f(steps) = 1
//
//function f(x) = x/steps;
//function f(x) = (x-2x(steps-x)(1+(steps/2-x))/steps/steps)/steps;
//function f(x) = 1-sin(x/steps
70)/sin(70);
function f(x) = (x-0.4x(steps-x)/steps)/steps;

echo(f0 = f(0), f1=f(steps));

for(i = [0:steps-1]) {
z_pos = i/steps * height;
step_height    = height/steps;
local_start_l  = f(i) * diff_l + start_l;
local_start_w  = f(i) * diff_w + start_w;
local_target_l = f(i+1) * diff_l + start_l;
local_target_w = f(i+1) * diff_w + start_w;
local_l_factor = local_start_l/local_target_l;
local_w_factor = local_start_w/local_target_w;

    color( c = [sqrt(1 - i/(steps- 1)), sqrt(i/(steps-1)),

sqrt(i/(steps-1)),
1.])
translate([0,0,z_pos])
linear_extrude(step_height, convexity = 10, slices = 1,
scale = [1/local_l_factor, 1/local_w_factor])
resize([local_target_l * local_l_factor, local_target_w *
local_w_factor,1])
square([1, 1], center = true);
}

Em sex., 26 de jun. de 2020 às 19:44, amundsen <roald.baudoux@brutele.be> escreveu: > I 've tried with sweep but I've had some issues so I have finally tried > with > a for loop and linear_extrude. > > I've just managed to do it. > > Your Idea is good but there is no curvature in the rising edges. I guess your intention might be something like this: // any increasing function such that // f(0) = 0 and f(steps) = 1 // //function f(x) = x/steps; //function f(x) = (x-2*x*(steps-x)*(1+(steps/2-x))/steps/steps)/steps; //function f(x) = 1-sin(x/steps*70)/sin(70); function f(x) = (x-0.4*x*(steps-x)/steps)/steps; echo(f0 = f(0), f1=f(steps)); for(i = [0:steps-1]) { z_pos = i/steps * height; step_height = height/steps; local_start_l = f(i) * diff_l + start_l; local_start_w = f(i) * diff_w + start_w; local_target_l = f(i+1) * diff_l + start_l; local_target_w = f(i+1) * diff_w + start_w; local_l_factor = local_start_l/local_target_l; local_w_factor = local_start_w/local_target_w; color( c = [sqrt(1 - i/(steps- 1)), sqrt(i/(steps-1)), sqrt(i/(steps-1)), 1.]) translate([0,0,z_pos]) linear_extrude(step_height, convexity = 10, slices = 1, scale = [1/local_l_factor, 1/local_w_factor]) resize([local_target_l * local_l_factor, local_target_w * local_w_factor,1]) square([1, 1], center = true); }
A
amundsen
Wed, Jul 1, 2020 6:32 AM

@adrianv you're right the pasted example was linear and I've achieved this
but not with that code but to me the trickiest part was to manage the growth
for each layer. The model shown the picture below was made with a similar
code using a sine profile for the inner curve.

@caterpillar very interesting and concise. However I had to modify the calls
to libraries like this to make it function:

use <dotSCAD/src/bezier_curve.scad>;
use <dotSCAD/src/hull_polyline3d.scad>;
use <dotSCAD/src/sweep.scad>;
use <dotSCAD/src/paths2sections.scad>;

Thank you everyone.

http://forum.openscad.org/file/t2715/curvy_extrusion_2.jpg

--
Sent from: http://forum.openscad.org/

@adrianv you're right the pasted example was linear and I've achieved this but not with that code but to me the trickiest part was to manage the growth for each layer. The model shown the picture below was made with a similar code using a sine profile for the inner curve. @caterpillar very interesting and concise. However I had to modify the calls to libraries like this to make it function: use <dotSCAD/src/bezier_curve.scad>; use <dotSCAD/src/hull_polyline3d.scad>; use <dotSCAD/src/sweep.scad>; use <dotSCAD/src/paths2sections.scad>; Thank you everyone. <http://forum.openscad.org/file/t2715/curvy_extrusion_2.jpg> -- Sent from: http://forum.openscad.org/
AP
Alexander Pruss
Wed, Jul 1, 2020 4:43 PM

My tubemesh library allows you to do that with a lot of flexibility:
https://www.thingiverse.com/thing:2406760

--
Sent from: http://forum.openscad.org/

My tubemesh library allows you to do that with a lot of flexibility: https://www.thingiverse.com/thing:2406760 -- Sent from: http://forum.openscad.org/