trying to modify Sweep

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

trying to modify Sweep

jon_bondy
I'm trying to do something that seems conceptually simple to me, but it
keeps failing.

Rather than passing a parameter-less shape() function into sweep(), I am
passing a function with one parameter, the scale. This should allow me
to use a circular cross section to create a
snake-that-swallowed-a-grapefruit shape, by varying the scale dynamically.

In the implementation of sweep() I changed this function, as follows (I
calculate to_3d() of the shape() each time):

     function sweep_points() = flatten([for (i=[0:pathlen])
transform(path_transforms[i], to_3d(shape(i)))]);

I renamed sweep.scad to be sweep-jon.scad.  While sweep-jon.scad
compiles without errors, the invocation code (below) fails with"Ignoring
unknown function 'shape'" and then "PolySet has degenerate polygons".

What am I missing?


use <sweep-Jon.scad>

function f(a) = [18*sin(360*a), 18-18*cos(360*a*0.7), 36*sin(360*a/2)];

function shape(d) =
     [for (i=[1:10:360]) [d*sin(i), d*cos(i)]];

step = 0.005;
path = [for (t=[0:step:1-step]) f(t)];
path_transforms = construct_transform_path(path);
sweep(shape(), path_transforms);

--
Sent from my desktop computer.
I do not receive emails while away from my desk,
nor do I receive texts on my main phone number
(which is a land line).
If you know that I am on the road, please text me.
If you know that I am home, please email me.


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: trying to modify Sweep

nophead
You can't pass functions in OpenSCAD. You are simply passing in the result of calling the function with no argument. So inside sweep it has no access to shape().

On 2 January 2018 at 21:15, jon <[hidden email]> wrote:
I'm trying to do something that seems conceptually simple to me, but it keeps failing.

Rather than passing a parameter-less shape() function into sweep(), I am passing a function with one parameter, the scale. This should allow me to use a circular cross section to create a snake-that-swallowed-a-grapefruit shape, by varying the scale dynamically.

In the implementation of sweep() I changed this function, as follows (I calculate to_3d() of the shape() each time):

    function sweep_points() = flatten([for (i=[0:pathlen]) transform(path_transforms[i], to_3d(shape(i)))]);

I renamed sweep.scad to be sweep-jon.scad.  While sweep-jon.scad compiles without errors, the invocation code (below) fails with"Ignoring unknown function 'shape'" and then "PolySet has degenerate polygons".

What am I missing?


use <sweep-Jon.scad>

function f(a) = [18*sin(360*a), 18-18*cos(360*a*0.7), 36*sin(360*a/2)];

function shape(d) =
    [for (i=[1:10:360]) [d*sin(i), d*cos(i)]];

step = 0.005;
path = [for (t=[0:step:1-step]) f(t)];
path_transforms = construct_transform_path(path);
sweep(shape(), path_transforms);

--
Sent from my desktop computer.
I do not receive emails while away from my desk,
nor do I receive texts on my main phone number
(which is a land line).
If you know that I am on the road, please text me.
If you know that I am home, please email me.


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org