Dodecahedron

Following examples show one way to create a parametric Dodecahedron shape.

function build() {

    let edgeLength = 10; // params.edgeLength;

    return dodecahedron(edgeLength);
}

function dodecahedron(edgeLength){

    

    const Vertex = cadlib.Vertex;
    const Edge = cadlib.Edge;
    const Face = cadlib.Face;
    const Wire = cadlib.Wire;
    
    const gr = (1+Math.sqrt(5))/2; //golden ratio
    
    const rcp = 1/gr;   //reciprocal of golden ratio
    
    let hollowIt = false; // params.hollowIt - hollowIt is of type boolean
 
    //Create dodecahedron with edgelength 2/gr to scale
    
    //Create vertices
    let vyzRect1 = new Vertex(0, -rcp, -gr);
    let vyzRect2 = new Vertex(0, rcp, -gr);
    let vyzRect3 = new Vertex(0, rcp, gr);
    let vyzRect4 = new Vertex(0, -rcp, gr);
    let vxzRect1 = new Vertex(gr, 0, rcp);
    let vxzRect2 = new Vertex(gr, 0, -rcp);
    let vxzRect3 = new Vertex(-gr, 0, -rcp);
    let vxzRect4 = new Vertex(-gr, 0, rcp);
    let vxyRect1 = new Vertex(rcp, -gr, 0);
    let vxyRect2 = new Vertex(rcp, gr, 0);
    let vxyRect3 = new Vertex(-rcp, gr, 0);
    let vxyRect4 = new Vertex(-rcp, -gr, 0);
    let vCubeTop1 = new Vertex(1, 1, 1);
    let vCubeTop2 = new Vertex(1, 1, -1);
    let vCubeTop3 = new Vertex(-1, 1, -1);
    let vCubeTop4 = new Vertex(-1, 1, 1);
    let vCubeBot1 = new Vertex(1, -1, 1);
    let vCubeBot2 = new Vertex(1, -1, -1);
    let vCubeBot3 = new Vertex(-1, -1, -1);
    let vCubeBot4 = new Vertex(-1, -1, 1);
 
    //create edges
    let exyTop = new Edge().createLine(vxyRect2, vxyRect3);
    let eToptoCube1 = new Edge().createLine(vxyRect2, vCubeTop1);
    let eToptoCube2 = new Edge().createLine(vxyRect2, vCubeTop2);
    let eToptoCube3 = new Edge().createLine(vxyRect3, vCubeTop3);
    let eToptoCube4 = new Edge().createLine(vxyRect3, vCubeTop4);
    let eTopCubetoyz1 = new Edge().createLine(vCubeTop1, vyzRect3);
    let eTopCubetoyz2 = new Edge().createLine(vCubeTop2, vyzRect2);
    let eTopCubetoyz3 = new Edge().createLine(vCubeTop3, vyzRect2);
    let eTopCubetoyz4 = new Edge().createLine(vCubeTop4, vyzRect3);
 
    let exzRight = new Edge().createLine(vxzRect1, vxzRect2);
    let exzLeft = new Edge().createLine(vxzRect3, vxzRect4);
    let eTopCubetoxz1 = new Edge().createLine(vCubeTop1, vxzRect1);
    let eTopCubetoxz2 = new Edge().createLine(vCubeTop2, vxzRect2);
    let eTopCubetoxz3 = new Edge().createLine(vCubeTop3, vxzRect3);
    let eTopCubetoxz4 = new Edge().createLine(vCubeTop4, vxzRect4);
 
    let exyBot = new Edge().createLine(vxyRect4, vxyRect1);
    let eBotCubetoxz1 = new Edge().createLine(vCubeBot1, vxzRect1);
    let eBotCubetoxz2 = new Edge().createLine(vCubeBot2, vxzRect2);
    let eBotCubetoxz3 = new Edge().createLine(vCubeBot3, vxzRect3);
    let eBotCubetoxz4 = new Edge().createLine(vCubeBot4, vxzRect4);
    let eBotCubetoyz1 = new Edge().createLine(vCubeBot1, vyzRect4);
    let eBotCubetoyz2 = new Edge().createLine(vCubeBot2, vyzRect1);
    let eBotCubetoyz3 = new Edge().createLine(vCubeBot3, vyzRect1);
    let eBotCubetoyz4 = new Edge().createLine(vCubeBot4, vyzRect4);
    let eyzBack = new Edge().createLine(vyzRect1, vyzRect2);
    let eyzFront = new Edge().createLine(vyzRect3, vyzRect4);
 
    let eBotCubetoxy1 = new Edge().createLine(vxyRect1, vCubeBot1);
    let eBotCubetoxy2 = new Edge().createLine(vxyRect1, vCubeBot2);
    let eBotCubetoxy3 = new Edge().createLine(vxyRect4, vCubeBot3);
    let eBotCubetoxy4 = new Edge().createLine(vxyRect4, vCubeBot4); 
    //create faces
    let fTopFront = new Face([new Wire([exyTop, eToptoCube4, eTopCubetoyz4, eTopCubetoyz1, eToptoCube1])]);
    let fTopBack = new Face([new Wire([exyTop, eToptoCube2, eTopCubetoyz2, eTopCubetoyz3, eToptoCube3])]);
    let fTopRight = new Face([new Wire([eToptoCube1, eTopCubetoxz1, exzRight, eTopCubetoxz2, eToptoCube2])]);
    let fTopLeft = new Face([new Wire([eToptoCube3, eTopCubetoxz3, exzLeft, eTopCubetoxz4, eToptoCube4])]);
    let fMidBackRight = new Face([new Wire([eTopCubetoxz2, eBotCubetoxz2, eBotCubetoyz2, eyzBack, eTopCubetoyz2])]);
    let fMidBackLeft = new Face([new Wire([eyzBack, eBotCubetoyz3, eBotCubetoxz3, eTopCubetoxz3, eTopCubetoyz3])]);
    let fMidFrontLeft = new Face([new Wire([eyzFront, eTopCubetoyz4, eTopCubetoxz4, eBotCubetoxz4, eBotCubetoyz4])]);
    let fMidFrontRight = new Face([new Wire([eyzFront, eBotCubetoyz1, eBotCubetoxz1, eTopCubetoxz1, eTopCubetoyz1])]);
    let fBotFront = new Face([new Wire([exyBot, eBotCubetoxy1, eBotCubetoyz1, eBotCubetoyz4, eBotCubetoxy4])]);
    let fBotBack = new Face([new Wire([exyBot, eBotCubetoxy2, eBotCubetoyz2, eBotCubetoyz3, eBotCubetoxy3])]);
    let fBotLeft = new Face([new Wire([exzLeft, eBotCubetoxz3, eBotCubetoxy3, eBotCubetoxy4, eBotCubetoxz4])]);
    let fBotRight = new Face([new Wire([exzRight, eBotCubetoxz1, eBotCubetoxy1, eBotCubetoxy2, eBotCubetoxz2])]);
 
    //create shell and solid
    let shell = cadlib.makeShell([fTopFront, fTopBack, fTopRight, fTopLeft, fMidBackRight, fMidBackLeft, fMidFrontLeft, fMidFrontRight, fBotBack, fBotLeft, fBotRight, fBotFront]);
    let solid = cadlib.makeSolidFromShells([shell]);
    solid = cadlib.fixShape(solid);
 
    //scale solid to parameter edge length
    var scFactor = edgeLength/(2/gr);
    solid = cadlib.scale(solid, scFactor, {x:0, y:0, z:0});
    if (hollowIt) {
	    return cadlib.hollow(solid, 0.5);
    }
    else
        return solid;
 
}