Sierpinski Icosahedron

By: Gijs Bellaard

Sierpinski Icosahedron


The Sierpinski icosahedron is made by repeatedly replacing the 12 corners of all the icosahedron with half-sized icosahedron.


//The golden ratio
const float PHI = 1.61803398875;

//The amount of iterations
const int ITERATIONS = 15;

//The scaling factor between iterations
const float SCALE = 2.;

//Fold normals
const vec3 N1 = normalize(vec3(PHI, 1.0-PHI, -1.0    ));
const vec3 N2 = normalize(vec3(1.0, PHI    , -PHI-1.0));

const vec3 O = vec3(-0.850650787,-0.525731087,0);

float distanceSierpinskiIcosahedron(vec3 p){
    float s = 1.;

    for(int i=0; i<ITERATIONS; i++){   
        z = abs(z);      
        z -= 2.*min(0.,dot(z,N1))*N1; 
        z -= 2.*min(0.,dot(z,N2))*N2; 
        z *= SCALE;
        s *= SCALE;
        z += O;
    //Distance to a icosahedron
    float d = distanceIcosahedron(p);
    return d/s;