Page 1 of 2

Sierpinski Tetrahedron Generator

Posted: Wed Sep 12, 2007 6:56 am
by matsta
hey guys

just asked a friend of mine thomas (lyc.deviantart.com) to build me an app that creates sierpinski tetrahedrons and exports them in .obj format. can be quite useful and can be used to make some pretty cool stuff. here is an image i made quick as an example ;) once again. very nifty! Hope u like

http://www.fractographer.com/binaries/tetra_sierp.zip

greetz
mat

Posted: Wed Sep 12, 2007 7:01 am
by Kram1032
I want to see far more depth :D - looks great as a start :) (but I could build that - with far more patience - in blender, as well....)

Posted: Wed Sep 12, 2007 7:04 am
by matsta
o btw kram ;) tom just asked me to say it takes the recursion level as a commandline parameter. :D

so yea. depth to the max ;)

greetz

Posted: Wed Sep 12, 2007 7:06 am
by Kram1032
:D cool - will be computing heavy, then, though^^ (Ram expensive and such) - damn, I also need such friends^^

Posted: Wed Sep 12, 2007 10:45 am
by CoolColJ
just the thing for Alien stuff ala Stargate ;)

Posted: Wed Sep 12, 2007 11:41 pm
by Kram1032
this fractal is in use in all the internal-antenna-mobile phones, btw :D (the 2D version of it, at least)

Posted: Fri Sep 14, 2007 2:29 am
by IanC
Nice :)

I wrote one for blender for a comp a while back
http://blenderartists.org/forum/showpos ... ostcount=3

Heres the code if anyone wants it, makes a range of different level gaskets.

Code: Select all

import Blender
from Blender import Mesh,Scene
scn=Scene.GetCurrent()
def generate(location, scale, level, currentVerts,currentFaces):
    height=2.
    x,y,z=location
    newVerts,newFaces=[],[]
    if level:
        scale/=2.0
        generate(location,scale,level-1,currentVerts,currentFaces)
        generate([x-scale,y-scale,z-scale*height],scale,level-1,currentVerts,currentFaces)
        generate([x+scale,y-scale,z-scale*height],scale,level-1,currentVerts,currentFaces)
        generate([x-scale,y+scale,z-scale*height],scale,level-1,currentVerts,currentFaces)
        generate([x+scale,y+scale,z-scale*height],scale,level-1,currentVerts,currentFaces)    
    else:
        start=len(currentVerts)
        currentVerts.extend([[x,y,z],\
        [x-scale,y-scale,z-scale*height],\
        [x+scale,y-scale,z-scale*height],\
        [x+scale,y+scale,z-scale*height],\
        [x-scale,y+scale,z-scale*height]])
        currentFaces.extend([[start,start+1,start+2],\
        [start,start+2,start+3],\
        [start,start+3,start+4],\
        [start,start+1,start+4],\
        [start+1,start+2,start+3,start+4]])
    return [currentVerts,currentFaces]
for i in range(6):
    v,f=generate([0,0,2],1,i,[],[])
    level=Mesh.New(str(i)+'level')
    level.verts.extend(v)
    level.faces.extend(f)
    ob=scn.objects.new(level,'gasket'+str(i))
Modified to just make one

Code: Select all

import Blender
from Blender import Mesh,Scene

################
# Level of gasket wanted
i=6
# warning: try 5/6 first, it's quite dense already.
################

scn=Scene.GetCurrent()
def generate(location, scale, level, currentVerts,currentFaces):
    height=2.
    x,y,z=location
    newVerts,newFaces=[],[]
    if level:
        scale/=2.0
        generate(location,scale,level-1,currentVerts,currentFaces)
        generate([x-scale,y-scale,z-scale*height],scale,level-1,currentVerts,currentFaces)
        generate([x+scale,y-scale,z-scale*height],scale,level-1,currentVerts,currentFaces)
        generate([x-scale,y+scale,z-scale*height],scale,level-1,currentVerts,currentFaces)
        generate([x+scale,y+scale,z-scale*height],scale,level-1,currentVerts,currentFaces)    
    else:
        start=len(currentVerts)
        currentVerts.extend([[x,y,z],\
        [x-scale,y-scale,z-scale*height],\
        [x+scale,y-scale,z-scale*height],\
        [x+scale,y+scale,z-scale*height],\
        [x-scale,y+scale,z-scale*height]])
        currentFaces.extend([[start,start+1,start+2],\
        [start,start+2,start+3],\
        [start,start+3,start+4],\
        [start,start+1,start+4],\
        [start+1,start+2,start+3,start+4]])
    return [currentVerts,currentFaces]


v,f=generate([0,0,2],1,i,[],[])
level=Mesh.New(str(i)+'level')
level.verts.extend(v)
level.faces.extend(f)
ob=scn.objects.new(level,'gasket'+str(i))
Kram, it's not too heavy, Takes under a second for a level 6, a few seconds for a level 7 (level 7 = 390k faces). (amd64 3000)

Posted: Fri Sep 14, 2007 2:35 am
by Kram1032
yeah....
7 = 4^7 faces= 16384 --- not too much
10 = 4^10 = 1.048.576 - that's quite impressive, already, I'd say...

that's the calc, if level 1 = a simple tetrahedron... if that's lvl 0, it's 4^8 bzw 4^11... I wonder, how you come on your face counts...

Posted: Fri Sep 14, 2007 3:02 am
by IanC
Kram, that's not quite right for mine.

Mine isn't a serpinski tetrahedron one, it's a serpinski gasket based on a square based pyramid. I only just clicked that the OP was different, I just didn't think, sorry.

So mine is 5 faces each, and 5 objects. :)

Mine goes from level 0 as a pyramid.

So,

Code: Select all

level - faces
0 - 5
1 - 25
2 - 125
3 - 625
4 - 3,125
5 - 15,625
6 - 78,125
7 - 390,625
8 - 1,953,125
9 - 9,765,625
10 - 48,828,125
11 - 244,140,625
12 - 1,220,703,125
13 - 6,103,515,625
14 - 30,517,578,125
15 - 152,587,890,625

Which is why I warn against high levels :D

Posted: Fri Sep 14, 2007 3:29 am
by Kram1032
ah, ok, I see^^
so, about the absolute maximum is 8 - 9 should be quite unhandleable^^

Posted: Fri Sep 14, 2007 3:39 am
by IanC
Yeah. Most I've ever worked with in blender is about 3 mill, and that was with the sculpting tools, not a recursive python prog.

7 is surprisingly dense though, hitting the point where you have to start to zoom in to see the smallest pyramids.

Posted: Fri Sep 14, 2007 5:12 am
by Kram1032
so, 7 is just perfect, I guess^^ - I tried to model the cube version of that... MUCH more polys needed :S - I got to 3 steps, then, it's simply too slow + too much work^^ (no script - handmade^^)

Posted: Fri Sep 14, 2007 7:03 am
by IanC
It's the 'goldilocks' number :)

Handmade versions? You madman!

I did think about writing a general version, so you could make your own. Maybe if I get some time, but I'm working :)

Posted: Fri Sep 14, 2007 7:16 am
by Kram1032
would be soooo cool :D
I made quite some fractals y hand, now^^

Posted: Fri Sep 14, 2007 9:44 am
by IanC
It's not hard to write, it's just a more general case of my code.

Take my code and replace the hard coded shape by reading in an object from the scene, and have a group of objects showing the replacement rule (so to get what my code does normally, you'd make a square based pyramid, and then place several of those into a level 1 version).

To be honest, I spend 8-10 hours coding a day (then more if I decide to work on anything of my own projects) so unless something really grabs me I tend not to work on it.