# flattening curved surfaces

53 messages
123
Open this post in threaded view
|

## flattening curved surfaces

 I have a bit of code at the end of this question.  It produces a shape with 4 curved sides, each of which lies on the surface of a cylinder.   Note that this is an example shape: I want to work with families of similar shapes, not just with this one example. I would like a way to take each of the 4 surfaces and produce a 2D shape that, when cut out and bent, would conform to the original surface.  The idea is to be able to create the original shape out of, say, cardboard by cutting out the 4 2D shapes and then taping them together. I have a conceptual idea of how this would be done in a traditional programming language if I had a list of the coordinates along each of the 4 boundary lines.  I considered re-writing the code, below, as a sweep, and generating the coordinates explicitly, but a) that is not trivial (to me), and ii) I want to solve the more general case where the equations that determine the shape are not known.  I looked at the generated STL file, and the coordinates are there, but not organized in the way that I would want them to be. This may be more effort than I want to expend, but I wondered if anyone had a brilliant insight. Thanks! Jon le = 10;    // length d1 = 25;    // diameter of top d2 = 35;    // diameter of bottom d  = -8;    // delta to drop center of bottom \$fn = 100; module shape() {      translate([0, 0, -6])          intersection() {              translate([-le/2, 0, 0])                  difference() {                      rotate([0, 90, 0])                          cylinder(h = le, d = d1);                      translate([-1, 0, d])                          rotate([0, 90, 0])                              cylinder(h = le + 2, d = d2);                      }              intersection() {                  translate([10, 0, 0])                      cylinder(h = 100, d = 30);                  translate([-10, 0, 0])                      cylinder(h = 100, d = 30);                  }              }          } shape(); *difference() {      shape();      translate([0, 0, -4])          scale([0.8, 0.8, 2])              shape();      } _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: flattening curved surfaces

 You might want to look at map projections... cartographers have been working on this for centuries  (for the oblate spheroid class of surfaces).On 25/12/2016 13:40, "jon" <[hidden email]> wrote:I have a bit of code at the end of this question.  It produces a shape with 4 curved sides, each of which lies on the surface of a cylinder.  Note that this is an example shape: I want to work with families of similar shapes, not just with this one example. I would like a way to take each of the 4 surfaces and produce a 2D shape that, when cut out and bent, would conform to the original surface.  The idea is to be able to create the original shape out of, say, cardboard by cutting out the 4 2D shapes and then taping them together. I have a conceptual idea of how this would be done in a traditional programming language if I had a list of the coordinates along each of the 4 boundary lines.  I considered re-writing the code, below, as a sweep, and generating the coordinates explicitly, but a) that is not trivial (to me), and ii) I want to solve the more general case where the equations that determine the shape are not known.  I looked at the generated STL file, and the coordinates are there, but not organized in the way that I would want them to be. This may be more effort than I want to expend, but I wondered if anyone had a brilliant insight. Thanks! Jon le = 10;    // length d1 = 25;    // diameter of top d2 = 35;    // diameter of bottom d  = -8;    // delta to drop center of bottom \$fn = 100; module shape() {     translate([0, 0, -6])         intersection() {             translate([-le/2, 0, 0])                 difference() {                     rotate([0, 90, 0])                         cylinder(h = le, d = d1);                     translate([-1, 0, d])                         rotate([0, 90, 0])                             cylinder(h = le + 2, d = d2);                     }             intersection() {                 translate([10, 0, 0])                     cylinder(h = 100, d = 30);                 translate([-10, 0, 0])                     cylinder(h = 100, d = 30);                 }             }         } shape(); *difference() {     shape();     translate([0, 0, -4])         scale([0.8, 0.8, 2])             shape();     } _______________________________________________ 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
Open this post in threaded view
|

## Re: flattening curved surfaces

Open this post in threaded view
|

## Re: flattening curved surfaces

Open this post in threaded view
|

## Re: flattening curved surfaces

 In reply to this post by jon_bondy jon_bondy wrote Note that this is an example shape: I want to work with families of similar shapes, not just with this one example. I imagine that if it's possible to generate those shapes in polyhedron, it won't be hard to achieve what you want. \$ 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: flattening curved surfaces

 In reply to this post by jon_bondy On 25. des. 2016 02:52, jon wrote: > That was not the answer I was hoping for, but it certainly is the answer > I was looking for! > > Thank you! You are welcome. At least it may have saved you some time chasing the unobtainable. Carsten Arnholm _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: flattening curved surfaces

 Incidental to the question but when I put a # in front of the first cylinder it doesn't show the whole cylinder. It does for the other three cylinders. Why is that?On 25 December 2016 at 09:16, Carsten Arnholm wrote:On 25. des. 2016 02:52, jon wrote: That was not the answer I was hoping for, but it certainly is the answer I was looking for! Thank you! You are welcome. At least it may have saved you some time chasing the unobtainable. Carsten Arnholm _______________________________________________ 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
Open this post in threaded view
|

## Re: flattening curved surfaces

 In reply to this post by cacb cacb wrote On 25. des. 2016 01:39, jon wrote: Using only OpenSCAD, something like that is not possible at all, since there is no way in the language to access the vertices and faces of the result of a boolean operation. Carsten is right but there is a workaround. A python code by Neon22 converts AMF files (possibly exported by OpenSCAD) to a text file in the OpenSCAD polyhedron format. See this discussion. By using its output file in you OpenSCAD code, you will have access to the model vertices and a code may be devised to find and unfold the developable surfaces. However, the latest doesn't seem to be a trivial task. See for instance: http://complexitys.com/english/geometry/developable-surfaces/#.WF9isH10ca9
Open this post in threaded view
|

## Re: flattening curved surfaces

Open this post in threaded view
|

## Re: flattening curved surfaces

Open this post in threaded view
|

## Re: flattening curved surfaces

 In reply to this post by Parkinbot Parkinbot wrote I like your approach and I don't think it is too difficult to implement, if you restrict the design to a set of constraints, which your parser can assume to hold without further testing. (Also I don't see any advantage in using AMF instead of STL.) I have suggested AMF file export because this is the input file format Neon22's python code requires to generate the polyhedron data. Do you call that a not difficult to implement solution? Rely on thresholds is not a good strategy. For instance, subdivide a square in 4 triangles meeting at its center and move up slightly two opposed vertices and move down the other two. It will not be a developable surface but may pass a reasonable threshold. The main property of triangulated developable surfaces that may be handy is that the sum of the internal angles of the triangles incident at each vertex of such surfaces should be 360 degrees. One strategy to find the pieces of developable surfaces could be to calculate that sum at each vertex of the triangulation and collect those vertices that have the required sum of 360 degrees and are in the same connected component of the triangulation. To do that you possibly will need a triangulation data structure that is not trivial to implement in OpenSCAD.
Open this post in threaded view
|

## Re: flattening curved surfaces

 In reply to this post by Ronaldo On 25. des. 2016 13:16, Ronaldo wrote: > Carsten is right but there is a workaround. A python code by Neon22 converts > AMF files (possibly exported by OpenSCAD) to a text file in the OpenSCAD > polyhedron format. See this  discussion > That is a good idea, but he appears to manually modify the converted code to get the modified coordinates, a bit cumbersome. Another idea along the same lines would be to do the coordinate modification in the conversion code, which would essentially become a 'morphing conversion', see below. On the issue of unfolding the surfaces to be traced on paper, it is not possible in the general case, I agree. A spherical surface cannot be unfolded on a flat surface for example. On morphing, I tried it using jons model (scaled up 10x and using \$fn=300 in OpenSCAD). Since all sides are curved in the first place, it lends itself to easy morphing (to some degree). An image of the original shape is attached. Example morphing code (angelscript), using the AMF generated by OpenSCAD: ----     polyhedron@ cs = polyhedron("curved_surfaces.amf");     double px=8;     double pz=4;     const double pi = 4.0*atan(1.0);     // compute transformed vertices     pos3d@[] vert(nv);     for(uint iv=0; iv
Open this post in threaded view
|

## Re: flattening curved surfaces

Open this post in threaded view
|

## Re: flattening curved surfaces

 In reply to this post by Ronaldo Ronaldo wrote Rely on thresholds is not a good strategy. For instance, subdivide a square in 4 triangles meeting at its center and move up slightly two opposed vertices and move down the other two. It will not be a developable surface but may pass a reasonable threshold. You can always construct those counter examples. My opinion is: Know what you do, already when you do your design. This is what I meant by rule 1. The main property of triangulated developable surfaces that may be handy is that the sum of the internal angles of the triangles incident at each vertex of such surfaces should be 360 degrees. Isn't that too strict? Doesn't it hold only for planar surfaces?
Open this post in threaded view
|

## Re: flattening curved surfaces

 2016-12-25 14:32 GMT-02:00 Parkinbot :Ronaldo wrote > The main property of triangulated developable surfaces that may be handy > is that the sum of the internal angles of the triangles incident at each > vertex of such surfaces should be 360 degrees. Isn't that too strict? Doesn't it hold only for planar surfaces?Certainly is not too strict. If a set of triangle around a vertex are part of a developable surface this condition must be met. Otherwise, when they are laid down on a plane, either they will not close (for angle sum lesser then 360) or they will overlap. Note that this condition should be met at the internal vertices. For the border vertices the sum should be lesser than 360. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: flattening curved surfaces

 Ronaldo wrote Certainly is not too strict. I doubt that. Have a look at a cylinder. It contains 3 surfaces that doubtless can be unrolled into 2D. Two of them meet your condition, the third one doesn't. A threshold can be easily selected to separate the triags.
Open this post in threaded view
|

## Re: flattening curved surfaces

 Parkinbot wrote Have a look at a cylinder. It contains 3 surfaces that doubtless can be unrolled into 2D. Two of them meet your condition, the third one doesn't. A threshold can be easily selected to separate the triags. If the only vertices of your cylinder (a prism to be precise) is at the borders of the two planar faces, then none of them satisfies the condition. So they cannot be in the interior of the developed surfaces. Any other vertex not in those borders will satisfy the condition and will be eligible to be inside. Observe that the problem of finding a partition of developable surfaces for a given polyhedron has many solutions. A trivial one is to define a partition of isolated triangles. Another is a partition of triangle pairs. In the case of a prism, it is possible to find a unique partition for the whole surface. There is no better solution, only wrong ones.
Open this post in threaded view
|

## Re: flattening curved surfaces

 It is very tiring to discuss such obvious things and subtleties. Again: I am perfectly sure that the sketched algorithm will work. If you know a better solution, then please present it in a constructive way, so that we follow it.
Open this post in threaded view
|

## Re: flattening curved surfaces

 This post was updated on . In reply to this post by jon_bondy I have seen several implementations of this. There are a couple of guidelines which you might wish to follow just to simplify the code. - triangulate before unrolling. less cases to deal with. - mark the edges you wish to preserve when unrolling. (I use wings3d) - to avoid overlaps, unroll, test and move around to a different face if it overlaps. Else split the shape to a new boundary so overlaps can be avoided. - check your progress against pepakura - a free version of which can be downloaded to view opened files. Pepakura is designed for paper folding and low polygon polyhedra which approximate the more detailed surface. It is quite robust. After you have it all unrolled you're into packing algorithms but that's a different tail... (https://github.com/Jack000/SVGnest)