request for relative_extrude

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

request for relative_extrude

Neon22
The current linear_extrude works well but cannot make objects that taper or do certain kinds of rotation or translation effects.
My request is for either:
- a relative flag added to linear_extrude, or
- a new command relative_extrude or similar.

Here is a taper module:
module create_taper(length, z_pos, hole_dia, taper_factor, count=20) {
        // incremental hull() of pairs of exp cylinders
	dist = length/count;
	factor = taper_factor/dist;
	for (i = [0:count]) {
		hull () {
			translate([dist*i, 0,z_pos])
			rotate([0,90,0])
				cylinder(r=exp(ln(hole_dia)+i/factor));
                        // this second shape is the next step duplicated within this one.
			translate([dist*(i+1), 0,z_pos])
			rotate([0,90,0])
				cylinder(r=exp(ln(hole_dia)+(i+1)/factor));
		}
	}
}


create_taper(10,0,5,8);
Taper using hull()
This works by incrementally combining the hull() of a pair of cylinders, where the diameter expands exponentially..
Instead I propose something like this:
dist = 10;
dia = 4;
module my_profile(dia) {
	circle(d=dia );
};

relative_extrude(steps=10) {
	translate([0, 0, dist/steps])
	cylinder(d=dia));
        // or circle(d=dia);
        // or myprofile(dia);
};
// OR with profile as an argument
relative_extrude(steps=10, profile=my_profile) {
	translate([0, 0, dist/steps])
        scale([1, 1, 0.9])
        profile;
The idea is bit like a macro in a lisp-like language. It would create an implied let() with 'step' defined as a for variable incrementing from [0:steps].
This could be used as a factor within each iteration.
At each iteration the new shape(2D) would be created based on the previous one.
So rotates will be local around the center of the previous face and the face normal would define the Z axis for the next step.
This way many kinds of shapes can be represented including ones that curve and twist relative for each step.
E.g.
dist = 10;
relative_extrude(steps=36) {
     rotate([5,0,0]) 
     translate([0,0,dist]])
     scale([1,1,0.95])
     polygon([..],[..],...]);
}
Would create a 180 degree arc in X of the polygon tapering by 95% each iteration.

If using the existing linear extrude, and adding a relative flag, then not as many shapes can be created. The flag would be interpreted as indicating that the next step is local to the just-created face.

I suspect there is a way to do this in the current OpenSCAD using multmatrix, projection, children(), and hull().
But I am proposing making it work differently and perhaps more simply for OpenSCAD2.