Parkinbot wrote
> Jon, > > I think your project is just another example, why a more general interface > for linear_extrude() would make sense. Of course sweep/skin functionality > will also do as it provides the most general interface for extrusions. > ... I think it's also a good example of how the scope is endless. Jon_Bondy wrote > ... > I thought of creating the curves with Bezier curves inside OpenSCAD, but > most implementations are limited to 4 control points; and working in > OpenSCAD by typing in numbers could be both laborious and nonintuitive. > ... OpenSCAD may not be suitable for the sort of development process you're looking for. IIRC Npoint bezier is not that hard to do. function nbezier(points,t)= 1>=len(points)? points[0] : nbezier( [for(i=[0:len(points)2]) points[i]*t+points[i+1]*(1t)], t ); module segment (a,b,r=0.1) { d=(ba); phi=atan2(sqrt(d.x*d.x+d.y*d.y),d.z); theta=atan2(d.y,d.x); len=sqrt(d*d); translate(a) rotate(a=theta) rotate(v=[0,1,0],a=phi) cylinder(r=r,h=len); } list=[ [0,1,0],[4,1,4],[5,5,5],[2,3,3],[5,5,0] ]; shape=[for (t=[0:0.05:1]) nbezier(list,t)]; for(i=[0:len(shape)2]) { segment(shape[i],shape[i+1]); }  Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
Thanks for the npoint Bezier code!
On 2/16/2018 12:04 PM, NateTG wrote: > Parkinbot wrote >> Jon, >> >> I think your project is just another example, why a more general interface >> for linear_extrude() would make sense. Of course sweep/skin functionality >> will also do as it provides the most general interface for extrusions. >> ... > I think it's also a good example of how the scope is endless. > > > Jon_Bondy wrote >> ... >> I thought of creating the curves with Bezier curves inside OpenSCAD, but >> most implementations are limited to 4 control points; and working in >> OpenSCAD by typing in numbers could be both laborious and nonintuitive. >> ... > OpenSCAD may not be suitable for the sort of development process you're > looking for. > > IIRC Npoint bezier is not that hard to do. > > function nbezier(points,t)= > 1>=len(points)? > points[0] > : > nbezier( > [for(i=[0:len(points)2]) points[i]*t+points[i+1]*(1t)], > t > ); > > module segment (a,b,r=0.1) { > d=(ba); > phi=atan2(sqrt(d.x*d.x+d.y*d.y),d.z); > theta=atan2(d.y,d.x); > len=sqrt(d*d); > translate(a) > rotate(a=theta) > rotate(v=[0,1,0],a=phi) > cylinder(r=r,h=len); > } > > > list=[ [0,1,0],[4,1,4],[5,5,5],[2,3,3],[5,5,0] ]; > > shape=[for (t=[0:0.05:1]) nbezier(list,t)]; > > for(i=[0:len(shape)2]) { > segment(shape[i],shape[i+1]); > } > > > > > >  > Sent from: http://forum.openscad.org/ > > _______________________________________________ > OpenSCAD mailing list > [hidden email] > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > >  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 
I made an error so that produces the bezier line reversing the order of the
vertices. You can switch t and (1t) to get the version that goes in the correct direction: > function nbezier(points,t)= > 1>=len(points)? > points[0] > : > nbezier( > [for(i=[0:len(points)2]) points[i]*(1t)+points[i+1]*t], > t > );  Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
In reply to this post by jon_bondy
In case you are still interested in drawing the "weird vase" in Inkscape... Inkscape allows you to interpolate between two shapes. That detail was the inspiration for this:
First, a couple of shapes: imagine the "weird vase" cut by the XY and the YZ planes
One of the shapes must be copied and mirrored Then a couple of Inkscape's path interpolations, and save as SVG Importing the SVG file into OpenSCAD we can arrange the "planes" like this And cutting vertical slices and "hulling" each of them ends up like this This is the code: width = 90; height = 120; planes = 13; module plane(n) { linear_extrude(height=1, center=true) intersection() { translate([width*(nfloor(planes/2)), 0]) import(str(planes, "planes.svg")); square([width, height], true); } } module planes() { for(i=[1:planes1]) rotate([90, 0, 180/(planes1)*i]) plane(i); } for(i=[height/2:height/2]) hull() { intersection() { planes(); translate([0, 0, i]) cube([width, width, 1], true); } } The attached file includes the .scad, the .svg and a rendered .amf 20180216 18:52 GMT+01:00 jon <[hidden email]>: Thanks for the npoint Bezier code! Saludos,
Antonio _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org weird_vase.7z (127K) Download Attachment 
Very creative! On 2/16/2018 4:33 PM, Antonio Bueno
wrote:
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
In reply to this post by Ronaldo
What you seem to want is some kind of interpolation. I don't believe that polynomial regression or higher degree Bezier curves are the best way to go.
There is many interpolation schemes but, unless you need a smooth curve (with continuous curvature), a Hermite interpolation might be satisfactory. It will give you tangent continuity. In the following, I will give you a specific way to do it based on the subdivBezier3() function I mentioned before [1]. Given a list of points p to be interpolated, the following function computes a list of points in a Hermite interpolation curve of those points:
The number of generated points by InterpHerm() depends exponentially on n so keep it low: 3 or 4 should be enough. An adequate parametrization of that curve in the interval [0,1] is the following:
Given any t in the interval [0,1] and a Hermite interpolation pc computed by InterpHerm(), the function F() produces a point in the curve such that:
So, typically you should compute pc = IntepolHerm(p) once and call
F(t,pc) with as many values of t as you want or need. Note that with this setting, the input points p of
IntepolHerm(p)
may be not only 2D or 3D points but may be any uniform list of lists of numbers. So, you may define p such that:
where [x,y,z] is a 3D point, r is a radius and ang is an angle. The resulting "point" generated by
F(t,pc)
will have the same structure: a 3D point, a radius and an angle. This way you can interpolate many different parameter values in one go. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
If it’s helpful for you, I just tweaked my BOSL library’s bezier.scad to accept Norder beziers by giving an N= argument to the related bezier functions and modules. Library code: Relevant docs: Some modules still have problems extruding concave paths, though. I’m having troubles getting a good function working to triangulate the end faces. Functional programming is like pulling teeth for this sort of thing. *shakes fist impotently* Any pointers would be appreciated, if anybody has done this.  Revar
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
In reply to this post by Ronaldo
Ronaldo wrote
> What you seem to want is some kind of interpolation. > I don't see how a lineoriented interpolation scheme operating over a sequence of Npoints will result in a vase, unless the Npoints are fed into some generator function, which Jon seemingly wants to avoid. 1. For the description of a 2manifold some 2Dinterpolation scheme operating over a grid, a sequence of polygons or similar is needed. 2. Further, boundary conditions are of interest whenever a sequence is not circular. E.g. to describe the bottom and the top of the vase. 3. With an interpolation scheme you can only describe smooth surfaces. This is not always wanted. Therefore a Bezierbase approach is richer ...  Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
In reply to this post by RevarBat
> Some modules still have problems extruding concave paths, though. I’m
having troubles getting a good function working to triangulate the end faces. Detecting selfintersection is a bit of a chore. Detecting 0length segments is easy. Once you have those two pieces worked out, polyhedron accepts faces with more than 3 edges now.  Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
Sadly, CGAL will barf frequently even with known good coplanar face points. CGAL is only really reliable with triangles, in my experience.
 Revar On Feb 18, 2018, at 6:47 AM, NateTG <[hidden email]> wrote: >> Some modules still have problems extruding concave paths, though. I’m > having troubles getting a good function working to triangulate the end > faces. > > Detecting selfintersection is a bit of a chore. Detecting 0length > segments is easy. Once you have those two pieces worked out, polyhedron > accepts faces with more than 3 edges now. > > > > >  > Sent from: http://forum.openscad.org/ > > _______________________________________________ > 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 
Administrator

> On Feb 18, 2018, at 6:10 PM, Revar Desmera <[hidden email]> wrote:
> > Sadly, CGAL will barf frequently even with known good coplanar face points. CGAL is only really reliable with triangles, in my experience. > In OpenSCAD, we work around this by first giving CGAL the know good coplanar face, and if it throws an exception, we send it a triangulated version. Marius _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
In reply to this post by RevarBat
RevarBat wrote
> Sadly, CGAL will barf frequently even with known good coplanar face > points. CGAL is only really reliable with triangles, in my experience. > >  Revar > ... FWIW I did write a face triangulator: triangulate.scad <http://forum.openscad.org/file/t2140/triangulate.scad> It's not particularly clever or efficient, but it should work.  Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
It seems that your ear clipping method doesn't work properly in some cases: face = [[20, 0], [15.5279, 8.96503], [10, 17.3205], [0, 8.85357], [10, 17.3205], [31.0929, 17.9515], [20, 0], [33.2343, 19.1878], [10, 17.3205], [0, 14.4569], [10, 17.3205], [19.0507, 10.9989]] face = [[20, 0], [31.8838, 18.4081], [10, 17.3205], [0, 7.34213], [10, 17.3205], [27.7456, 16.019], [20, 0], [5.22655, 3.01755], [10, 17.3205], [0, 29.8851], [10, 17.3205], [4.12534, 2.38177]] face = [[20, 0], [24.6573, 14.2359], [10, 17.3205], [0, 6.03876], [10, 17.3205], [20.8959, 12.0643], [20, 0], [19.3807, 11.1895], [10, 17.3205], [0, 27.649], [10, 17.3205], [11.166, 6.44668]] 20180219 7:15 GMT03:00 NateTG <[hidden email]>: FWIW I did write a face triangulator: _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
Thanks for the test cases. This should be fixed: triangulate.scad 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 
Nice but I still have caught some other cases with this test code: b = 20; seed =floor(rands(0,10000,1)[0]); // some problematic seeds: 2517, 4041, 2033 echo(seed=seed); // to reproduce problematic cases a = rands(b/5, 2*b, 12,seed); star = [ for(i=[0:30:3601]) (i%60 ? a[i/30]:b)*[cos(i), sin(i)] ]; color("red") translate([0,0,5]) polygon(star); star3 = to3d(star); polyhedron( star3, triangulate_face(star3,[for(i=[0:len(star)1]) i ])); 20180219 16:06 GMT03:00 NateTG <[hidden email]>: Thanks for the test cases. This should be fixed: triangulate.scad _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
This one was missing: function to3d(p) = [for(pi=p) [pi[0], pi[1], 0] ]; 20180219 17:50 GMT03:00 Ronaldo Persiano <[hidden email]>:
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
In reply to this post by RevarBat
On 18/02/18 23:10, Revar Desmera wrote:
Sadly, CGAL will barf frequently even with known good coplanar face points. CGAL is only really reliable with triangles, in my experience. This is why I have my own version of skin () that triangulates the top and bottom. Sometimes the render retries and it all works but more often it barfs out an error with no clue as to which bit of geometry.
_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
In reply to this post by Ronaldo
Wow... maybe I should go to the school for children that can't math good.
triangulate.scad <http://forum.openscad.org/file/t2140/triangulate.scad>  Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
Don't be so severe with yourself! Your code is cleaner than my own. I haven't checked it in depth but it seems to be ok now. Nice work. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
Ronaldo wrote
> Don't be so severe with yourself! Your code is cleaner than my own. I > haven't checked it in depth but it seems to be ok now. Nice work. > ... It can get in trouble when there are colinear points. Something like: test=[ [10,0],[0,0],[10,30],[10,20],[10,10]]; Is a legitimate (ish) polygon, but the algorithm will clip point 1 first, and be left with 4 vertices on a line which it can't handle. Also, it should really have input checking.  Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org 
Free forum by Nabble  Edit this page 