# What's the best way to accomplish splitting these elements?

18 messages
Open this post in threaded view
|

## What's the best way to accomplish splitting these elements?

 Assuming I have: translate([4, 5, 0]) cylinder(d1=10, d2=0, h=10); cylinder(d1=10, d2=0, h=10); translate([-5, 3, 0]) cylinder(d1=15, d2=0, h=10); The result is this: This is just a simple example. I need to be able to split this up into chunks for 3d printing. (It's for an art project) Right now, I'm doing 160x160 mm regions (via intersection with cube). However, this leaves very very ugly inorganic seams. I would like to be able to do basically "intersections between cones extruded along z axis", for lack of a better term. Where two of the cones intersect, I would like to be able to "cut straight down" to the xy plane. The result for this example would be three separate objects, that get "cylinderified" at the points where they intersect. Does this make sense? I can provide a pencil sketch if that would be helpful also. This must be possible, I just am not skilled enough with openscad to achieve this. My thought is perhaps create 2d profile shapes from the intersection of the cones, projected to an xy plane at z = 0. Then extrude those above the cone max heights. Finally, one by one, do intersections of those extruded projections with each cone. I'm not exactly sure how to do this though. (In addition, what is the name of the operation I am trying to accomplish here?) Thank you so much!! -- 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: What's the best way to accomplish splitting these elements?

 r u trying to do something like Tower of Hanoi? On 7/5/19, guaranteed_interwoven <[hidden email]> wrote: > Assuming I have: > > translate([4, 5, 0]) > cylinder(d1=10, d2=0, h=10); > > cylinder(d1=10, d2=0, h=10); > > translate([-5, 3, 0]) > cylinder(d1=15, d2=0, h=10); > > The result is this: > > > > This is just a simple example. I need to be able to split this up into > chunks for 3d printing. (It's for an art project) > > Right now, I'm doing 160x160 mm regions (via intersection with cube). > > However, this leaves very very ugly inorganic seams. > > I would like to be able to do basically "intersections between cones > extruded along z axis", for lack of a better term. > > Where two of the cones intersect, I would like to be able to "cut straight > down" to the xy plane. > > The result for this example would be three separate objects, that get > "cylinderified" at the points where they intersect. > > Does this make sense? I can provide a pencil sketch if that would be > helpful > also. > > This must be possible, I just am not skilled enough with openscad to > achieve > this. > > My thought is perhaps create 2d profile shapes from the intersection of the > cones, projected to an xy plane at z = 0. Then extrude those above the cone > max heights. Finally, one by one, do intersections of those extruded > projections with each cone. I'm not exactly sure how to do this though. > > (In addition, what is the name of the operation I am trying to accomplish > here?) > > Thank you so much!! > > > > -- > 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: What's the best way to accomplish splitting these elements?

Open this post in threaded view
|

## Re: What's the best way to accomplish splitting these elements?

Open this post in threaded view
|

## Re: What's the best way to accomplish splitting these elements?

 I think MIchael's code can be simplified by:module cutCyl() {  difference()  {    children(0);    for(i=[1:1:\$children-1])      linear_extrude(height=1000)        projection() children(i);  }}cutCyl() { c1(); c2(); c3();} };However, the union of that last object with c2() and c3() does not seem to be the intended split of the cone union.The problem as I see is that the line of intersection of two cones is in a vertical plane just in the very specific case where both cone have same height and base diameter. In those case, a vertical plane can "organically" split the twp cones. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: What's the best way to accomplish splitting these elements?

 I think now I have understood guaranteed_interwoven's construction. Very clever split.\$fn = 20;t1 = [4, 5, 0];t2 = [0, 0, 0];t3 = [-5, 3, 0];delta = 0.02;module c1() translate(t1) cylinder(d1=10, d2=0, h=10);module c2() translate(t2) cylinder(d1=10, d2=0, h=10);module c3() translate(t3) cylinder(d1=15, d2=0, h=10);              module cutCyl()  intersection() {    children(0);    linear_extrude(height=1000)      projection()        difference() {          children(0);          for(i=[1:1:\$children-1]) children(i);        }  }translate(delta*t1) cutCyl() { c1(); c2(); c3();}translate(delta*t2) cutCyl() { c2(); c1(); c3();}translate(delta*t3) cutCyl() { c3(); c1(); c2();} _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: What's the best way to accomplish splitting these elements?

 You folks are my heroes :) This last one is exactly what I needed! Especially with the delta in there, that is very slick. In terms of iterating over each object and exporting, I have been using bash for that, so no worries there. (Unless there is a better way I'm not aware of.) This is perfect! Thank you so much!! -- 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: What's the best way to accomplish splitting these elements?

 This post was updated on . My apologies, one last question here. I'm trying to do one last generifying step, to extend to an arbitrary number of objects. \$fn = 20; module gen_node(coords, d, h) {   translate(coords)   cylinder(d1=d, d2=0, h=h); }               module cutCyl() {   intersection()   {     children(0);     linear_extrude(height=1000)     projection()     {       difference()       {         children(0);         for(i=[1:1:\$children-1]) children(i);       }     }   } } data = [   [[4, 5, 0], 10, 10],   [[0, 0, 0], 10, 20],   [[-5, 3, 0], 15, 10],   [[-2, 6, 0], 15, 7], ]; /* Does not work: cutCyl() {   for (i = [0: len(data)])   {     gen_node(data[i][0], data[i][1], data[i][2]);   } } */ // Does work cutCyl() {   gen_node(data[0][0], data[0][1], data[0][2]);   gen_node(data[1][0], data[1][1], data[1][2]);   gen_node(data[2][0], data[2][1], data[2][2]);   gen_node(data[3][0], data[3][1], data[3][2]); } I did notice that the delta doesn't work for certain shapes. The delta is a good idea I think to guarantee that the pieces fit together once printed. What I can do is that the "subtracting" objects can just have their diameters increased by that delta, which I think will work nicely. So I basically want to do a for loop from within cutCyl, but the actual for loop version doesn't work. I had a suspicion that the for loop was affecting the object tree, but I'm not exactly sure how. So I tried to unroll the for loop manually, and this does work. So my question is now "How do I modify cutCyl so that it can accept the for looped version here?" (As an aside, I have been writing openscad code the same way I am used to writing C, with the opening braces on the next line. However, I defer to the style guide of the language of course, is this generally frowned upon? Should I adopt the style I have seen in examples in this thread?) Thank you!! -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list Discuss@lists.openscad.org http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: What's the best way to accomplish splitting these elements?

Open this post in threaded view
|

## Re: What's the best way to accomplish splitting these elements?

Open this post in threaded view
|

## Re: What's the best way to accomplish splitting these elements?

 In reply to this post by MichaelAtOz Understood. How do I work around this implicit for loop union then? Thank you! -- 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: What's the best way to accomplish splitting these elements?

 This post was updated on . Never mind, I think I have it solved: \$fn = 20; delta = 0.5; module gen_node(coords, d, h) {   translate(coords)   cylinder(d1=d, d2=0, h=h); }     data = [   [[4, 5, 0], 10, 10],   [[0, 0, 0], 10, 20],   [[-5, 3, 0], 15, 10],   [[-2, 6, 0], 15, 7],   [[2, 16, 0], 20, 20], ]; module embedded(target) {   intersection()   {     gen_node(data[target][0], data[target][1], data[target][2]);     linear_extrude(height=1000)     projection()     {       difference()       {         gen_node(data[target][0], data[target][1], data[target][2]);         for(i=[0:len(data)])         {           if(i != target)           {             gen_node(data[i][0], data[i][1] + delta, data[i][2]);           }         }       }     }   } } for(i = [0:len(data)-1]) {   embedded(i); } Having to embed the module call in the actual operation feels wrong to me, but I don't think it's possible any other way. -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list Discuss@lists.openscad.org http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

## Re: What's the best way to accomplish splitting these elements?

 I thought for sure my delta solution would work...but sadly it appears inconsistent. Is there an easy way to fix that I wonder? Thank you! -- 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: What's the best way to accomplish splitting these elements?

 I think I'm closer with: \$fn = 20; delta = 0.5; module gen_node(coords, d, h) {   translate(coords)   cylinder(d1=d, d2=0, h=h); }     data = [   [[4, 5, 0], 10, 10],   [[0, 0, 0], 10, 20],   [[-5, 3, 0], 15, 10],   [[-2, 6, 0], 15, 7],   [[2, 16, 0], 20, 20], ]; module embedded(target) {       translate(data[target][0])   scale([(data[target][1] - delta)/data[target][1], (data[target][1] - delta)/data[target][1], 1])   translate(-data[target][0])       intersection()   {     gen_node(data[target][0], data[target][1], data[target][2]);     linear_extrude(height=1000)     projection()     {       difference()       {         gen_node(data[target][0], data[target][1], data[target][2]);         for(i=[0:len(data)])         {           if(i != target)           {             gen_node(data[i][0], data[i][1], data[i][2]);           }         }       }     }   } } for(i = [0:len(data) - 1]) {   embedded(i); } This is at least consistent per edge, but not consistent per node or globally. -- 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: What's the best way to accomplish splitting these elements?

 I don't think that changing the cone shapes is a good idea to get the intended gap. And in some cases, there is no displacement of the embeded(target) which produces a good gap, for instance when one cone base is entirely inside another cone base. So, the general problem of finding appropriate small cone displacement to get gaps has no solution. To find a solution when one exists seems to be a hard problem.I tried a heuristic strategy that does not work in many cases; change the main code to:delta = 0.02;for(i = [0:len(data)-1]){  translate(displ(i))  embedded(i);}where displ() is defined by:function sum(l) =  [for(i=[0:len(l)-1]) 1]*l;function displ(i) =   let( ctp = sum([for(di=data) di[0]])/len(data) )  delta*(data[i][0]-ctp);BTW, two 'for' in your code have an improper last index and I got a warnings of undef values delivered to translate.Correction:        for(i=[0:len(data)-1])Em seg, 8 de jul de 2019 às 10:31, guaranteed_interwoven <[hidden email]> escreveu:I think I'm closer with: \$fn = 20; delta = 0.5; module gen_node(coords, d, h) {   translate(coords)   cylinder(d1=d, d2=0, h=h); }      data = [   [[4, 5, 0], 10, 10],   [[0, 0, 0], 10, 20],   [[-5, 3, 0], 15, 10],   [[-2, 6, 0], 15, 7],   [[2, 16, 0], 20, 20], ]; module embedded(target) {   translate(data[target][0])   scale([(data[target][1] - delta)/data[target][1], (data[target][1] - delta)/data[target][1], 1])   translate(-data[target][0])   intersection()   {     gen_node(data[target][0], data[target][1], data[target][2]);     linear_extrude(height=1000)     projection()     {       difference()       {         gen_node(data[target][0], data[target][1], data[target][2]);         for(i=[0:len(data)])         {           if(i != target)           {             gen_node(data[i][0], data[i][1], data[i][2]);           }         }       }     }   } } for(i = [0:len(data) - 1]) {   embedded(i); } This is at least consistent per edge, but not consistent per node or globally. -- 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: What's the best way to accomplish splitting these elements?

 why not using offset() after the projection? module embedded(target, delta) {   intersection()   {     gen_node(data[target][0], data[target][1], data[target][2]);     linear_extrude(height=1000, convexity = 5)     offset(-delta)     projection()     {       difference()       {         gen_node(data[target][0], data[target][1], data[target][2]);         for(i=[0:len(data)-1])         {           if(i != target)           {             gen_node(data[i][0], data[i][1], data[i][2]);           }         }       }     }   } } -- Sent from: http://forum.openscad.org/_______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org