Bellaard.com

Sierpinski Dodecahedron

By: Gijs Bellaard

Sierpinski Dodecahedron

Description

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

GLSL Code


//The golden ratio
const float PHI = 1.61803398875;

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

//The scaling factor between iterations
const float SCALE = 1. + PHI;

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

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

    for(int i=0; i<ITERATIONS; i++){   
        //Folds
        p -= 2.*min(0.,dot(p,N1))*N1; 
        p -= 2.*min(0.,dot(p,N2))*N2; 
        p -= 2.*min(0.,dot(p,N3))*N3; 
        p -= 2.*min(0.,dot(p,N2))*N2;
        p -= 2.*min(0.,dot(p,N1))*N1;
        p -= 2.*min(0.,dot(p,N2))*N2;
        p -= 2.*min(0.,dot(p,N3))*N3; 
        
        //Scaling
        p   *= SCALE;
        s   *= SCALE;
        
        //Offset
        p -= 1.;
    }
    
    //Distance to a dodecahedron
    float d = distanceDodecahedron(p);
    
    return d/s; 
}