Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Sierpinski Sieve/Triangle

Jesse Malthus
OMG HAX!
Join date: 21 Apr 2006
Posts: 649
07-15-2006 18:49
Hey all,
I was thinking about implementing a 3D <a href="http://mathworld.wolfram.com/SierpinskiSieve.html">Sierpinski Sieve</a> in Second Life, but I have no idea how to begin >.<
Any math geeks in the house? (I did do a 2D implementation in Java)
Thanks,
--Jesse
_____________________
Ruby loves me like Japanese Jesus.
Did Jesus ever go back and clean up those footprints he left? Beach Authority had to spend precious manpower.
Japanese Jesus, where are you?
Pragmatic!
Lumpy Tapioca
Registered User
Join date: 16 Dec 2004
Posts: 33
I saw one...
07-15-2006 18:53
There was a very large Sierpinski structure at last year's Burning Life sim. It was sort of bronze colored at very beautiful.
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
07-15-2006 19:07
You could script this, but its probably easier just to build it by hand (that's how I made one of these). Something like this works very well with shift-drag copying of prims and groups of prims.

First get a tetrahedron - there are a few ways to make one of them, explore with the cube and prism shapes. Once you've got a tetrahedron you like, you need to be able to use 4 copies to make a larger tetrahedron, having each smaller tetrahedron at one corner of the larger tetrahedron. You should end up with a tetrahedron twice the side length of the original small one, with a hole in the middle (the hole will be an octahedron). Repeat the whole process, using your larger tetrahedron as the building block.

Linking pieces before you move is a good idea, until the pieces get to be more than 255 prims. Also using the grid to position things should help, though you may need to be careful about the sizes of your tetrahedra to have this work nicely.
_____________________
-Seifert Surface
2G!tGLf 2nLt9cG
Jesse Malthus
OMG HAX!
Join date: 21 Apr 2006
Posts: 649
07-15-2006 19:20
A self-building recursive Sierpinski Sieve would be awesome, but it's begining to look more and more not worth it...
_____________________
Ruby loves me like Japanese Jesus.
Did Jesus ever go back and clean up those footprints he left? Beach Authority had to spend precious manpower.
Japanese Jesus, where are you?
Pragmatic!
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
07-16-2006 00:22
I've been building/working with equilaterals and "perfect" tetrahedrons in SL for some of my recent projects. A 3D Sierpinski structure would be kinda neat to generate. Maybe I will make one after I get some of my other projects done. :)
Nepenthes Ixchel
Broadly Offended.
Join date: 6 Dec 2005
Posts: 696
07-16-2006 07:19
From: Jesse Malthus
A self-building recursive Sierpinski Sieve would be awesome, but it's begining to look more and more not worth it...


With a six-generation sieve taking up over 4000 prims you better have a lot of land!
Jesse Malthus
OMG HAX!
Join date: 21 Apr 2006
Posts: 649
07-16-2006 11:37
From: Nepenthes Ixchel
With a six-generation sieve taking up over 4000 prims you better have a lot of land!

>.< I forgot about that. 2D sieves are managable in terms of numbers, but adding in the other dimension would kill the prim count.
_____________________
Ruby loves me like Japanese Jesus.
Did Jesus ever go back and clean up those footprints he left? Beach Authority had to spend precious manpower.
Japanese Jesus, where are you?
Pragmatic!
Patch Lamington
Blumfield SLuburban
Join date: 2 Nov 2005
Posts: 188
07-17-2006 15:12
Ed Angel's Interactive Computer Graphics has an algorithm for the gasket. Not considered the problems of transferring it into SL myself.

I have to admit I though Seifert would have used a script to build his version! Well done on doing it without.
_____________________
Blumfield - a regular everyday kind of 'burb in an irregular world.
This notice brought to you by the Blumfield Visitors and Residents Bureau.
Xixao Dannunzio
Owner, X3D Enterprises
Join date: 20 Mar 2006
Posts: 114
07-17-2006 15:19
I made one of these using a fractal script a while back. Worked nicely.
Cyclopean Sprocket
Compulsive Builder
Join date: 16 Feb 2006
Posts: 17
07-17-2006 15:37
This isn't as hard as it sounds. You start with a large equilatteral tetrahedron.

Here's some quick pseudocode to write a script and insert. Function names and parameters are approximate. This pseudocode assumes that the base is flat on the Z plane, and the forward lower edge is parallel with the Y axis.

on_rez(integer iParm)
{
if ( iParm == 0 )
return;
vector mySize = getScale()

setScale( <mysize.x/2, mysize.y/2, mysize.z/2>;);

lPos = llGetPos();
if ( iParm == 1 )
{
llSetPos( lPos + <0,0,mySize.z/4> );
}
else if ( iParm == 2 )
{
llSetPos ( lPos + < mySize.x/4, 0, -(mySize.z/4) > );
}
else if ( iParm == 3)
{
llSetPos ( lPos + < -(mySize.x/4), (mySize.y/4), -(mySize.z/4) > );
}
else
{
llSetPos ( lPos + < -(mySize.x/4), -(mySize.y/4), -(mySize.z/4) > );
}
if ( existsInInventory(llGetObjectName()) )
{
llRezObject(llGetObjectName(),<0,0,0>,<0,0,0>,1);
llRezObject(llGetObjectName(),<0,0,0>,<0,0,0>,2);
llRezObject(llGetObjectName(),<0,0,0>,<0,0,0>,3);
llRezObject(llGetObjectName(),<0,0,0>,<0,0,0>,4);
llDie();
}
}

Someone please correct me if my -4's are wrong, I don't have time to test this myself right now.

Now the fun part. Recursively place the tetrahedron into the inventory of itself for each iteration that you want the program to go through. So your parent would have a copy of itself in inventory, and that object, when rez'd would have one in ITS inventory, etc. The program stops when it reaches the bottom level object which has no copy in inventory.

Also, this isn't TERRIBLY prim intensive. Each iteration quadruples the number of prims, so the interations will go 1, 4, 16, 64, 256...

However, after five interations on a ten meter tall tetrahedron, the resulting prims will be .625 meters tall. Not microscopic, but detailed enough to make an interesting effect.
Cyclopean Sprocket
Compulsive Builder
Join date: 16 Feb 2006
Posts: 17
07-17-2006 20:29
Ok, here's the finished code. The random sleep at the beginning of the Rez is to avoid flooding the server. For every iteration over 5 you attempt, you need to quadruple that number. At some point, though, it'll stop you due to recursive rez'ing. I now have a 256 tetrahedron over my castle if you want to see it.

Visit Cyclopean Castle ( at Areumdeuli 171,198,140 )

CODE

string gNom = "Serpinski Tetrahedron";

default
{
state_entry()
{
llSay(0, "Hello, Avatar!");
}

touch_start(integer iCount)
{
llOwnerSay("Inventory has " + (string)llGetInventoryNumber(6) + " objects");
vector lPos = llGetPos();
llRezObject(gNom,lPos,ZERO_VECTOR,ZERO_ROTATION,1001);
llRezObject(gNom,lPos,ZERO_VECTOR,ZERO_ROTATION,2001);
llRezObject(gNom,lPos,ZERO_VECTOR,ZERO_ROTATION,3001);
llRezObject(gNom,lPos,ZERO_VECTOR,ZERO_ROTATION,4001);
llDie();
}


on_rez(integer iParm)
{
llSleep(llFrand(15.0));
integer lIteration = (iParm%1000);
integer lParm = (iParm - lIteration)/1000;
integer i = 0;
float lMult = 1.0;
while ( i < lIteration )
{
lMult = lMult * 2.0;
i++;
}
if ( iParm == 0 )
return;
vector mySize = llGetScale();

llSetScale( <(mySize.x/lMult), (mySize.y/lMult), (mySize.z/lMult)> );

vector lPos = llGetPos();
float lFour = 2.0 * lMult;
float lEight = 4.0 * lMult;
float lSqrtThree = 2.309 * lMult;

if ( lParm == 1 )
{
lPos = lPos + <0,0,mySize.z/lFour>;
}
else if ( lParm == 2 )
{
lPos = lPos + < mySize.x/lFour, 0, -(mySize.z/lFour) >;
}
else if ( lParm == 3)
{
lPos = lPos + < -(mySize.x/lEight), (mySize.y/lSqrtThree), -(mySize.z/lFour) >;
}
else
{
lPos = lPos + < -(mySize.x/lEight), -(mySize.y/lSqrtThree), -(mySize.z/lFour) >;
}
llSetPos(lPos);
if ( llGetInventoryNumber(6) > 0 )
{
llRezObject(gNom,lPos,ZERO_VECTOR,ZERO_ROTATION,1001 + lIteration);
llRezObject(gNom,lPos,ZERO_VECTOR,ZERO_ROTATION,2001 + lIteration);
llRezObject(gNom,lPos,ZERO_VECTOR,ZERO_ROTATION,3001 + lIteration);
llRezObject(gNom,lPos,ZERO_VECTOR,ZERO_ROTATION,4001 + lIteration);
llDie();
}
}

}