discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

making a sierpinski with OpenSCAD

A
Anto
Sat, Jun 27, 2015 11:00 AM

I am just learning OpenSCAD, i want to make a sierpinski with spheres in the void spaces, so i tried to run a sierpinki script and it crashed due to error on the first line... 
from openscad import *from math import sqrt, pow, sin, cos

numbers of iterations to recurse, you don't need manyiterations = 5 [....]

it doesnt seem backwards compatible? what programs can run .scad files?

I am just learning OpenSCAD, i want to make a sierpinski with spheres in the void spaces, so i tried to run a sierpinki script and it crashed due to error on the first line...  from openscad import *from math import sqrt, pow, sin, cos # numbers of iterations to recurse, you don't need manyiterations = 5 [....] it doesnt seem backwards compatible? what programs can run .scad files?
TP
Torsten Paul
Sat, Jun 27, 2015 11:46 AM

On 06/27/2015 01:00 PM, Anto wrote:

I am just learning OpenSCAD, i want to make a sierpinski with
spheres in the void spaces, so i tried to run a sierpinki script
and it crashed due to error on the first line...

from openscad import *
from math import sqrt, pow, sin, cos

numbers of iterations to recurse, you don't need many

iterations = 5
[....]

it doesnt seem backwards compatible? what programs can run .scad files?

This is no OpenSCAD script. From the syntax it looks like some
python wrapper (maybe https://github.com/kevinmehall/pyscad ?).
But there are lots of python related project, so it's hard to tell
which one it actually is.

Maybe have a look at http://www.thingiverse.com/thing:187131
which has the scad script attached.

ciao,
Torsten.

On 06/27/2015 01:00 PM, Anto wrote: > I am just learning OpenSCAD, i want to make a sierpinski with > spheres in the void spaces, so i tried to run a sierpinki script > and it crashed due to error on the first line... > > from openscad import * > from math import sqrt, pow, sin, cos > > # numbers of iterations to recurse, you don't need many > iterations = 5 > [....] > > it doesnt seem backwards compatible? what programs can run .scad files? > This is no OpenSCAD script. From the syntax it looks like some python wrapper (maybe https://github.com/kevinmehall/pyscad ?). But there are lots of python related project, so it's hard to tell which one it actually is. Maybe have a look at http://www.thingiverse.com/thing:187131 which has the scad script attached. ciao, Torsten.
A
Anto
Sat, Jun 27, 2015 12:56 PM

Thanks Torsten, there are quite alot of error codes on Thingiverse. 
I have managed the sierpinski with spheres, some of the sizes are wrong, here it is:
TETRA_POINTS = [    [1/sqrt(3), 0, -sqrt(2/3).33],    [-1/(2sqrt(3)), 1/2, -sqrt(2/3).33],    [-1/(2sqrt(3)), -1/2, -sqrt(2/3).33],    [0, 0, sqrt(2/3).66]];
TETRA_POINTS2 = [    [1/sqrt(3), 0, 0],    [-1/(2sqrt(3)), 1/2, 0],    [-1/(2sqrt(3)), -1/2, 0],    [0, 0, sqrt(2/3)],    [0, 0, sqrt(2/3).5]];
module tetra() {    polyhedron(        points=TETRA_POINTS,        triangles=[            [0, 1, 2],            [2, 1, 3],            [0, 2, 3],            [0, 3, 1]    ]);}
module siervoids(n, overscale=0.2) {    if (n == 0) {        //scale(.3)        //cube();    } else {        for (pt = TETRA_POINTS) {            scale(n
n*.041)            sphere(r=5);            translate(pow(2, n - 1) * pt)            siervoids(n - 1);        }    }}
module sier(n, overscale=0.2) {    if (n == 0) {        scale(1 + overscale)        tetra();    } else {        for (pt = TETRA_POINTS) {            translate(pow(2, n - 1) * pt)            sier(n - 1);        }    }}siervoids(6);sier(6);
From: Torsten Paul Torsten.Paul@gmx.de
To: discuss@lists.openscad.org
Sent: Saturday, June 27, 2015 1:46 PM
Subject: Re: [OpenSCAD] making a sierpinski with OpenSCAD

On 06/27/2015 01:00 PM, Anto wrote:

I am just learning OpenSCAD, i want to make a sierpinski with
spheres in the void spaces, so i tried to run a sierpinki script
and it crashed due to error on the first line...

from openscad import *
from math import sqrt, pow, sin, cos

numbers of iterations to recurse, you don't need many

iterations = 5
[....]

it doesnt seem backwards compatible? what programs can run .scad files?

This is no OpenSCAD script. From the syntax it looks like some
python wrapper (maybe https://github.com/kevinmehall/pyscad ?).
But there are lots of python related project, so it's hard to tell
which one it actually is.

Maybe have a look at http://www.thingiverse.com/thing:187131
which has the scad script attached.

ciao,
  Torsten.


OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

Thanks Torsten, there are quite alot of error codes on Thingiverse.  I have managed the sierpinski with spheres, some of the sizes are wrong, here it is: TETRA_POINTS = [    [1/sqrt(3), 0, -sqrt(2/3)*.33],    [-1/(2*sqrt(3)), 1/2, -sqrt(2/3)*.33],    [-1/(2*sqrt(3)), -1/2, -sqrt(2/3)*.33],    [0, 0, sqrt(2/3)*.66]]; TETRA_POINTS2 = [    [1/sqrt(3), 0, 0],    [-1/(2*sqrt(3)), 1/2, 0],    [-1/(2*sqrt(3)), -1/2, 0],    [0, 0, sqrt(2/3)],    [0, 0, sqrt(2/3)*.5]]; module tetra() {    polyhedron(        points=TETRA_POINTS,        triangles=[            [0, 1, 2],            [2, 1, 3],            [0, 2, 3],            [0, 3, 1]    ]);} module siervoids(n, overscale=0.2) {    if (n == 0) {        //scale(.3)        //cube();    } else {        for (pt = TETRA_POINTS) {            scale(n*n*.041)            sphere(r=5);            translate(pow(2, n - 1) * pt)            siervoids(n - 1);        }    }} module sier(n, overscale=0.2) {    if (n == 0) {        scale(1 + overscale)        tetra();    } else {        for (pt = TETRA_POINTS) {            translate(pow(2, n - 1) * pt)            sier(n - 1);        }    }}siervoids(6);sier(6); From: Torsten Paul <Torsten.Paul@gmx.de> To: discuss@lists.openscad.org Sent: Saturday, June 27, 2015 1:46 PM Subject: Re: [OpenSCAD] making a sierpinski with OpenSCAD On 06/27/2015 01:00 PM, Anto wrote: > I am just learning OpenSCAD, i want to make a sierpinski with > spheres in the void spaces, so i tried to run a sierpinki script > and it crashed due to error on the first line... > > from openscad import * > from math import sqrt, pow, sin, cos > > # numbers of iterations to recurse, you don't need many > iterations = 5 > [....] > > it doesnt seem backwards compatible? what programs can run .scad files? > This is no OpenSCAD script. From the syntax it looks like some python wrapper (maybe https://github.com/kevinmehall/pyscad ?). But there are lots of python related project, so it's hard to tell which one it actually is. Maybe have a look at http://www.thingiverse.com/thing:187131 which has the scad script attached. ciao,   Torsten. _______________________________________________ OpenSCAD mailing list Discuss@lists.openscad.org http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
N
Neon22
Wed, Jul 1, 2015 8:05 AM

Working pretty well but its adhoc nature is starting to defeat you.
There are many alg for creating these and you have chosen one where the
triangles grow from the center out. You have oversized the geo so there is
overlap for your physical model.

  • Note that the oversized factor in sier never works unless you make only a
    single triangle.
    Actually it looks like it was from thingiverse...

Another approach would be to use a non recursive routine. This will be
easier to control the oversize for overlaps.
Another approach would be to have the first triangle become the largest
encompassing triangle then every level beings to subtract the geo from the
prior models. OpenSCAD is good at this.

Check out some online algorithms for creation. Your initial foray was
finding a python program. These can be easy to read and a good source of
info. There are many pages on Sierpinski algorithms online.

Remember the volume of a triangle and volume of a sphere are calculated
differently and this factor difference is what you need to get the right
size for spheres.
Try starting with a more normalised pyramid. The math might be easier.

--
View this message in context: http://forum.openscad.org/making-a-sierpinski-with-OpenSCAD-tp12932p12967.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

Working pretty well but its adhoc nature is starting to defeat you. There are many alg for creating these and you have chosen one where the triangles grow from the center out. You have oversized the geo so there is overlap for your physical model. - Note that the oversized factor in sier never works unless you make only a single triangle. Actually it looks like it was from thingiverse... Another approach would be to use a non recursive routine. This will be easier to control the oversize for overlaps. Another approach would be to have the first triangle become the largest encompassing triangle then every level beings to subtract the geo from the prior models. OpenSCAD is good at this. Check out some online algorithms for creation. Your initial foray was finding a python program. These can be easy to read and a good source of info. There are many pages on Sierpinski algorithms online. Remember the volume of a triangle and volume of a sphere are calculated differently and this factor difference is what you need to get the right size for spheres. Try starting with a more normalised pyramid. The math might be easier. -- View this message in context: http://forum.openscad.org/making-a-sierpinski-with-OpenSCAD-tp12932p12967.html Sent from the OpenSCAD mailing list archive at Nabble.com.