# Can you sweep a object with fingers Classic List Threaded 61 messages 1234
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 Ronaldo wrote Well, I have rechecked this. It seems that the vertices of meeting parts should be exactly the same. Try this code with show edges: // tetrahedron with a missin face p = [ [0,0,0], [10,0,0], [0,10,0], [0,0,10] ]; f = [ [0,1,2], [0,3,1], [0,2,3] ]; // additional faces to close it n=3; degface = false; ps = [for(i=[0:n+1])  p*i/(n+1) + p*(n+1-i)/(n+1) ];   fs = [for(i=[1:n+1]) [ 3, 3+i, 4+i ] ]; df = n>0 && degface ? [for(i=[n+2:-1:1]) 3+i ] : []; // the full tetrahedron difference(){     polyhedron(concat(p,ps),concat(f,fs,[df]));     cube(3,center=true);     translate([10,0,0]) cube(3,center=true); } Have you noticed that there are always 2 cases of duplications? p= [ A,B,C,D]; n=0: ps= [ C,B ]; p+ps => [A,B,C,D,  C,B]; n=1: ps= [ C,P, B ]; p+ps => [A,B,C,D,  C,P,B]; n=2: ps= [ C,P, Q, B ]; p+ps => [A,B,C,D,  C,P,Q,B]; n=3: ps= [ C,P, Q, R, B ]; p+ps => [A,B,C,D,  C,P,Q,R,B]; B and C are always duplicated regardless of n. \$ Runsun Pan, PhD \$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); \$ Tips; \$ Snippets
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 Thx, Ronaldo. The understanding of no need to be exact same number of points on both faces could save a lot of troubles. \$ Runsun Pan, PhD \$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); \$ Tips; \$ Snippets
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 I am not sure I have understood your understanding.2016-11-19 22:40 GMT-02:00 runsun :Thx, Ronaldo. The understanding of no need to be exact same number of points on both faces could save a lot of troubles. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 @Ronaldo: I think I didn't think through it clearly. You are right to point that out. What interests me is the re-sampling process to match two surfaces. I'd be interested how you achieved that as in the following fig: Or how Parkinrob achieves his: A while ago I was solving a similar/related situation (of joining two polys), and I figured that a resampling approach is needed. This attempt was reflected in a forum post in which I was looking for a solution to punch an irregular hole in a poly plan, 'cos I believe that is the basic for lofting, which is essential for poly joining. Later I came up with a preliminary solution of re-sampling: It is still far from "irregular hole", but already can do lots of cool stuff. \$ Runsun Pan, PhD \$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); \$ Tips; \$ Snippets
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 runsun wrote @Ronaldo: I think I didn't think through it clearly. You are right to point that out. What interests me is the re-sampling process to match two surfaces. I'd be interested how you achieved that as in the following fig: runsun, the re-sampling I use is a simple process. First, compute (for each polygon) the list of the distances along the polygon border from each vertex to the starting vertex: they are ascending-ordered lists. Normalize the two lists, dividing each one by its maximum. Then, both start with zero and end with 1. Refer to the figure where the blue dots represent one list and the green dots the other: Now merge the lists (like in merge sort) with one difference: if the same value is found in both lists, put just one in the output list (the red dot in the output list). Use the output list to re-sample both polygon by doing appropriate interpolations. I am sure you would be able to write this algorithm but I may provide my codes if you need. Another approach is taken by skin() in list comprehension demos. Suppose the one polygon has n vertices more then the other. The skin() algorithm inserts n new vertices (Linde calls them Steiner points) in the "smaller" one. The method inserts one at a time in the longest edge splitting it in half, with an additional care: if the longest edge is not an original polygon edge, it removes the k previously inserted vertices from it and inserts k+1 subdividing the edge equally. In fact, it is more efficient than that but with the same result. I don't use this method because it is more complex and it is not continuous with the vertex positions: a small change in a vertex may cause a big change in the re-sampling. Anyway, I have a clearer and commented implementation of the method if you need it.
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 @Ronaldo, ah ha ! The moment I spotted your figure, I see how you did it right away. It turns out that my method is the same as what you described in the skin() approach, and, as you mentioned, it's much more difficult to code. I actually moved a step further to insert points bidirectionally --- that is, insert points that are missing on both polys. That made it even more troublesome. I'll see if I can apply your approach. Thx. \$ Runsun Pan, PhD \$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); \$ Tips; \$ Snippets
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 2016-11-20 14:55 GMT-02:00 runsun :@Ronaldo, ah ha ! The moment I spotted your figure, I see how you did it right away. It turns out that my method is the same as what you described in the skin() approach, and, as you mentioned, it's much more difficult to code. I actually moved a step further to insert points bidirectionally --- that is, insert points that are missing on both polys. That made it even more troublesome. I'll see if I can apply your approach. Thx.I do insert points in both polygon. Curiously, you image irregular_tube_paring suggested me something similar to what I do and not what skin() does. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 I think the basic idea is probably the same, but in my case, I use "angle to the starting point" as a comparison criteria for point-insertion, you use "ratio of length to the starting point". In my first impression, ratio should be easier than angle. For one thing, calculating "angle" will require a common center for both surfaces, which brings a whole new problem to solve (how to identify this common center when the surface is irregular). The use of "ratio" will require no such center, which is what I think the main difference.   \$ Runsun Pan, PhD \$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); \$ Tips; \$ Snippets
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 In reply to this post by Ronaldo I found a first simple scheme to make a furcation: The incomming data are the three mouth closed arcs and its traversal derivatives. The surface is composed of three rectangular and three triangular Bezier patches. The joint at the green lines is continuous but not C1. To have a C1 joint the mouth arcs should be cubic splines at least C1 and the triangular patch has to be divided in three triangular Bezier patches in a Clough-Tocher subdivision. This scheme is not easily extended for more mouths. The top and bottom triangles would turn into more sided polygons and a different subdivision must be devised. But any way, this experiment shows that at least a hand with 2 fingers is feasible by terminating sweeps/skins at the three mouths.
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 Correction: the surface is composed of three rectangular and two triangular patches. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 In reply to this post by Ronaldo @Ronaldo, What formula did you apply to obtain a triangular Bezier patch? I haven't got to adventure beyond Bezier curves before I was distracted away from OpenSCAD. Btw, with your success of the bifurcation above, I think it's very close to making a full hand --- instead of trying to come up with a poly of multiple mouths, it should be easier to stitch multiple of above figures into one hand of 5 fingers. \$ Runsun Pan, PhD \$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); \$ Tips; \$ Snippets
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 runsun wrote What formula did you apply to obtain a triangular Bezier patch? I haven't got to adventure beyond Bezier curves before I was distracted away from OpenSCAD. What do you mean by formula? Triangular Bezier patches are defined by a triangular array of control points. To evaluate a point in it, I apply its recursive evaluation definition (Casteljau). To generate a triangular mesh I evaluate it in a regular triangular grid of the parameters. And to display it I pass the list of triangles of the triangular evaluation mesh to polyhedron. All done by a set of small functions. Btw, with your success of the bifurcation above, I think it's very close to making a full hand --- instead of trying to come up with a poly of multiple mouths, it should be easier to stitch multiple of above figures into one hand of 5 fingers. Yes, I know it but then the "hand" will be subdivided by lot of patches and all the stuff will be harder to assemble. What I want is a general scheme that works with a n-furcation so to speak: given n mouths it computes the n-furcation. Using the scheme I sketched, in a 5-furcation, I will need to compute two pentagonal C1 patches. That patches could be naturally split in triangles. However, the C1 interpolation methods for arbitrary triangulations are harder to compute and have many limitations. I am still researching this.
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 @Ronaldo, That's good enough for me for now. Thx for the explanation.   \$ Runsun Pan, PhD \$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); \$ Tips; \$ Snippets
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 Any way, if someone wants to play with triangular patches here are my codes to start with: // Tpatch is any triangular array of 3D points // an example of a degree 3 Bezier Tpatch control points p = 10*[ [ [0,0,3] ],          [ [1.5,0.5,5], [1.5,2.5,6] ],          [ [3,0,3],    [3.5,1,3],  [3,3,3]     ],          [ [4,-1,3],    [5,1.5,1], [4.5,4.5,1], [4,6,3] ] ]; n = 10; justTpatch = false; // set true to see a solid (manifold) model // Bezier Tpatch mesh btp = Bezier_Tpatch_mesh(p,n); // Bezier Tpatch converted to polyhedron data format bp = Tpatch2polyhedron(btp,inv=true); // three polygons meeting the Bezier Tpatch borders p1 = polygon2polyhedron(concat([[0,0,0]], [for(q=btp) q])); p2 = polygon2polyhedron(concat([[0,0,0]], [for(q=btp) q[len(q)-1]]),inv=true); p3 = polygon2polyhedron(concat([[0,0,0]], btp[len(btp)-1])); if(justTpatch)     color("red") make_polyhedron([bp]); else     make_polyhedron([ bp,p1,p2,p3 ]); // evaluates a Bezier Tpatch with control points p in a parameter space point (u,v) function Bezier_Tpatch_eval(p,u,v,degree=3) =     let( l = \$from==undef? [0,0]: \$from,          i = l, j = l, w = 1-u-v )     degree==1?         u*p[i][j] + v*p[i+1][j] + w*p[i+1][j+1] :         u*Bezier_Tpatch_eval(p,u,v,degree-1,\$from=l)           + v*Bezier_Tpatch_eval(p,u,v,degree-1,\$from=l+[1,0])               + w*Bezier_Tpatch_eval(p,u,v,degree-1,\$from=l+[1,1]); // builds a triangular mesh (itself a Tpatch) evaluating the Bezier Tpatch p // in a regular triangular grid of size n function Bezier_Tpatch_mesh(p,n) =     let(degree=len(p)-1)     [ for(i=[n:-1:0]) [ for(j=[n-i:-1:0]) Bezier_Tpatch_eval(p,i/n,j/n,degree) ] ]; // converts Tpatch tp to a polyhedron data [ vertices, tris ] format; // inv=true reverses the circulation order function Tpatch2polyhedron(tp, inv=false) =     let( n = len(tp) != 0 ? len(tp) : 0,          vertices = n == 0 ? [] : [ for(l=tp) for(pt=l) pt ],              tris     = concat(  [ for(i=[0:n-2], j=[0:i],   st=i*(i+1)/2 )                                 inv ? [ st+j, st+i+j+2, st+i+1+j ]:                                       [ st+j, st+i+1+j, st+i+j+2 ] ] ,                              [ for(i=[1:n-2], j=[0:i-1], st=i*(i+1)/2 )                                 inv ?   [ st+j, st+j+1, st+i+j+2 ] :                                         [ st+j, st+i+j+2, st+j+1 ] ] ) )     [ vertices, tris ]; // converts a polygon poly to a polyhedron data [ vertices, tris ] format; // inv=true reverses the circulation order function polygon2polyhedron(poly, inv=false) =      let( vertices  = poly,           range     = inv ? [len(poly)-1: -1: 0] : [0:len(poly)-1],           facets    = [[for(i=range) i ]] )     [ vertices, facets ]; // generates a polyhedron with the surface of a Tpatch p with color c module show_Tpatch(p,c="yellow") {     q = Tpatch2polyhedron(p);     color(c) make_polyhedron([ q ]); } // generates one polyhedron composed by the polyhedron data in list polys module make_polyhedron(polys, convexity = 10) {     function _accum_sum(l, offs=0, res=) =         len(res) == len(l) ?             res :             _accum_sum(l, offs+l[len(res)-1], concat(res, [ offs+l[len(res)-1] ] ));     vertlist = [for(p=polys, pt=p) pt]; // collect all verts from polyhedra     vertlens = [for(p=polys) len(p) ]; // number of vertices of each polyhedron data     acclens  = _accum_sum(vertlens);  // accumulated sum of the vertex set sizes to offset face indices     facets   = [ for(i=[0:len(polys)-1], f=polys[i] ) [ for(v=f) acclens[i]+v ] ];     polyhedron(         points = vertlist,         faces  = facets,         convexity = convexity     ); }
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 @Rolnado, Thx you very very much. I'll take a deep look. \$ Runsun Pan, PhD \$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); \$ Tips; \$ Snippets
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 Well, that is a vast subject to be discussed here. I suggest you study some on line texts on Bezier curve before reading about Bezier triangle patches. I have just found this one. Although I have not read it, it seems it covers the basic properties and concepts. The next step is to understand how to build surfaces by tensor product. I need to find a good reference for you. After that you will be able to understand Bezier triangle surfaces. runsun wrote 1) how are the control points obtained ? Control points are the coefficient of a polynomial. For a cubic curve, you have 4 of them. For a biquadratic surface, you have 6. Either they are data input or they are computed in order to get a specific polynomial (like, for instance, in curve or surface fitting). Consider you have a shape in mind that you want to present it with OpenSCAD. How is the shape turned into the control points ? That is the hard part. The Bezier control points of a curve or surface is a coarse approximation of the curve segment or surface patch. In an interactive environment, you change the position of the CPs and see the result. In OpenSCAD, you need to change coordinates of the CPs and run the code again. The CPs are a good indicator of the surface shape due to some properties: a) the curve segment or surface patch is in the convex hull of its CPs; b) the curve segment or surface patch interpolates 2 (in case of curves), 3 (in case of Bezier triangles) or 4 (in case of rectangular Bezier patches) of its CPs. c) if you lift a CP, all the curve segment or surface patch lifts (except for the interpolated points) but the lifting effect is greater near the changed CP; d) the curve segment or surface patch is tangent to segments or polygons built from CPs near the interpolation points. 2) Is the control points the only thing the generate the whole shape ? My study of your code so far seems to indicate that. That is, the 3 polys are all generated from the control points ? Yes, if you have the coefficients of a polynomial it is fully determined.
Open this post in threaded view
|

## Re: Can you sweep a object with fingers

 Thx, Ronaldo. The ref you gave is a great resource. Will need to get myself familiar with the way a surface be made with CPs. I'm to some extent quite familiar with Bezier curve: But those were done with existing points, on which the CPs are made. So it will take some digging to get to know how the CPs could come first (i.e., w/o points of the surface to start with) in the Bezier surface. \$ Runsun Pan, PhD \$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); \$ Tips; \$ Snippets