# Polyhedron tube with irregular sides -- is it possible ?

112 messages
1234 ... 6
Open this post in threaded view
|

## Polyhedron tube with irregular sides -- is it possible ?

 This post was updated on . I wanna make some tube-like shape with irregular sides, similar like one below: This is made with a polygon + linear_extrude out of pts_out =  [ [0,0],[6,0],[6,5],[0,5] ]; pts_in =  [ [2,1],[5,2], [3,4]]; To make a polyhedron, I convert pts to 3D: pts =  [[0, 0, 0], [6, 0, 0], [6, 5, 0], [0, 5, 0], [2, 1, 0], [5, 2, 0], [3, 4, 0], [0, 0, 3], [6, 0, 3], [6, 5, 3], [0, 5, 3], [2, 1, 3], [5, 2, 3], [3, 4, 3]]; Their indices are placed on the extruded shape as follow: I tried several combinations of faces but couldn't get a polyhedron. Here are two tries:  faces1= [[0, 7, 8, 1], [1, 8, 9, 2], [2, 9, 10, 3], [3, 10, 7, 0], [4, 5, 12, 11], [5, 6, 13, 12], [6, 4, 11, 13], [0, 1, 2, 3], [4, 5, 6], [7, 8, 9, 10], [11, 12, 13]]; polyhedron( points = pts, faces = faces1  );  faces2 = [[0, 7, 8, 1], [1, 8, 9, 2], [2, 9, 10, 3], [3, 10, 7, 0], [4, 5, 12, 11], [5, 6, 13, 12], [6, 4, 11, 13], [0, 1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12, 13]]; color(undef,0.8) polyhedron( points = pts , faces = faces2 ); I'm wondering if this is even possible and if yes, how? \$ 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: Polyhedron tube with irregular sides -- is it possible ?

Open this post in threaded view
|

## Re: Polyhedron tube with irregular sides -- is it possible ?

 Peter Falke wrote ​I guess you need to tesselate the face properly. That was my very first try. But consider that I want a generalized approach, in which users can punch any shape of hole on a surface of any shape, this one doesn't seem to be ideal. My 2nd try was a function to generate points like this: It works, but I imagine that it is still far from the objective of "any shape". So I thought, we can do polygon of any shape with a hole of any shape like this: polygon (points= concate( pts_out,pts_in), faces= [ [0,1,2,3],[4,5,6] ] );   Shouldn't we be able to use the same way to generate a surface with a hole in 3D? So I tried, but it doesn't seem to work. Maybe we can implement this feature by allowing faces to have this way: [ ..., [ [0, 1, 2, 3], [4, 5, 6] ]    , [ [7, 8, 9], [10, 11, 12, 13] ]] and with this allows for a "punched hole surface" in 3D, thus consistent with that in 2D ? \$ 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: Polyhedron tube with irregular sides -- is it possible ?

 Why do you want to exclude using the difference() operation?2015-09-14 17:09 GMT+02:00 runsun :Peter Falke wrote > ​I guess you need to tesselate the face properly. That was my very first try. But consider that I want a generalized approach, in which users can punch any shape of hole on a surface of any shape, this one doesn't seem to be ideal. My 2nd try was a function to generate points like this: It works, but I imagine that it is still far from the objective of "any shape". So I thought, we can do polygon of any shape with a hole of any shape like this: > polygon (points= concate( pts_out,pts_in), faces= [ [0,1,2,3],[4,5,6] ] ); Shouldn't we be able to use the same way to generate a surface with a hole in 3D? So I tried, but it doesn't seem to work. Maybe we can implement this feature by allowing faces to have this way: > [ > ..., * > [ [0, 1, 2, 3], [4, 5, 6] ] >    , [ [7, 8, 9], [10, 11, 12, 13] ] * > ] and with this allows for a "punched hole surface" in 3D, thus consistent with that in 2D ? ----- \$  Runsun Pan, PhD \$ -- libs: doctest , faces ( git ), offliner ( git );  tips: hash( 1 , 2 ), sweep , var \$ -- Linux Mint 17.1 Rebecca x64  + OpenSCAD 2015.03.15/2015.04.01.nightly -- View this message in context: http://forum.openscad.org/Polyhedron-tube-with-irregular-sides-is-it-possible-tp13813p13824.html 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 _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Polyhedron tube with irregular sides -- is it possible ?

 Peter Falke wrote Why do you want to exclude using the difference() operation? It's part of my polyhedron-based lib, in which I'll use the "holed surface" in different situations, including the irregular-side tube mentioned here. \$ 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: Polyhedron tube with irregular sides -- is it possible ?

 In reply to this post by runsun polyhedron() cannot do "faces with holes" currently as far as i know. However there is a work-around. It is called the Keyhole Polygon... Basically you take any polygon with a single hole... and pretend you slice a knife down from the outside of the polygon, straight down, until you cut into the hole. What you end up with is a single polygon without any holes. Here is a picture https://sozvyezdami.files.wordpress.com/2013/04/11.png?w=640The caveat that the new edges you create by cutting will be coincident with each other.... and the 'points' or 'nodes' of those new edges will also be coincident, which can be a problem for some polygon processing algorithms. However it appears to work on your basic example in OpenSCAD. Here is your code rewritten to have two 'keyhole' polygons on top and bottom. pts =  [[0, 0, 0], [6, 0, 0], [6, 5, 0], [0, 5, 0], [2, 1, 0], [5, 2, 0], [3, 4, 0], [0, 0, 3], [6, 0, 3], [6, 5, 3], [0, 5, 3], [2, 1, 3], [5, 2, 3], [3, 4, 3]]; faces1= [[0, 7, 8, 1], [1, 8, 9, 2], [2, 9, 10, 3], [3, 10, 7, 0], [4, 5,12, 11], [5, 6, 13, 12], [6, 4, 11, 13], [0, 1, 2, 3, 4, 6, 5, 4, 3], [10, 9, 8, 7, 11, 12, 13, 11, 7]]; polyhedron( points = pts, faces = faces1  ); Also i had to re-order some of the vertices, as viewable in 'View/ThrownTogether' mode within OpenSCAD to make sure there were no naughty purples. Hope this helps! -don bright [hidden email] _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: Polyhedron tube with irregular sides -- is it possible ?

 Hi Don, interesting approach. I seem to read similar one when reading Computer Geometry or something a while back, but can't recall what it's for. This approach seems to simplify the problem significantly. The re-arrangement of points is not a big issue. On the other hand, for my application, it might bring up other problems. What I show in this thread is an extremely simplified example. The actual tube in my lib could be a complicated one with random curving, etc. To make a holed surface on the end of a long tube with this approach, the entire tube will have to be sliced apart. I also intend to use a holed surface as the merging face when cylinder of different sides (in polyhedron) linked together. That is, to merge two polyhedria. It will then be a budding, but not hole-punching/cutting, process. Anyway, thx for the idea. I believe it'd turn out useful in the future development of my lib. \$ 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: Polyhedron tube with irregular sides -- is it possible ?

 In reply to this post by donbright Regarding "faces with hole", following up the "keyhole polygon" solution described by dob bright 3 yrs ago (which is also presented as an "alternative face description" in the official document ). I found that it could even be used to make a polyhedron cube with multiple holes, like this: ```pts = [[0, 0, 0], [0, 4, 0], [3, 5, 0], [2, 0, 0], [0, 0, 2], [0, 4, 2], [3, 5, 2], [2, 0, 2], [1, 0.5, 0], [0.4, 1.2, 0], [0.5, 2.1, 0], [2, 1.5, 0], [1, 0.5, 2], [0.4, 1.2, 2], [0.5, 2.1, 2], [2, 1.5, 2], [1.5, 2.5, 0], [0.5, 3.5, 0], [2, 3.5, 0], [1.5, 2.5, 2], [0.5, 3.5, 2], [2, 3.5, 2]]; faces = [[4, 5, 6, 7, 4, 15, 14, 13, 12, 15, 4, 21, 20, 19, 21], [3, 2, 1, 0, 3, 8, 9, 10, 11, 8, 3, 16, 17, 18, 16], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7], [9, 8, 12, 13], [10, 9, 13, 14], [11, 10, 14, 15], [8, 11, 15, 12], [17, 16, 19, 20], [18, 17, 20, 21], [16, 18, 21, 19]]; polyhedron(pts,faces); ``` In this case, the top face uses pts[4] as the starting point to cut into the two holes: ```[ 4, 5, 6, 7 , 4 , 15, 14, 13, 12, 15 , 4 , 21, 20, 19, 21 ] ``` as shown in this figure: What surprises me is that the 2 cut lines, 4~15 and 4~21, go across the entire holes. Is this normal? It seems that this approach works in more holes, too: ```pts = [[0, 0, 0], [0, 4, 0], [3, 5, 0], [2, 0, 0], [0, 0, 1], [0, 4, 1], [3, 5, 1], [2, 0, 1], [1, 0.5, 0], [0.4, 1.2, 0], [2, 1.5, 0], [1, 0.5, 1], [0.4, 1.2, 1], [2, 1.5, 1], [0.5, 1.8, 0], [0.5, 2.1, 0], [1.8, 2.2, 0], [1.5, 2, 0], [0.5, 1.8, 1], [0.5, 2.1, 1], [1.8, 2.2, 1], [1.5, 2, 1], [1, 2.75, 0], [0.5, 3.5, 0], [2, 3.5, 0], [1, 2.75, 1], [0.5, 3.5, 1], [2, 3.5, 1]]; faces = [[4, 5, 6, 7, 4, 13, 12, 11, 13, 4, 21, 20, 19, 18, 21, 4, 27, 26, 25, 27], [3, 2, 1, 0, 3, 8, 9, 10, 8, 3, 14, 15, 16, 17, 14, 3, 22, 23, 24, 22], [0, 1, 5, 4], [1, 2, 6, 5], [2, 3, 7, 6], [3, 0, 4, 7], [9, 8, 11, 12], [10, 9, 12, 13], [8, 10, 13, 11], [15, 14, 18, 19], [16, 15, 19, 20], [17, 16, 20, 21], [14, 17, 21, 18], [23, 22, 25, 26], [24, 23, 26, 27], [22, 24, 27, 25]]; polyhedron(pts,faces); ``` The top face: ```[ 4, 5, 6, 7 , 4 , 13, 12, 11, 13 , 4 , 21, 20, 19, 18, 21 , 4 , 27, 26, 25, 27 ] ``` I'd like to know what you experts think about this. \$ Runsun Pan, PhD \$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); \$ Tips; \$ Snippets 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 \$ 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: Polyhedron tube with irregular sides -- is it possible ?

 Very interesting stuff. Thanks for digging out this hack! I immediately wanted this for sweep();   A sweep with a "close" attribute doing a single hole without difference() is already nothing new - you sweep up and down.   sweep([circle(10, 0), circle(10, 20), circle(7, 20), circle(7, 0)], close = true);   function circle(r=10, z = 0, N=10) = [for(i=[0:N-1]) [r*cos(360/N*i), r*sin(360/N*i), z]]; I guess this approach will allow to implement a sweep() allowing for as many holes as one likes. I'll have to add a new interface parameter to my sweep() that lets one supply a list of polygons describing the holes. The first and last face need the hack, the rest is more or less straight forward. Being able to sweep objects with multiple holes can speed up rendering of a lot of stuff. I'm looking forward to have it. -- 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 tube with irregular sides -- is it possible ?

 It's happy to preview but doesn't work with a union with a unit cube and F6.On Mon, 10 Dec 2018 at 04:09, Parkinbot <[hidden email]> wrote:Very interesting stuff. Thanks for digging out this hack! I immediately wanted this for sweep();  A sweep with a "close" attribute doing a single hole without difference() is already nothing new - you sweep up and down.  sweep([circle(10, 0), circle(10, 20), circle(7, 20), circle(7, 0)], close = true);  function circle(r=10, z = 0, N=10) = [for(i=[0:N-1]) [r*cos(360/N*i), r*sin(360/N*i), z]]; I guess this approach will allow to implement a sweep() allowing for as many holes as one likes. I'll have to add a new interface parameter to my sweep() that lets one supply a list of polygons describing the holes. The first and last face need the hack, the rest is more or less straight forward. Being able to sweep objects with multiple holes can speed up rendering of a lot of stuff. I'm looking forward to have it. -- 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 tube with irregular sides -- is it possible ?

 Oh, how stupid I didn't check this little detail :-( . My first approach was to use a polygon with the same point sequence, but that didn't work, because my sweep() currently also puts vertical walls along the kerfs. So if CGAL would cooperate, one could easily implement sweep() to omit those walls.   use a = circle(30, 0, 10, -1);   b = circle(6, 0, 100, 1);   q = prepsweep([a, each forN_(b, 17)]); sweep([q, Tz_(10, q)]); function prepsweep(P) = [each P[0], each for(p=[1:len(P)-1]) each [P[p], [P[p][0]], [P[0][len(P[0])-1]]]]; function forN_(P, r=0, N=6) = [for(i=[0:N-1]) T_(r*sin(360/N*i), r*cos(360/N*i), 0, P)]; function circle(r=10, z = 0, N=10, dir=1) = [for(i=[0:N-1]) [r*cos(dir*360/N*i), r*sin(dir*360/N*i), z]]; -- 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 tube with irregular sides -- is it possible ?

 A multi-hole sweep can be also implemented straight forward and does not need this hack. It has to provide its own triangulation of the first and last faces with holes and just can't rely on CGAL to do it. CGAL gets slow anyway, when it starts with "trying alternative construction". The rest is just building the walls like a vectorized sweep. The new call will be something like: sweep(outerpolygon_sequence=a, listofholes_sequence=b) As soon as I find time, I'm gonna try it. -- 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 tube with irregular sides -- is it possible ?

 You could just use clockwise-counterclockwise to identify holes. I did write a triangulation thing for bending text, though there's probably a better way. https://gist.github.com/NateTG/b350378c56f436d3996a2107f7cba965-- 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 tube with irregular sides -- is it possible ?

 With a polyhedron counter-clockwise is already used to mean a face facing the other way, which is different from a hole in a face. E.g. in runsun's numbered example the bottom face is listed counter-clockwise looking from the top because it is pointing downwards.Perhaps the first polygon in the face could be assumed the outward facing direction and any polygons in the same face that go the opposite direction to be holes in it.On Mon, 10 Dec 2018 at 18:17, NateTG <[hidden email]> wrote:You could just use clockwise-counterclockwise to identify holes. I did write a triangulation thing for bending text, though there's probably a better way. https://gist.github.com/NateTG/b350378c56f436d3996a2107f7cba965 -- 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 tube with irregular sides -- is it possible ?

Open this post in threaded view
|

## Re: Polyhedron tube with irregular sides -- is it possible ?

Open this post in threaded view
|

## Re: Polyhedron tube with irregular sides -- is it possible ?

Open this post in threaded view
|

## Re: Polyhedron tube with irregular sides -- is it possible ?

 In reply to this post by Parkinbot A triangulation like earcut with holes will be cumbersome to implement in OpenSCAD. However a fast and viable solution for implementing the multi-hole sweep is to use a vectorized lazy union sweep for the holes and difference the result from the sweep of the outer polygon. For export one will have to use a Boolean operation to do a CGAL check anyway. -- 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
|