# Polyhedron generation from two parallel polygones?

39 messages
12
Open this post in threaded view
|

## Polyhedron generation from two parallel polygones?

 Hello, Generating a polyhedron from two polygons is not too difficult when the polygon has a limited number of vertices. However I have a polygon with several tens in order to represent curves correctly. Now my idea is to generate a second polygon from the original one, in a plane parallel to the first one, scale and translate it a little bit and then generate a polyhedron from the original and the new polygon. As I want to achieve this repeatedly and possibly with different polygons, do you think it would be possible to create a short algorithm to generate a suitable path whatever the number of vertices? Which data structures/strategies would you use then? Thank you in advance. -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

 I have code which does this, it basically generates a lot of triangles. In my code I do everything with 3d points, and then do a step at the end which first turns the all of the points into a list of unique vertices, and them converts the list of triangles into references to the vertices On Wed, 17 Jun 2020, 16:13 amundsen, <[hidden email]> wrote:Hello, Generating a polyhedron from two polygons is not too difficult when the polygon has a limited number of vertices. However I have a polygon with several tens in order to represent curves correctly. Now my idea is to generate a second polygon from the original one, in a plane parallel to the first one, scale and translate it a little bit and then generate a polyhedron from the original and the new polygon. As I want to achieve this repeatedly and possibly with different polygons, do you think it would be possible to create a short algorithm to generate a suitable path whatever the number of vertices? Which data structures/strategies would you use then? Thank you in advance. -- 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
Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

 This sort of thing has been done many times by many people. There is a library called list-comprehension-demos that is perhaps one of the first to do it and it displays a method for doing it.  And dotSCAD also has code for this.  https://github.com/JustinSDK/dotSCADIn BOSL2 (a library which is still in development): https://github.com/revarbat/BOSL2/wiki/skin.scadyou can see code that does this, and the wiki shows examples of the results.   If you understand how to use list comprehensions then it is not difficult to construct a polyhedron by connecting two polygons with the same number of vertices, located anywhere in 3-space, though if you generate self-intersecting sides the resulting polyhedron will be invalid.  You simply have to construct the list of vertices and then write a list comprehension that assembles the appropriate face list.   I wrote a skin() routine to connect a sequence of polygons with different numbers of vertices using three different methods.   The most sophisticated is a quadratic programming method to find a minimum edge length vertex alignment for creating triangular faces between the two polygons.  I would say that was a fairly tricky business.   The sweep() operation of taking a given fixed shape and applying transformations is straight forward if you specify the transformations completely but tricky when you try to sweep along a path, because a path doesn't provide enough information to fully define the transformations for each polygon.   -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

 In reply to this post by amundsen I'm not entirely clear on what you want to do, but could a hull() work? -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

 So far I've got the best results with BOSL's convex_hull (see example below). BOSL2's skin would be perfect for that purpose but I couldn't even run the first example without error messages. Is BOSL2 too early in its development or is it me? The basic hull won't do it for sure. use steps = 100; height = 10; startshape = [for(i=[0:steps]) [cos(i/steps * 360) * 2 + 3, sin(i/steps * 360) * 4 + 7, 0]]; endshape = [for(i=[0:steps]) [cos(i/steps * 360) * 10 - 15, sin(i/steps * 360) * 5 - 12, height]]; allpoints = concat(startshape, endshape); polyhedron(points = allpoints, faces = convex_hull3d(allpoints)); -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

 I managed to use BOSL2's skin function. The examples were lacking the required use<> code. So, here's a basic example of what I want to do. use use \$fn=32; polygon_steps = 100; random_range = 1; startshape = [for(i=[0:polygon_steps]) [cos(i/polygon_steps * 360) * 2 + 3, sin(i/polygon_steps * 360) * 4 + 7]]; endshape = [for(i=[0:polygon_steps]) [cos(i/polygon_steps * 360) * 10 - 15 + rands(-random_range, random_range,1)[0], sin(i/polygon_steps * 360) * 5 - 12 + rands(-random_range, random_range,1)[0]]];         skin([startshape, endshape], z=[0,10], slices=10); -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

 In reply to this post by amundsen While your startshape is well behaved, your randomly constructed endshape is not *simple*. I.e. it has self-intersections and therefore you won't get a valid result - check with F12 for pink triangles. -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

 In reply to this post by amundsen My tubemesh library is designed precisely for this kind of thing. It allows the two polygons to have different numbers of points, and tries to optimize triangle placement. You can do a gradual morphing of one polygon into another, with various transformations along the way. Sometimes you will have problems with self-intersections, though often these can be avoided by adding more morphing layers. https://www.thingiverse.com/thing:2406760-- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

 I am really happy with my current results (see picture) but I'll have a look to your library @Alexander Pruss. @Parkinbot random was just a tryout, I don't really need it. Thank you everyone. -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

 In reply to this post by amundsen Let me also recommend the nSplines library by Parkinbot.       https://www.thingiverse.com/thing:1208001His library also includes an interpolator which can be applied to an array of linear lists, and extrapolate new entire lists.  Very nice for smoothing out rough transitions from one list/polygon to the next! I have used nSplines quite extensively, such as these flowers: https://www.thingiverse.com/richalt2/designsFYI, Rich ----- richalt2  (so why does the forum show me as OpenSCAD mailing list?) Rich Altmaier -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

 In reply to this post by amundsen If you want to use dotSCAD.... use ; use ; \$fn=32; polygon_steps = 100; random_range = 1; startshape = [     for(i=[0:polygon_steps])     [         cos(i/polygon_steps * 360) * 2 + 3,         sin(i/polygon_steps * 360) * 4 + 7,         0     ] ]; endshape = [     for(i=[0:polygon_steps])     [         cos(i/polygon_steps * 360) * 10 - 15 + rands(-random_range, random_range,1)[0],         sin(i/polygon_steps * 360) * 5 - 12 + rands(-random_range, random_range,1)[0],         10  // z     ] ]; // I think `sweep` is enough. sweep(     [         startshape,         endshape             ] ); /* // In case you really want a `slices` parameter... loft(         [             startshape,             endshape                 ],         slices = 4 ); */ ----- https://openhome.cc-- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Polyhedron generation from two parallel polygones?

 ah!btw.. I have a Library or a dotSCAD question: Your example starts withuse ;use ;I see this often. But it never works. In order to get it working I need to change it touse ;use ;Is this correct? And normal to need to search the lib' before I know the exact path or is there a way to shorten this ?Am Mi., 8. Juli 2020 um 04:46 Uhr schrieb caterpillar <[hidden email]>:If you want to use dotSCAD.... use ; use ; \$fn=32; polygon_steps = 100; random_range = 1; startshape = [     for(i=[0:polygon_steps])     [         cos(i/polygon_steps * 360) * 2 + 3,         sin(i/polygon_steps * 360) * 4 + 7,         0     ] ]; endshape = [     for(i=[0:polygon_steps])     [         cos(i/polygon_steps * 360) * 10 - 15 + rands(-random_range, random_range,1)[0],         sin(i/polygon_steps * 360) * 5 - 12 + rands(-random_range, random_range,1)[0],         10  // z     ] ]; // I think `sweep` is enough. sweep(     [         startshape,         endshape            ] ); /* // In case you really want a `slices` parameter... loft(         [             startshape,             endshape                ],         slices = 4 ); */ ----- https://openhome.cc -- 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
Open this post in threaded view
|