restrict hull function to one or two dimensions

classic Classic list List threaded Threaded
42 messages Options
123
Reply | Threaded
Open this post in threaded view
|

restrict hull function to one or two dimensions

rav0r
This post has NOT been accepted by the mailing list yet.
I am trying to modulate an object by not changing it's suface so I designed a code for it to be sliced and the slices be rearranged after a custom equation. The problem I have is that if the object is not flat and has holes that need to be preserved, hull does not help much. As a test, we place two objects and use the code, the two join. Of course, in a simplified case, I can cut the object and create a module out of every cut, but is there a way to automize this for, let's say, 100 modules?  



module test() {
cube([200,10,2]);
translate([0,12,0])
cube([200,10,2]);
}



//variables for cut points
ca1=-8.89;
ca2=-8.9;
cb1=-9.89;
cb2=-9.9;

//variables for equation
a=110;
b=125;
c=-250;


//variables for y cut points
yca1=-8.89;
yca2=-8.9;
ycb1=-9.89;
ycb2=-9.9;

//variables for y equation
ya=110;
yb=125;
yc=-250;

module x2() {

for (z = [1:50])
hull() {
translate([0,0,log(z+a)*b+c])

{

difference() {
test();
translate([z+ca1,-10,-1]) cube([300,200,200]);
 
translate([ca2-300+z,-100,-1]) cube([300,200,200]);
}
}


translate([0,0,log(z+a-1)*b+c])

{
difference() {
test();
translate([z+cb1,-10,-1]) cube([300,200,200]);
 
translate([-300+cb2+z,-100,-1]) cube([300,200,200]);
}
}

}
}


x2();
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

MichaelAtOz
Administrator
rav0r wrote
I am trying to modulate an object by not changing it's suface so I designed a code for it to be sliced and the slices be rearranged after a custom equation. The problem I have is that if the object is not flat and has holes that need to be preserved, hull does not help much. As a test, we place two objects and use the code, the two join. Of course, in a simplified case, I can cut the object and create a module out of every cut, but is there a way to automize this for, let's say, 100 modules?  



module test() {
cube([200,10,2]);
translate([0,12,0])
cube([200,10,2]);
}



//variables for cut points
ca1=-8.89;
ca2=-8.9;
cb1=-9.89;
cb2=-9.9;

//variables for equation
a=110;
b=125;
c=-250;


//variables for y cut points
yca1=-8.89;
yca2=-8.9;
ycb1=-9.89;
ycb2=-9.9;

//variables for y equation
ya=110;
yb=125;
yc=-250;

module x2() {

for (z = [1:50])
hull() {
translate([0,0,log(z+a)*b+c])

{

difference() {
test();
translate([z+ca1,-10,-1]) cube([300,200,200]);
 
translate([ca2-300+z,-100,-1]) cube([300,200,200]);
}
}


translate([0,0,log(z+a-1)*b+c])

{
difference() {
test();
translate([z+cb1,-10,-1]) cube([300,200,200]);
 
translate([-300+cb2+z,-100,-1]) cube([300,200,200]);
}
}

}
}


x2();
bump, as it didn't make it to the mailing list.
Admin - email* me if you need anything,
or if I've done something stupid...
* click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain; to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.


The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/ time is running out!
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

cacb
On 2016-03-25 02:41, MichaelAtOz wrote:

> rav0r wrote
>> I am trying to modulate an object by not changing it's suface so I
>> designed a code for it to be sliced and the slices be rearranged after
>> a
>> custom equation. The problem I have is that if the object is not flat
>> and
>> has holes that need to be preserved, hull does not help much. As a
>> test,
>> we place two objects and use the code, the two join. Of course, in a
>> simplified case, I can cut the object and create a module out of every
>> cut, but is there a way to automize this for, let's say, 100 modules?

You could perhaps slice the model by means of many intersection()'s with
a thin+wide cube(), stacked on top of each other. This could be in z,y,z
or some other direction. Then reassemble by modulating the slices as
preferred and scale up the slice thickness slightly. Finally union() the
modulated slices.

This should preserve holes and surface shapes. Not sure if it will work
in practice, but you could try.

Carsten Arnholm

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

Ronaldo
In reply to this post by MichaelAtOz
Do you mean something like that:

module test2() {
  translate([100,0,0])
  difference(){
    cylinder(r=100,h=10,center=true);
    cylinder(r=50,h=12,center=true);
  }
}

 module slice(x,d) {
   intersection(){
     children();
     translate([x,0,0])
       cube([d,1000,1000],center=true);
   }
 }
 
 function shear_transf(x1,x2,d) = let( r=d/(x2-x1) )
    [ [1,0,0,0], [0,1,0,0], [r,0,1,-r*x1], [0,0,0,1] ];
 
 module shear(x1,x2,d) {
   multmatrix(shear_transf(x1,x2,d)) children();
 }
 
 function f(x,a,b,c) = a*x*x+b*x+c;
 
 module modulate(a,b,c,x1,x2,d){
   for(x=[x1:d:x2]) {
     translate([0,0,f(x,a,b,c)])
       shear(x,x+d,f(x+d,a,b,c)-f(x,a,b,c)) slice(x,d) children();
   }
 }
 
modulate(-0.01, 1.5, 10, 0, 200, 2) test2();
translate([0,0,-200]) test2();
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

jon_bondy
I love it!

Jon

On 3/25/2016 9:38 AM, Ronaldo wrote:

> module test2() {
>    translate([100,0,0])
>    difference(){
>      cylinder(r=100,h=10,center=true);
>      cylinder(r=50,h=12,center=true);
>    }
> }
>
>   module slice(x,d) {
>     intersection(){
>       children();
>       translate([x,0,0])
>         cube([d,1000,1000],center=true);
>     }
>   }
>  
>   function shear_transf(x1,x2,d) = let( r=d/(x2-x1) )
>      [ [1,0,0,0], [0,1,0,0], [r,0,1,-r*x1], [0,0,0,1] ];
>  
>   module shear(x1,x2,d) {
>     multmatrix(shear_transf(x1,x2,d)) children();
>   }
>  
>   function f(x,a,b,c) = a*x*x+b*x+c;
>  
>   module modulate(a,b,c,x1,x2,d){
>     for(x=[x1:d:x2]) {
>       translate([0,0,f(x,a,b,c)])
>         shear(x,x+d,f(x+d,a,b,c)-f(x,a,b,c)) slice(x,d) children();
>     }
>   }
>  
> modulate(-0.01, 1.5, 10, 0, 200, 2) test2();
> translate([0,0,-200]) test2();
>


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

runsun
In reply to this post by Ronaldo
@ Ronaldo: Very good example usage of multmatrix. Thx for sharing.
$ Runsun Pan, PhD
$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); $ Tips; $ Snippets
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

Ronaldo
In reply to this post by Ronaldo
There was a mistake in the definition of module modulate. The correct one would be:

 module modulate(a,b,c,x1,x2,dx){
   for(x=[x1:dx:x2]) {
     translate([0,0,f(x+dx/2,a,b,c)])
       shear(x,x+dx,f(x+dx,a,b,c)-f(x,a,b,c)) slice(x,dx) children();
   }
 }
 
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

rav0r
This post was updated on .
In reply to this post by cacb
It did work, I came up with this idea, but it takes days to render. Will try out Ronaldo's version.
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

Ronaldo
All depends on the complexity of your starting model and the slice width. If you could share your model we could suggest other alternatives. For instance, if your model has only vertical throughout holes, you would get a little time gain doing the differences after modulation. Anyway, please share your final solution. I am interested in it.

2016-04-04 17:09 GMT-03:00 rav0r <[hidden email]>:
It did work, I came up with this idea, but it takes days to render. Will try
out the other versions.



--
View this message in context: http://forum.openscad.org/restrict-hull-function-to-one-or-two-dimensions-tp16696p16964.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
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

rav0r
It's a frame with a grid, about 250mm long, 80 mm wide and 5 bars (longtitudinal) plus 3 cross bars. Openscad is the only application that can work without issues in regard to "full" stl's, not only facets.
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

Ronaldo
I would take a very different approach for your problem. I would "modulate" the center lines of each bar, sweep each with the bar section and union everything. A sweep module may be found in:

https://github.com/openscad/list-comprehension-demos

Take the sweep-path.scad as an example. And ask for help if you need.
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

Ronaldo
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

rav0r
In reply to this post by Ronaldo
That is easier said than done, but the frame has an irregular shape. I could, of course use this module http://www.thingiverse.com/thing:210099 for the extrusion but I need all the grid's elements to have a specific bevel and 3D orientation. I guess the whole job is harder than I thought, though, for a core 2 duo cpu. Probably an i7 would do just fine.
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

Ronaldo
Do you have an image of the frame?

2016-04-06 14:08 GMT-03:00 rav0r <[hidden email]>:
That is easier said than done, but the frame has an irregular shape. I could,
of course use this module http://www.thingiverse.com/thing:210099 for the
extrusion but I need all the grid's elements to have a specific bevel and 3D
orientation. I guess the whole job is harder than I thought, though, for a
core 2 duo cpu. Probably an i7 would do just fine.



--
View this message in context: http://forum.openscad.org/restrict-hull-function-to-one-or-two-dimensions-tp16696p16987.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
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

rav0r
Rendering Polygon Mesh using CGAL...
WARNING: CGAL Evaluator: Root node didn't fit into cache
PolySets in cache: 9
PolySet cache size in bytes: 221448
CGAL Polyhedrons in cache: 597
CGAL cache size in bytes: 104854928
   Top level object is a 3D object:
   Simple:        yes
   Vertices:   175957
   Halfedges:  529502
   Edges:      264751
   Halffacets: 191240
   Facets:      95620
   Volumes:      3420
Total rendering time: 20 hours, 48 minutes, 39 seconds
Rendering finished.

In reality, it took 3 times that much as it says.
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

Ronaldo
Well, it is a lot of rendering time indeed for an object so simple. And because of its simplicity, the slicing approach doesn't seem to be the best. Do you need a so fine slicing? You have more than 1000 slices!

What OpenSCAD version are you using? "Let" was not recognized by your version!
I am sure you would have a huge benefit from using sweep. But certainly it would not work with older versions like yours. You will need the last official version.
Would you share the code of your grid frame?

2016-04-09 11:12 GMT-03:00 rav0r <[hidden email]>:
Rendering Polygon Mesh using CGAL...
WARNING: CGAL Evaluator: Root node didn't fit into cache
PolySets in cache: 9
PolySet cache size in bytes: 221448
CGAL Polyhedrons in cache: 597
CGAL cache size in bytes: 104854928
   Top level object is a 3D object:
   Simple:        yes
   Vertices:   175957
   Halfedges:  529502
   Edges:      264751
   Halffacets: 191240
   Facets:      95620
   Volumes:      3420
Total rendering time: 20 hours, 48 minutes, 39 seconds
Rendering finished.

In reality, it took 3 times that much as it says.
<http://forum.openscad.org/file/n17004/scad.jpg>



--
View this message in context: http://forum.openscad.org/restrict-hull-function-to-one-or-two-dimensions-tp16696p17004.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
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

rav0r
//bevel

use <bevel_extrude.scad>




module grila() {
union() {
//grid
translate ([0,0,0]){
bevel_extrude(height=10,bevel_depth=6,$fn=16)import("rama_pct.dxf");
}

//horizontal
translate ([0,0,0]){
bevel_extrude(height=10,bevel_depth=6,$fn=16)import("rama_oriz_1.dxf");
}

translate ([0,0,0]){
bevel_extrude(height=10,bevel_depth=6,$fn=16)import("rama_oriz_2.dxf");
}

translate ([0,0,0]){
bevel_extrude(height=10,bevel_depth=6,$fn=16)import("rama_oriz_3.dxf");
}

translate ([0,0,0]){
bevel_extrude(height=10,bevel_depth=6,$fn=16)import("rama_oriz_4.dxf");
}

translate ([0,0,0]){
bevel_extrude(height=10,bevel_depth=6,$fn=16)import("rama_oriz_5.dxf");
}

//vertical
translate ([0,0,0]){
linear_extrude(height=3)
import("rama_vert.dxf");
}
}
}

grila();
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

Ronaldo
I can't reproduce your model without the dxf files.
Do you have images of your them?

2016-04-09 18:38 GMT-03:00 rav0r <[hidden email]>:
//bevel

use <bevel_extrude.scad>




module grila() {
union() {
//grid
translate ([0,0,0]){
bevel_extrude(height=10,bevel_depth=6,$fn=16)import("rama_pct.dxf");
}

//horizontal
translate ([0,0,0]){
bevel_extrude(height=10,bevel_depth=6,$fn=16)import("rama_oriz_1.dxf");
}

translate ([0,0,0]){
bevel_extrude(height=10,bevel_depth=6,$fn=16)import("rama_oriz_2.dxf");
}

translate ([0,0,0]){
bevel_extrude(height=10,bevel_depth=6,$fn=16)import("rama_oriz_3.dxf");
}

translate ([0,0,0]){
bevel_extrude(height=10,bevel_depth=6,$fn=16)import("rama_oriz_4.dxf");
}

translate ([0,0,0]){
bevel_extrude(height=10,bevel_depth=6,$fn=16)import("rama_oriz_5.dxf");
}

//vertical
translate ([0,0,0]){
linear_extrude(height=3)
import("rama_vert.dxf");
}
}
}

grila();



--
View this message in context: http://forum.openscad.org/restrict-hull-function-to-one-or-two-dimensions-tp16696p17014.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
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

rav0r
Reply | Threaded
Open this post in threaded view
|

Re: restrict hull function to one or two dimensions

Ronaldo
Thank you for that. I agree that my suggestion of using sweep is hard, if not impossible, to implement if your sections come from dxf files like this one. To adopt sweep you will need the 2D shapes expressed as a list of points and there is no way in the language, and this is an unfortunate missing feature of OpenSCAD, to access the points of dxf files.

If you are able to generate the list of points of your dxf files I am sure you would have a huge time gain by using sweep to get your intent. The chamfer in the bars would not be an obstacle to the sweep approach.
123