New forum member, extruding along path

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

New forum member, extruding along path

gasstationwithoutpumps
Hi, I'm new to the OpenSCAD forum, but I've been using OpenSCAD for about a year (you can see a few of my rather simple designs at https://www.thingiverse.com/gasstationwithoutpumps/things), with more discussion of them and some unreleased design on my blog at https://gasstationwithoutpumps.wordpress.com). I came to this forum looking for information on how to do something that I see as one of the biggest holes in OpenSCAD: extruding along an arbitrary path. I found out about sweep.scad in the list comprehension demos, which provides a somewhat klugey workaround—I have to have a polygon and a polygonal path expressed as arrays of points (perhaps with an additional array of orientation vectors), but what I wanted to start with was an SVG file with a cross-section and an SVG file of the paths. Unfortunately, OpenSCAD can convert arrays to geometry, but then provides no way to extract the arrays again from the geometry. So I can import SVG into OpenSCAD, but not use the resulting imported objects as either the cross-sectional profile or as the path. One of the biggest things on my wish list is a way to get arrays of points from objects. I found another link to an inkscape plug-in, https://www.thingiverse.com/thing:2805184, that converts SVG files to arrays of Bézier curves, which almost completes the task. After playing around with both, I found some minor bugs: The definition of "cap" in sweep_polyhedron relied on a test of len(caps), which is not acceptable to the 2019-05 release. I changed it to
cap     =  (closed || caps==[]) ? [false,false]:
                    (caps==true || caps==false)?      [caps,caps] :
                   (len(caps)==1) ?         [caps[0], caps[0]] :
                    inv ?                    [caps[1], caps[0]] :
                                             [caps[0], caps[1]]
removing the error message. There are several other places in the list comprehension demo code where similar tests relying on len(non_list) being legal and returning undef are used, but that "feature" seems to have been deprecated. For the inkscape plugin, I ran into two problems:
  • One was that a group scaling in my SVG file got applied twice so that the cross-sectional profile was 96/25.4 times larger that it should have been. Luckily this could be compensated for by scaling the output arrray, and OpenScad makes multiplying an array by a constant easy.
  • A bigger annoyance was that the output created a polygon for each path in the SVG file, when many of the paths were open paths. I had to edit the output code to make functions that returned the bezier_coordinates for each array of points, rather than making a union of the bezier_polygons in a module. Then I could use the points (with to_3d() and referenced_path_transforms()) to do a sweep. I'd like for the Inkscape plugin to create those functions for me, so I can just "use" the output .scad file without having to edit it.
I managed to get everything sort of working, but I still have some minor problems:
  • If the number of steps in bezier_coordinates() is too high, then the tangent computations at the end of the path end up producing "undef", and an ugly artifact is created at the end of the path. I think that this may be related to OpenSCAD rounding to a coarse grid, so that multiple points in a row are identical and the tangent is indeed undefined. I fixed this problem by keeping the number of steps small (6 was ok, 10 was too many for the curves I was using).
  • The CGAL interpretation failed, probably because the tubes produced by the sweep were not capped, and I had not buried the ends of all of them in other geometry. I can probably fix this by more careful placement of the end points.
I would like to thank the creators of the list comprehension demos and the Inkscape plugin, because I certainly would not have had the patience to create them myself. I hope that sometime soon extruding along a path becomes a built-in to OpenSCAD, and that the language is extended so that paths can be turned into arrays of points.

Sent from the OpenSCAD mailing list archive at Nabble.com.

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

Re: New forum member, extruding along path

cgriffith
I think I do something similar to what your asking.  I make cookie cutters
for my wife.  The outline of cookie cutter is created as SVG in inkscape.  I
use the inkscape extension from  https://www.thingiverse.com/thing:2805184
<https://www.thingiverse.com/thing:2805184>   to convert SVG to bezier
points in scad file.  Then I created a custom SVG in inkscape that is the
profile of the cutter; pulled into scad file as another bezier path.
Finally, I use the  BOSL <https://github.com/revarbat/BOSL/wiki>   library's
extrude_2d_shapes_along_bezier
<https://github.com/revarbat/BOSL/wiki/beziers.scad#extrude_2d_shapes_along_bezier>
.  It takes lots of tweeking, but I end up with my profile extruded along
the shape of the cookie cutter.  Let me know if you need more details.



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

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

Re: New forum member, extruding along path

gasstationwithoutpumps
cgriffith wrote

> I think I do something similar to what your asking.  I make cookie cutters
> for my wife.  The outline of cookie cutter is created as SVG in inkscape.
> I
> use the inkscape extension from  https://www.thingiverse.com/thing:2805184
> &lt;https://www.thingiverse.com/thing:2805184&gt;   to convert SVG to
> bezier
> points in scad file.  Then I created a custom SVG in inkscape that is the
> profile of the cutter; pulled into scad file as another bezier path.
> Finally, I use the  BOSL &lt;https://github.com/revarbat/BOSL/wiki&gt; 
> library's
> extrude_2d_shapes_along_bezier
> &lt;https://github.com/revarbat/BOSL/wiki/beziers.scad#extrude_2d_shapes_along_bezier&gt; 
> .  It takes lots of tweeking, but I end up with my profile extruded along
> the shape of the cookie cutter.  Let me know if you need more details.

I am also trying to do cookie cutters.
I tried using the extrude_bezier_along_bezier from the BOSL/beziers.scad
library, but it does not seem to provide any way to control the orientation
of the profile, which seems to twist in arbitrary directions—I had better
luck with the list-comprehension-demos sweep, which has
referenced_path_transforms, where I could get things that previewed almost
right, but got assertion errors from CGAL.

How did you control the orientation of the profile?



-----
gasstationwithoutpumps.wordpress.com
www.thingiverse.com/gasstationwithoutpumps/things
--
Sent from: http://forum.openscad.org/

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

Re: New forum member, extruding along path

tp3
Here's my simple take on cookie cutters. The examples are
just geometry, but the star() and heart() can be easily
replaced with an import("shape.svg").

$fa = 4;
$fs = .5;

height = 12;

module heart(w = 30) {
    translate([0, w * sqrt(2) / 2]) {
        rotate(-135) {
            square(w);
            translate([w / 2, 0]) circle(d = w);
            translate([0, w / 2]) circle(d = w);
        }
    }
}

module star(n = 5, r1 = 22, r2 = 40) {
    function r(a) = a % 2 == 0 ? r2 : r1;
    function p(a) = [ -sin(a), cos(a) ];

    assert(n >= 3);
    points = [ for (a = [0 : 2 * n - 1]) r(a) * p(180 / n * a) ];
    polygon(points);
}

module outline() {
    difference() {
        offset(0.01) children();
        children();
    }
}

module cut(height, base_height, r1, r2) {
    translate([0, 0, -base_height]) cylinder(r = 2 * r1, h = base_height);
    translate([0, 0, -0.01]) cylinder(r1 = r1, r2 = r2, h = height);
}

module cookie_cutter(height = 12, base_height = 1, r1 = 0.8, r2 = 0.2) {
    minkowski() {
        linear_extrude(0.01) outline() children();
        cut(height, base_height, r1, r2);
    }
}

cookie_cutter() star(5, 22, 40);
//cookie_cutter(r1 = 1.2, r2 = 0.6) star(5, 30, 52);
//cookie_cutter(height = 15, r1 = 1.2, r2 = 0.4) star(5, 22, 40);

//cookie_cutter() heart(30);


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

Re: New forum member, extruding along path

adrianv
In reply to this post by gasstationwithoutpumps
What is the cookie cutter shape you need to produce that makes this task
tricky?  (Or to put it another way, why isn't the posted example good
enough?)  

I wonder if the CGAL assertion errors might be occurring due to self
intersection of the polyhedron generated by sweep().  If I'm imagining your
method correctly, that seems especially likely if your cookie cutter has
corners.  Depending on what you're trying to do, exactly, my rounded_sweep()
function might do what you want more easily.  It will handle corners without
trouble.  It extrudes a path with offsets from the original path, and you
can supply your own list of offsets (the "custom" option).   It's included
in BOSL2, but if you explain the cookie cutter problem a little better, I
might try a test of my own.  




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

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

Re: New forum member, extruding along path

cgriffith
@gasstationwithoutpumps

See where I say, "It takes lots of tweeking..."  Issues like what you
mention are that tweeking part.  Other issues I have to deal with are that
the output of inkscape bezier extension uses a path format of [[start_pt1,
ctr_pt1, ctr_pt2, end_pt1], [start_pt2, ctr_pt3, ctr_pt4, end_pt2]].  So I
have to convert that to what BOSL lib expects which is [start_pt, ctr_pt1,
ctr_pt2, end_pt1, ctr_pt3, ctr_pt4, ...]  I have used both
extrude_bezier_along_bezier and extrude_2d_shapes_along_bezier.  I first
rotate or flip the profile path around z axis arbitrary amounts till it
comes out correctly.  Once I get a reliable workflow, I plan to modify the
inkscape extension to write it all out the way I want it.

@adrianv and tp3,

I think it just boils down to me wanting to be a PITA about the cutting
profile.  I wanted to create a profile that is straight up and down on the
inside of the cutter, but gradually slope from thin cutting edge at top say
1.2mm to 6-8 mm pressing handle at bottom.  The only way I could figure to
do that was to create the profile as bezier path;
<http://forum.openscad.org/file/t2599/cutter_profile.jpg> .  None of the
online examples came close to doing this.



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

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

Re: New forum member, extruding along path

adrianv
Nothing wrong with creating the profile using beziers, though certainly there
are other ways.  I tried a rough attempt at your profile using my
round_corners function to show an alternative to beziers.  I start with a
basic profile shape drawn with straight lines and then round over the
corners.   Then I use rounded_sweep to create the outside of the cutter and
also the inside.  I added rounded edges at the top so you don't hurt your
fingers pressing on the cutter (though for printability the outside
roundover might need tweaking).   Note that offset() here is a function that
operates on a list of points, not the native offset() module.  

<http://forum.openscad.org/file/t2477/cutter.png>

include<BOSL2/std.scad>
include<BOSL2/rounding.scad>

cutter = star(d = 30, id= 20, n=7);

profile = [[0,0], [-2,9], [-4.5,10],[-5.6,12],[-5,12]];
rprofile = round_corners(profile, size=[0,.3,.2,.3,0],closed=false);

difference(){
  rounded_sweep(offset(cutter, r=1.2, closed=true), height=12,
bottom=rs_custom(rprofile));
  rounded_sweep(cutter, height=13,bottom=rs_teardrop(r=-1,extra=1));
}



cgriffith wrote
> I think it just boils down to me wanting to be a PITA about the cutting
> profile.  I wanted to create a profile that is straight up and down on the
> inside of the cutter, but gradually slope from thin cutting edge at top
> say
> 1.2mm to 6-8 mm pressing handle at bottom.  The only way I could figure to
> do that was to create the profile as bezier path;
> &lt;http://forum.openscad.org/file/t2599/cutter_profile.jpg&gt; .  None of
> the
> online examples came close to doing this.





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

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

Re: New forum member, extruding along path

gasstationwithoutpumps
In reply to this post by tp3
Torsten, I had seen your design before at
https://forum.openscad.org/Minkowski-Sum-and-Cookie-Cutter-tp20733p20753.html
<https://forum.openscad.org/Minkowski-Sum-and-Cookie-Cutter-tp20733p20753.html>  
and tried that approach.              

Your design runs, though the 3D Minkowski operation makes it *very* slow—I
killed the run after 10 minutes of getting nothing on a simplified version
of the cookie cutter I was trying to make.

Your approach also has no fillets nor rounding in the Z dimension, though
the convex corners are nicely rounded in the XY direction.
 
I was trying to see whether it is possible to make injection-moldable (not
just 3D-printable) models in OpenSCAD, but getting the necessary 3D fillets,
rounding, and draft angles seems to be very difficult.

For 3D printing, I have no problem working with just linear_extrude.



-----
gasstationwithoutpumps.wordpress.com
www.thingiverse.com/gasstationwithoutpumps/things
--
Sent from: http://forum.openscad.org/

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

Re: New forum member, extruding along path

gasstationwithoutpumps
In reply to this post by adrianv
adrianv wrote

> Nothing wrong with creating the profile using beziers, though certainly
> there
> are other ways.  I tried a rough attempt at your profile using my
> round_corners function to show an alternative to beziers.  I start with a
> basic profile shape drawn with straight lines and then round over the
> corners.   Then I use rounded_sweep to create the outside of the cutter
> and
> also the inside.  I added rounded edges at the top so you don't hurt your
> fingers pressing on the cutter (though for printability the outside
> roundover might need tweaking).   Note that offset() here is a function
> that
> operates on a list of points, not the native offset() module.  
>
> &lt;http://forum.openscad.org/file/t2477/cutter.png&gt; 

This comes much closer to what I was looking for—it runs fast enough to be
usable (41 seconds to render the outline of the cookie cutter) and seems to
do an ok job of providing profiles.  I've only tried it on closed paths so
far (where it works fine), but I'll try it on my full design soon, which
includes a number of open paths.

I think that the custom profiles will let me do both draft angles and
rounding of  edges—I'll play with it to see if I can get the control I want.




-----
gasstationwithoutpumps.wordpress.com
www.thingiverse.com/gasstationwithoutpumps/things
--
Sent from: http://forum.openscad.org/

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

Re: New forum member, extruding along path

gasstationwithoutpumps
Using the rounded_sweep() of BOSL2 worked for me, once I fixed a bug in
geometry.scad:  

The parallel check in offset should be

<pre>
parallelcheck =
                        (len(sharpcorners)==2 && !closed) ||
                        all_defined([for (i=[(closed?0:1):len(sharpcorners)-(closed?1:2)])
sharpcorners[i]])
</pre>

as both the first and last corners are undefined for an open path.




-----
gasstationwithoutpumps.wordpress.com
www.thingiverse.com/gasstationwithoutpumps/things
--
Sent from: http://forum.openscad.org/

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

Re: New forum member, extruding along path

cgriffith
rounded_sweep also works for me.

First let me say thank you so much Adrian.  I had no idea BOSL2 or
rounded_sweep even existed.  What I find kinda disappointing is that even
now that I know it exists, after reading documentation, I still don't think
I would have realized I could use it to solve my problem.

I can still use my same profile.  I convert my profile bezier to points and
use rounded_sweep.

So in conclusion, I have to convert both my cutter bezier and profile bezier
to coordinate points, then feed them into rounded_sweep.

Thanks again!



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

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

Re: New forum member, extruding along path

adrianv
Well, as it says at the top level, BOSL2 is in pre-alpha.  It's not stable
yet.   Changes are being made that break code, without any regard yet for
maintaining compatibility with previous BOSL2 versions.   So it hasn't been
strongly announced.  

When you say that you wouldn't have realized that rounded_sweep could solve
your problem, I take it this means the documentation is inadequate?  How can
I improve the documentation in a way that would help you understand the
capabilities of rounded_sweep?   Maybe I should add the cookie cutter
example, but what else would help?   (Note: I wrote rounded_sweep, kind of a
culmination of an effort for producing rounded shapes...but it can do more
than just round things.)    


cgriffith wrote

> rounded_sweep also works for me.
>
> First let me say thank you so much Adrian.  I had no idea BOSL2 or
> rounded_sweep even existed.  What I find kinda disappointing is that even
> now that I know it exists, after reading documentation, I still don't
> think
> I would have realized I could use it to solve my problem.
>
> I can still use my same profile.  I convert my profile bezier to points
> and
> use rounded_sweep.





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

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

Re: New forum member, extruding along path

gasstationwithoutpumps
adrianv wrote
> Well, as it says at the top level, BOSL2 is in pre-alpha.  It's not stable
> yet.   Changes are being made that break code, without any regard yet for
> maintaining compatibility with previous BOSL2 versions.   So it hasn't
> been
> strongly announced.  

I've made some progress on my cookie cutter, but not quite gotten everything
to work.  I gave up on doing the outline as a difference between two
solids—I could not get CGAL to render the result, even when the preview
looked fine, despite all the usual tweaking to avoid identical coordinates.
Instead I do all lines by making 2 copies—one with a slight positive offset
and one with a slight negative offset, then make a closed curve from one
copy forward followed by the other reversed.  Doing rounded_sweep on this
closed curve comes very close to doing what I want.

I've been running into problems with rounded_sweep with tight concave
curves—sometimes getting a point that way out of range.  I think the problem
is that the offset curve is sometimes running backwards (when the offset is
larger than the radius of curvature), but I've not yet looked for a bug in
the code for offset.  I've been considering breaking up tight curves into
separate pieces, but have not yet worked out the details of that—I'm not
sure that it will be as good as fixing offset would be, and might be just as
difficult.



-----
gasstationwithoutpumps.wordpress.com
www.thingiverse.com/gasstationwithoutpumps/things
--
Sent from: http://forum.openscad.org/

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

Re: New forum member, extruding along path

cgriffith
@gasstationwithoutpumps Can you provide an example of "the outline"?  I see
on your blog your doing Shakespeare cookie cutters; can you provide the
points for that outline?



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

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

Re: New forum member, extruding along path

gasstationwithoutpumps
cgriffith wrote
> @gasstationwithoutpumps Can you provide an example of "the outline"?  I
> see
> on your blog your doing Shakespeare cookie cutters; can you provide the
> points for that outline?

I've not decided yet whether to release the Shakespeare cookie cutter design
as open source.  The outer edge of the cutter is not causing any problems
anyway (once I switched over to handling it the same way that I handled the
interior lines).  The remaining problems are coming from the nose, which has
a tight turn in the curve.  

I'm going to play around with some simpler curves to see if I can figure out
what triggers the problems, and I'll post here when I have either a simple
example of the problem or a fix.

If I don't release the Shakespeare cookie cutter, I'll release a simpler SVG
design to show how to use the inkscape plug-in, modify the output scad file,
and add rounded profiles.



-----
gasstationwithoutpumps.wordpress.com
www.thingiverse.com/gasstationwithoutpumps/things
--
Sent from: http://forum.openscad.org/

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

Re: New forum member, extruding along path

gasstationwithoutpumps
I fixed the problem of bad points from the offsets by raising the quality to
quality=2.

I'm still running into problems with CGAL assertion errors from unions when
I have too many points in the paths. Everything looks ok in the previews,
and I can render each piece separately, but a union of even 2 overlapping
pieces failed when I had high-resolution paths, but worked fine for slightly
lower resolution paths.

Debugging is very slow, because the high-resolution runs often take over 40
minutes to run before reporting the assertion failure.



-----
gasstationwithoutpumps.wordpress.com
www.thingiverse.com/gasstationwithoutpumps/things
--
Sent from: http://forum.openscad.org/

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

Re: New forum member, extruding along path

gasstationwithoutpumps
Here is a simplified example of problems with rounded_sweep with a high-resolution path. It comes in 2 files: one modified from the output of the inkscape plugin, the other a generic cookie-cutter module that can be used with any suitably edited inkscape output.
//  simple stamp of a rounded shape, to demonstrate problems with 
//     rounded_sweep
//  Using the "rounding" library from BOSL2.
//
// Kevin Karplus
// 2019 Aug 10


use <BOSL2/std.scad> 
include <BOSL2/rounding.scad> 
include <BOSL2/paths.scad> 

use <scad-utils/lists.scad>   // for reverse()

use 


$fs=0.1;    // fineness for steps (sets offset_maxstep also)
    // also need to set smoothness high in call to cookie_cutter

cut_height=12;   // the height of the cutter
emboss_height=cut_height-2.5;  // the height of the embossing lines

top_round=0.5; // how far back from vertical the top (cutting or embossing) edge is roudned.

half_base_width = 1;   // half the thickness of the cutting and embossing ribs
    // at their bases
spread=3.5; // how far out does the base extend from the central line?

thickness=2;    // the thickness of the flat plate for the edge of the cutter

function outer_profile(top,height) =
    [[0,0], [-top/2,0], [-top,top/2], [-half_base_width,height-thickness-0.5], [-(half_base_width+spread)/2,height-thickness],[-(spread-2*tan(2)),height-thickness],[-spread,height], [-(spread-1),height]]; 
profile1=outer_profile(top_round,cut_height);   
profile3 = outer_profile(top_round,emboss_height);


function rounding(top) = [0,top/18,top/18,0.15,(spread-half_base_width)/50,(spread-half_base_width)/20,0.2,0];
rounding1 = rounding(top_round);

cut_profile = round_corners(profile1, size=rounding1,closed=false); 

emboss_profile = round_corners(profile3, size=rounding1,closed=false);  

module test_profiles()
{    color("red") linear_extrude(20) polygon(concat(cut_profile,
            reverse([ for (pt=cut_profile) [-pt[0], pt[1]]  ])));
     color("blue") translate([0,0,-10])linear_extrude(10)polygon(concat(emboss_profile, 
            reverse([ for (pt=emboss_profile) [-pt[0], pt[1]]  ])));
}

// test_profiles();

module cut_outline(bezier_path, smoothness=4)
{
    // split the bezier segments of the closed path into two groups
    mid_index = floor(len(bezier_path)/2);
    path1 = [for (i=[0:mid_index]) bezier_path[i]];
    path2 = concat([for (i=[mid_index+1:len(bezier_path)-1]) bezier_path[i]],
                [bezier_path[0]]);    
//    path2 = [for (i=[mid_index+1:len(bezier_path)-1]) bezier_path[i]];
    
    color("red",0.5) extrude_open(path1, smoothness=smoothness, profile=cut_profile, height=cut_height);
    color("blue",0.5) extrude_open(path2, smoothness=smoothness, profile=cut_profile, height=cut_height);
}

module extrude_solid(bezier_path, smoothness=4, profile=emboss_profile, height=emboss_height)
{   
    path = bezier_coordinates(bezier_path,smoothness);
    cutter = offset(simplify2d_path(path), r=-top_round, closed=true);

    rounded_sweep(cutter, height=height, 
	    bottom=rs_custom(profile), quality=4, offset_maxstep=$fs); 
    
    // alignment test (remove * to see shape above solid)
    * translate([0,0,height+1]) linear_extrude(height=5) polygon(path);
}



module extrude_open(bezier_path, smoothness=4, profile=emboss_profile, height=emboss_height)
{
    path = simplify2d_path(bezier_coordinates(bezier_path,smoothness));
    
    // alignment check
//    echo("path=",path);
*   color("red") translate([0,0,cut_height+1]) linear_extrude(height=5) polygon(path);
    
    // generate a polygon that wraps around the path.
    // Open the path by dropping the last point, if it is closed.
    closed = norm(path[0]-path[len(path)-1])< 0.001;
    shortened_path = [for (i=[0:len(path)-1-(closed? 1: 0)]) path[i]];
    there = offset(shortened_path,r=0.001,closed=false);
    back = reverse(offset(shortened_path,r=-0.001,closed=false));
    round_trip = simplify2d_path(offset(concat(there,back),0.001));

//   check for generation of polygon for 
//    echo("round_trip=", round_trip);
*    color ("blue") linear_extrude(height=5) polygon(round_trip);
    
   rounded_sweep(round_trip, height=height, 
        bottom=rs_custom(profile), quality=3, offset_maxstep=$fs);   
}


module cookie_cutter(y_height=85,smoothness=6)
{
    scale_factor=y_height/200;
    mirror([1,0,0]) translate(scale_factor*[0,300,0])
    {
            * let (path= outline())
            {   color("green") 
                    cut_outline(scale_factor*path, smoothness=smoothness);
            }
            echo("outline done");
            
            for (path= interior_closed())
            {    color("pink") extrude_solid(scale_factor*path, 
                        smoothness=smoothness);
            }
            echo("interior_closed done");
            
            * for( path=interior_open())     
            {    color("orange")
                    extrude_open(scale_factor*path, smoothness=smoothness);
            }
            echo("interior_open done");
                   
    }
}

// this shape succeeds
 color("blue") cookie_cutter(smoothness=4);

// increasing the resolution of the path causes the shape to fail, 
// even in preview.
 color("red") translate([30,0,0]) cookie_cutter(smoothness=5);

nostril.scad:
/**
 * This file contains a 2D vector representation of your InkScape file.
 * You can set the global variable "$fn" to alter the precision of the curves.
 * You should use "linear_extrude" or "rotate_extrude" to give it some volume.
 */

translate([0, 300]) {

	for(path_long=interior_closed())
		color("red") linear_extrude(4)  bezier_polygon(path_long);
}

function interior_closed() = [
nostril()
];

function interior_open() = [];
function outline() = [];


	// Path ID: 
	function nostril()=
	[[[-33.543028, -315.11091], [-33.982110999999996, -314.57131], [-33.70377, -313.82149], [-33.465188, -313.25593]], [[-33.465188, -313.25593], [-32.820589, -311.72486], [-31.397714999999998, -310.62104], [-29.825916, -310.15808999999996]], [[-29.825916, -310.15808999999996], [-28.17155, -309.61960999999997], [-26.233151, -309.49926999999997], [-24.694009, -310.43373999999994]], [[-24.694009, -310.43373999999994], [-23.641358, -311.07556999999997], [-22.719163, -312.09065999999996], [-22.481952, -313.3294399999999]], [[-22.481952, -313.3294399999999], [-22.406302, -313.9976199999999], [-22.811264, -314.6410199999999], [-23.409109, -314.9280799999999]], [[-23.409109, -314.9280799999999], [-24.109048, -315.2958499999999], [-24.877931, -315.5286499999999], [-25.525149, -315.9960799999999]], [[-25.525149, -315.9960799999999], [-26.422848, -316.6023199999999], [-27.405955, -317.0753999999999], [-28.418993, -317.4535999999999]], [[-28.418993, -317.4535999999999], [-29.732035, -317.89772999999985], [-31.176294, -317.4297999999999], [-32.288394, -316.6914599999999]], [[-32.288394, -316.6914599999999], [-32.800359, -316.3218699999999], [-33.217493999999995, -315.8164799999999], [-33.499751999999994, -315.2546399999999]], [[-33.499751999999994, -315.2546399999999], [-33.50915199999999, -315.2063399999999], [-33.499247, -315.14634999999987], [-33.543032, -315.1109099999999]], [[-33.543032, -315.1109099999999], [-33.543032, -315.1109099999999], [-33.543028, -315.11091], [-33.543028, -315.11091]], [[-33.543028, -315.11091], [-33.543028, -315.11091], [-33.543028, -315.11091], [-33.543028, -315.11091]]];

/**
 * Stripped down version of "bezier_v2.scad".
 * For full version, see: https://www.thingiverse.com/thing:2170645
 */

function BEZ03(u) = pow((1-u), 3);
function BEZ13(u) = 3*u*(pow((1-u),2));
function BEZ23(u) = 3*(pow(u,2))*(1-u);
function BEZ33(u) = pow(u,3);

function bezier_2D_point(p0, p1, p2, p3, u) = [
	BEZ03(u)*p0[0]+BEZ13(u)*p1[0]+BEZ23(u)*p2[0]+BEZ33(u)*p3[0],
	BEZ03(u)*p0[1]+BEZ13(u)*p1[1]+BEZ23(u)*p2[1]+BEZ33(u)*p3[1]
];

function bezier_coordinates(points, steps) = [
	for (c = points)
		for (step = [0:steps])
			bezier_2D_point(c[0], c[1], c[2],c[3], step/steps)
];

module bezier_polygon(points) {
	steps = $fn <= 0 ? 30 : $fn;
	polygon(bezier_coordinates(points, steps));
}


Sent from the OpenSCAD mailing list archive at Nabble.com.

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

Re: New forum member, extruding along path

cgriffith
Hi Kevin,

I was trying to see if I could find a solution to your issue.  I could not.
What I did see... 1) You are using the output of the inkscape extension
directly in BOSL library which is incompatable.  Like my post above, they
use different formats for the path.  If you pass the output of nostril()
funciton directly into...

//converts a quadratic bezier grouped into 4 point sub-paths with duplicate
control points
//accross adjacent sub-path, to 3 point sub-paths sharing duplicat control
points
//like BOSL lib expects
function inkscape_path_to_bosl(inkscape_path) = [
   for(path = inkscape_path)
      for (i = [0:1:2])
         path[i]
   ];

It will format the path that BOSL expects.  2) Your nostril() path has more
points than needed which leads to odd things around the point where path end
meets the beginning.  However, even if I clean the path up, I was still
getting that strange tangent artifact.  I could not get that to go away.  

So maybe you were correct when you wrote, " I think the problem
is that the offset curve is sometimes running backwards (when the offset is
larger than the radius of curvature".

I have extracted the converted and cleaned up nostril path here in case
someone else had time to troubleshoot.

BOSL_nostril=[[-33.543, -315.111],
             [-33.9821, -314.571], [-33.7038, -313.821], [-33.4652, -313.256],
             [-32.8206, -311.725], [-31.3977, -310.621], [-29.8259, -310.158],
             [-28.1715, -309.62], [-26.2332, -309.499], [-24.694, -310.434],
             [-23.6414, -311.076], [-22.7192, -312.091], [-22.482, -313.329],
             [-22.4063, -313.998], [-22.8113, -314.641], [-23.4091, -314.928],
             [-24.109, -315.296], [-24.8779, -315.529], [-25.5251, -315.996],
             [-26.4228, -316.602], [-27.406, -317.075], [-28.419, -317.454],
             [-29.732, -317.898], [-31.1763, -317.43], [-32.2884, -316.691],
             [-32.8004, -316.322], [-33.2175, -315.816], [-33.543, -315.111],
             [-33.9821, -314.571], [-33.7038, -313.821], [-33.4652, -313.256]];




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

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

Re: New forum member, extruding along path

gasstationwithoutpumps
cgriffith wrote

> Hi Kevin,
>
> I was trying to see if I could find a solution to your issue.  I could
> not.
> What I did see... 1) You are using the output of the inkscape extension
> directly in BOSL library which is incompatable.  Like my post above, they
> use different formats for the path.  If you pass the output of nostril()
> funciton directly into...
>
> //converts a quadratic bezier grouped into 4 point sub-paths with
> duplicate
> control points
> //accross adjacent sub-path, to 3 point sub-paths sharing duplicat control
> points
> //like BOSL lib expects
> function inkscape_path_to_bosl(inkscape_path) = [
>    for(path = inkscape_path)
>       for (i = [0:1:2])
>          path[i]
>    ];
>
> It will format the path that BOSL expects.  2) Your nostril() path has
> more
> points than needed which leads to odd things around the point where path
> end
> meets the beginning.  However, even if I clean the path up, I was still
> getting that strange tangent artifact.  I could not get that to go away.  

The bezier_coordinates() call provided with the inkscape plugin does the
necessary conversions while giving some control over the smoothness of the
resulting path.

I'have had good results for 3D printing by doing linear_extrude of the paths
converted by the inkscape plugin—it is only the rounding that is causing
problems.  OpenSCAD seems to be good for 3D printing, but not for designing
for injection molding, where draft angles, rounding, and filleting need to
be easily controlled.  The BOSL2 rounding functions came close to giving the
functionality I need, but still fell a little short of getting me to a
finished design.




-----
gasstationwithoutpumps.wordpress.com
www.thingiverse.com/gasstationwithoutpumps/things
--
Sent from: http://forum.openscad.org/

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

Re: New forum member, extruding along path

cgriffith
@gasstationwithoutpumps

I am glad to hear you got a working solution, but I would still like to know
why that particular path presents problems when used with rounded_sweep.
Maybe someone closer to that algorithm can explain

@adrianv

You had asked a very important question that I have been trying to find a
good way to answer.  Let me first say that the documentation for BOSL and
BOSL2 are the best I have seen; examples and pics of results are so helpful.
I really appreciate the hard work you have put in.  I can't say what I would
change because I feel it is my own inability to comprehend some of the
content or my own lack of imagination to see how something could be used,
not a fault of the documentation.  Seriously, thank you so much for your
valued work.




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

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