[OpenSCAD] Minkowski sum slowness

nop head nop.head at gmail.com
Tue Mar 22 23:52:53 CET 2011


All the examples with the sphere give a runtime error on my system (WinXP).

On 22 March 2011 21:42, Giles Bathgate <giles.bathgate at gmail.com> wrote:

> I have been doing some further investigation regarding minkowski sum
> slowness.
>
> My hypothesis was that openscad spheres have much more facets than
> neccecery
> to prove my hypothesis I created a sphere in terms of simpler
> primitives e.g. circle, and
> rotate_extrude
>
>   module halfcircle(r) {
>     difference() {
>       circle(r);
>       translate([-r,0])square([r*2,r]);
>     }
>   }
>
>   module sphere_alternate(r) {
>     rotate_extrude()
>       rotate([0,0,90])halfcircle(r);
>   }
>
>   $fn=20;
>   minkowski() {
>      cube([20,20,30]);
>      sphere_alternate(5);
>   }
>
> I then compiled this script:
>
> Parsing design (AST generation)...
> Compiling design (CSG Tree generation)...
> Compilation finished.
> Compiling design (CSG Products generation)...
> Processing uncached minkowski statement...
> ..rendering time: 0 hours, 0 minutes, 59 seconds
> Compiling design (CSG Products normalization)...
> CSG generation finished.
> Total rendering time: 0 hours, 1 minutes, 0 seconds
>
> With comparison to the standard sphere script:
>
>   $fn=20;
>   minkowski() {
>      cube([20,20,30]);
>      sphere(5);
>   }
>
> You can see this is about twice as slow:
>
> Parsing design (AST generation)...
> Compiling design (CSG Tree generation)...
> Compilation finished.
> Compiling design (CSG Products generation)...
> Processing uncached minkowski statement...
> ..rendering time: 0 hours, 2 minutes, 26 seconds
> Compiling design (CSG Products normalization)...
> CSG generation finished.
> Total rendering time: 0 hours, 2 minutes, 27 seconds
>
> Looking at the primitives.cc code for the built-in sphere you can see
> that the reason for this is that the number of fragments is calculated
> on a per ring basis. What it means is that when viewed from above
> (with $fn set to 10 for example) you can see that the sphere's
> projection (or outermost ring) is a 10 sided circle, however when
> viewed from the front the sphere projection has many more sides.
>
> I experimented with setting the number of fragments identical for
> every ring in the sphere, and setting the number of rings to half the
> number of fragments this gives a "symmetrical sphere", in that it
> looks the same when viewed from any direction
>
> I have pushed a patch for this to
> http://gitorious.org/openscad/openscad/commits/sphere-cylinder-optimisation
>
> After this patch is applied with the default settings (i.e. $fn not
> set) the sphere has a much better appearance imho.
>
> More interestingly the same script as in the original post is about
> twice the speed.
>
> $fn=50;
>
> minkowski()
> {
>  cube([10,10,1]);
>  sphere(r=2,h=1);
> }
>
> Parsing design (AST generation)...
> Compiling design (CSG Tree generation)...
> Compilation finished.
> Compiling design (CSG Products generation)...
> Processing uncached minkowski statement...
> ..rendering time: 0 hours, 8 minutes, 54 seconds
> Compiling design (CSG Products normalization)...
> CSG generation finished.
> Total rendering time: 0 hours, 8 minutes, 54 seconds
> _______________________________________________
> OpenSCAD mailing list
> OpenSCAD at rocklinux.org
> http://rocklinux.net/mailman/listinfo/openscad
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rocklinux.net/pipermail/openscad/attachments/20110322/fbc81aa6/attachment.html


More information about the OpenSCAD mailing list