discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

bend a pipe/tube

RS
Ralf Schlatterbeck
Wed, Apr 29, 2015 3:39 PM

On Wed, Apr 29, 2015 at 10:31:56AM -0400, Marius Kintel wrote:

On Apr 29, 2015, at 05:57 AM, biskero biskero@gmail.com wrote:

But I wanted to do it with a cylinder (in my case is a tube of oval section)
and apply a curve/bend at certain point to have one section straight and
rest shaped with that curve/bend.

There was a very similar feature request for this a while back:
https://github.com/openscad/openscad/issues/815

I've recently done something similar, in my case I've used the
combination of cube and (difference of) cylinder to create a small
skeleton outline, and then use minkowski with a sphere on this skeleton.

The cross-section of the resulting object isn't perfectly round (but the
smaller the skeleton is compared to the sphere this doesn't matter).

This gets painfully slow on rendering, though (but I've probably used
too many faces).
In my case I've computed the difference of two such objects (with the
second one translated).

The resulting STL is here:
http://project.runtux.com/lawnmowerpart.stl
the OpenSCAD code is on github:
https://github.com/rsc3d/rsc3d/blob/master/lawnmowerpart.scad

The relevant code is in the module "bow" (and "bows" to compute the
difference).

Ralf

Dr. Ralf Schlatterbeck                  Tel:  +43/2243/26465-16
Open Source Consulting                  www:  http://www.runtux.com
Reichergasse 131, A-3411 Weidling      email: office@runtux.com
allmenda.com member                    email: rsc@allmenda.com

On Wed, Apr 29, 2015 at 10:31:56AM -0400, Marius Kintel wrote: > On Apr 29, 2015, at 05:57 AM, biskero <biskero@gmail.com> wrote: > > > But I wanted to do it with a cylinder (in my case is a tube of oval section) > > and apply a curve/bend at certain point to have one section straight and > > rest shaped with that curve/bend. > > > There was a very similar feature request for this a while back: > https://github.com/openscad/openscad/issues/815 I've recently done something similar, in my case I've used the combination of cube and (difference of) cylinder to create a small skeleton outline, and then use minkowski with a sphere on this skeleton. The cross-section of the resulting object isn't perfectly round (but the smaller the skeleton is compared to the sphere this doesn't matter). This gets painfully slow on rendering, though (but I've probably used too many faces). In my case I've computed the difference of two such objects (with the second one translated). The resulting STL is here: http://project.runtux.com/lawnmowerpart.stl the OpenSCAD code is on github: https://github.com/rsc3d/rsc3d/blob/master/lawnmowerpart.scad The relevant code is in the module "bow" (and "bows" to compute the difference). Ralf -- Dr. Ralf Schlatterbeck Tel: +43/2243/26465-16 Open Source Consulting www: http://www.runtux.com Reichergasse 131, A-3411 Weidling email: office@runtux.com allmenda.com member email: rsc@allmenda.com
CL
Chow Loong Jin
Thu, Apr 30, 2015 5:14 AM

On Wed, Apr 29, 2015 at 07:50:34AM -0700, biskero wrote:

Ciao,

here is code I found to create a ellipse tube based on torus, but it's
pretty slow when I compile it into my design, OpenSCAD starts thinking!!! :)
Any suggestion how to speed this code?

		translate([0,0,-r2-1])
		linear_extrude(height=2*r2+2)
     		polygon([
	            [0,0],
	            [trx * cos(a0), try * sin(a0)],
	            [trx * cos(a1), try * sin(a1)],
	            [trx * cos(a2), try * sin(a2)],
	            [trx * cos(a3), try * sin(a3)],
	            [trx * cos(a4), try * sin(a4)],
	            [0,0]
	       ]);

This bit can be done using pieSlice() from MCAD.

--
Kind regards,
Loong Jin

On Wed, Apr 29, 2015 at 07:50:34AM -0700, biskero wrote: > Ciao, > > > here is code I found to create a ellipse tube based on torus, but it's > pretty slow when I compile it into my design, OpenSCAD starts thinking!!! :) > Any suggestion how to speed this code? > > translate([0,0,-r2-1]) > linear_extrude(height=2*r2+2) > polygon([ > [0,0], > [trx * cos(a0), try * sin(a0)], > [trx * cos(a1), try * sin(a1)], > [trx * cos(a2), try * sin(a2)], > [trx * cos(a3), try * sin(a3)], > [trx * cos(a4), try * sin(a4)], > [0,0] > ]); This bit can be done using pieSlice() from MCAD. -- Kind regards, Loong Jin
B
biskero
Thu, Apr 30, 2015 4:52 PM

Ciao,

I looked at what you said about changing the following code but not sure how
to do it with the lib you mention:

translate([0,0,-r2-1])
linear_extrude(height=2*r2+2)
polygon([
[0,0],
[trx * cos(a0), try * sin(a0)],
[trx * cos(a1), try * sin(a1)],
[trx * cos(a2), try * sin(a2)],
[trx * cos(a3), try * sin(a3)],
[trx * cos(a4), try * sin(a4)],
[0,0]
]);

how do I do it?

Thanks
Alessandro

--
View this message in context: http://forum.openscad.org/bend-a-pipe-tube-tp12503p12523.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Ciao, I looked at what you said about changing the following code but not sure how to do it with the lib you mention: translate([0,0,-r2-1]) linear_extrude(height=2*r2+2) polygon([ [0,0], [trx * cos(a0), try * sin(a0)], [trx * cos(a1), try * sin(a1)], [trx * cos(a2), try * sin(a2)], [trx * cos(a3), try * sin(a3)], [trx * cos(a4), try * sin(a4)], [0,0] ]); how do I do it? Thanks Alessandro -- View this message in context: http://forum.openscad.org/bend-a-pipe-tube-tp12503p12523.html Sent from the OpenSCAD mailing list archive at Nabble.com.
CL
Chow Loong Jin
Fri, May 1, 2015 5:09 PM

On Thu, Apr 30, 2015 at 09:52:03AM -0700, biskero wrote:

Ciao,

I looked at what you said about changing the following code but not sure how
to do it with the lib you mention:

translate([0,0,-r2-1])
linear_extrude(height=2*r2+2)
polygon([
[0,0],
[trx * cos(a0), try * sin(a0)],
[trx * cos(a1), try * sin(a1)],
[trx * cos(a2), try * sin(a2)],
[trx * cos(a3), try * sin(a3)],
[trx * cos(a4), try * sin(a4)],
[0,0]
]);

translate([0,0,-r2-1])
linear_extrude(height=2*r2+2)
pieSlice (size = max (trx, try), start_angle = start_angle, end_angle = end_angle);

By the way, I'll just leave this here as another sweep() example:

use <MCAD/general/sweep.scad>
use <MCAD/general/facets.scad>
use <scad-utils/shapes.scad>
use <scad-utils/transformations.scad>

$fs = 0.4;
$fa = 1;

function cot (angle) = 1 / tan (angle);

module elliptical_torus (r_x, r_y, cross_section_r)
{
cross_section = circle (r = cross_section_r,
$fn = get_fragments_from_r (cross_section_r));

// from http://math.stackexchange.com/questions/432902/
function radius_at_angle (angle) = (
    (r_x * r_y) /
    sqrt (pow (r_x * sin (angle), 2) + pow (r_y * cos (angle), 2))
);

// g, flattening factor as per wiki
flattening_factor = 1 - r_y / r_x;
function tangential_angle (polar_angle) = (
    ((polar_angle % 360 > 180) ? 180 : 0) +
    atan (-1 / (tan (polar_angle) / pow (1 - flattening_factor, 2)))
);

sweep (
    cross_section,
    [
        for (t = gen_facet_series (min (r_x, r_y)))
        let (angle = t * 360)
        translation ([r_x * cos (angle), r_y * sin (angle), 0]) *
        rotation ([0, 0, 90 + tangential_angle (angle)]) *
        rotation ([90, 0, 0])
    ],
    true
);

}

elliptical_torus (r_x = 40, r_y = 20, cross_section_r = 2);

--
Kind regards,
Loong Jin

On Thu, Apr 30, 2015 at 09:52:03AM -0700, biskero wrote: > Ciao, > > I looked at what you said about changing the following code but not sure how > to do it with the lib you mention: > > translate([0,0,-r2-1]) > linear_extrude(height=2*r2+2) > polygon([ > [0,0], > [trx * cos(a0), try * sin(a0)], > [trx * cos(a1), try * sin(a1)], > [trx * cos(a2), try * sin(a2)], > [trx * cos(a3), try * sin(a3)], > [trx * cos(a4), try * sin(a4)], > [0,0] > ]); translate([0,0,-r2-1]) linear_extrude(height=2*r2+2) pieSlice (size = max (trx, try), start_angle = start_angle, end_angle = end_angle); By the way, I'll just leave this here as another sweep() example: use <MCAD/general/sweep.scad> use <MCAD/general/facets.scad> use <scad-utils/shapes.scad> use <scad-utils/transformations.scad> $fs = 0.4; $fa = 1; function cot (angle) = 1 / tan (angle); module elliptical_torus (r_x, r_y, cross_section_r) { cross_section = circle (r = cross_section_r, $fn = get_fragments_from_r (cross_section_r)); // from http://math.stackexchange.com/questions/432902/ function radius_at_angle (angle) = ( (r_x * r_y) / sqrt (pow (r_x * sin (angle), 2) + pow (r_y * cos (angle), 2)) ); // g, flattening factor as per wiki flattening_factor = 1 - r_y / r_x; function tangential_angle (polar_angle) = ( ((polar_angle % 360 > 180) ? 180 : 0) + atan (-1 / (tan (polar_angle) / pow (1 - flattening_factor, 2))) ); sweep ( cross_section, [ for (t = gen_facet_series (min (r_x, r_y))) let (angle = t * 360) translation ([r_x * cos (angle), r_y * sin (angle), 0]) * rotation ([0, 0, 90 + tangential_angle (angle)]) * rotation ([90, 0, 0]) ], true ); } elliptical_torus (r_x = 40, r_y = 20, cross_section_r = 2); -- Kind regards, Loong Jin