Sierpinski Tetrahedron Generator

Discuss stuff not about Indigo.
User avatar
matsta
Posts: 730
Joined: Mon Jan 29, 2007 7:50 am
Location: 127.0.0.1

Sierpinski Tetrahedron Generator

Post by matsta » Wed Sep 12, 2007 6:56 am

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
Attachments
im1189534930.png
im1189534930.png (928.41 KiB) Viewed 6401 times
Last edited by matsta on Wed Sep 12, 2007 8:02 am, edited 2 times in total.

User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Wed Sep 12, 2007 7:01 am

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....)

User avatar
matsta
Posts: 730
Joined: Mon Jan 29, 2007 7:50 am
Location: 127.0.0.1

Post by matsta » Wed Sep 12, 2007 7:04 am

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

User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Wed Sep 12, 2007 7:06 am

:D cool - will be computing heavy, then, though^^ (Ram expensive and such) - damn, I also need such friends^^

User avatar
CoolColJ
Posts: 1738
Joined: Mon Jun 25, 2007 1:47 pm

Post by CoolColJ » Wed Sep 12, 2007 10:45 am

just the thing for Alien stuff ala Stargate ;)

User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Wed Sep 12, 2007 11:41 pm

this fractal is in use in all the internal-antenna-mobile phones, btw :D (the 2D version of it, at least)

IanC
Posts: 147
Joined: Thu Aug 24, 2006 4:46 am

Post by IanC » Fri Sep 14, 2007 2:29 am

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)

User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Fri Sep 14, 2007 2:35 am

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...

IanC
Posts: 147
Joined: Thu Aug 24, 2006 4:46 am

Post by IanC » Fri Sep 14, 2007 3:02 am

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

User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Fri Sep 14, 2007 3:29 am

ah, ok, I see^^
so, about the absolute maximum is 8 - 9 should be quite unhandleable^^

IanC
Posts: 147
Joined: Thu Aug 24, 2006 4:46 am

Post by IanC » Fri Sep 14, 2007 3:39 am

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.

User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Fri Sep 14, 2007 5:12 am

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^^)

IanC
Posts: 147
Joined: Thu Aug 24, 2006 4:46 am

Post by IanC » Fri Sep 14, 2007 7:03 am

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 :)

User avatar
Kram1032
Posts: 6649
Joined: Tue Jan 23, 2007 3:55 am
Location: Austria near Vienna

Post by Kram1032 » Fri Sep 14, 2007 7:16 am

would be soooo cool :D
I made quite some fractals y hand, now^^

IanC
Posts: 147
Joined: Thu Aug 24, 2006 4:46 am

Post by IanC » Fri Sep 14, 2007 9:44 am

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.

Post Reply
16 posts

Who is online

Users browsing this forum: No registered users and 41 guests