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 |
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, _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Was it difficulte to code such an algorithm? Any advice?
-- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
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/dotSCAD In BOSL2 (a library which is still in development): https://github.com/revarbat/BOSL2/wiki/skin.scad you 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 |
In reply to this post by amundsen
this one is mine. The tricky part, which I just ignored for this
example, is the starting and ending face. As long as they are reasonable, flat polyhedrons, this should work, although my actual code triangularises them (a more annoying problem) On Wed, Jun 17, 2020 at 5:36 PM amundsen <[hidden email]> wrote: > > Was it difficulte to code such an algorithm? Any advice? > > > > -- > 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 polyhedron.scad (3K) Download Attachment |
of course, I should have expected an error in the part of the code I
don't actually use... The only change in this is to reverse the last polygon, as the end cap needs to be flipped On Wed, Jun 17, 2020 at 6:37 PM A. Craig West <[hidden email]> wrote: > > this one is mine. The tricky part, which I just ignored for this > example, is the starting and ending face. As long as they are > reasonable, flat polyhedrons, this should work, although my actual > code triangularises them (a more annoying problem) > > On Wed, Jun 17, 2020 at 5:36 PM amundsen <[hidden email]> wrote: > > > > Was it difficulte to code such an algorithm? Any advice? > > > > > > > > -- > > 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 polyhedron.scad (4K) Download Attachment |
In reply to this post by amundsen
Thank you @acwest and @adrianv! I'll have a look to all of this.
-- 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 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 |
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 <BOSL/convex_hull.scad> 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 |
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 <BOSL2/skin.scad> use <BOSL2/rounding.scad> $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 |
At the top of each documentation page for BOSL2 it tells you what includes to
use for using the documented library file. For skin.scad it says: include <BOSL2/std.scad> include <BOSL2/skin.scad> Do you think this is insufficient and the includes should be repeated for every example? Note that you are not using rounding.scad in your example. But you do need std.scad, which you don't list. So have you achieved your goal or do you still have questions? amundsen wrote > 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 <BOSL2/skin.scad> > use <BOSL2/rounding.scad> > > $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 > Discuss@.openscad > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- 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 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 |
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 |
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. <http://forum.openscad.org/file/t2715/extrusion_13bis.png> -- 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 Alexander Pruss
It looks like tubemesh is very similar to BOSL2 skin. When you say
"gradually morphing of one polygon into another" do you mean simply a linear interpolation to generate intermediate slices, or is there something else going on? Alexander Pruss wrote > 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 > Discuss@.openscad > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- 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 amundsen
Let me also recommend the nSplines library by Parkinbot.
https://www.thingiverse.com/thing:1208001 His 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/designs FYI, 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 |
In reply to this post by amundsen
If you want to use dotSCAD....
use <loft.scad>; use <sweep.scad>; $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 |
btw.. I have a Library or a dotSCAD question: Your example starts with use <loft.scad>; use <sweep.scad>; I see this often. But it never works. In order to get it working I need to change it to use <dotSCAD/src/loft.scad>; use <dotSCAD/src/sweep.scad>; 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.... _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
The `libraries` folder of OpenSCAD is only one of library locations.
https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Libraries I set `OPENSCADPATH` to the src folder of dotSCAD so all my examples start from the root of src. https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Libraries#Setting_OPENSCADPATH ----- https://openhome.cc -- Sent from: http://forum.openscad.org/ _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
I see thank you. This reminds me of a long unsuccessful run. I just tried it - again no success.. am I to stupid for this? I entered the correct* path into every .profile: fully restarted: "WARNING: Can't open library 'loft.scad'.WARNING: Can't open library 'sweep.scad'.(* when I call this path in Finder (via cmd+shift+g) /Users/dpa/Documents/OpenSCAD/libraries/dotSCAD/src then I end up at the correct path)
restarted openSCAD .."WARNING: Can't open library 'loft.scad'.WARNING: Can't open library 'sweep.scad'. 😨 Am Mi., 8. Juli 2020 um 11:17 Uhr schrieb caterpillar <[hidden email]>: The `libraries` folder of OpenSCAD is only one of library locations. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org |
Free forum by Nabble | Edit this page |