• Icosahedron.js

  • ¶

    Icosahedron geometry generator. Based on http://paulbourke.net/geometry/platonic/

  • ¶

    Parent class : geom.Geometry

  • ¶

    Example use

     var g = new Icosahedron(0.5);
     var mesh = new Mesh(g, new materials.SolidColor());
    
    var geom = require('pex-geom');
    var Vec3 = geom.Vec3;
    var Geometry = geom.Geometry;
  • ¶

    Icosahedron ( r )

    r - radius { Number = 0.5 }

    function Icosahedron(r) {
      r = r || 0.5;
    
      var phi = (1 + Math.sqrt(5)) / 2;
      var a = 1 / 2;
      var b = 1 / (2 * phi);
    
      var vertices = [
        new Vec3(  0,  b, -a),
        new Vec3(  b,  a,  0),
        new Vec3( -b,  a,  0),
        new Vec3(  0,  b,  a),
        new Vec3(  0, -b,  a),
        new Vec3( -a,  0,  b),
        new Vec3(  a,  0,  b),
        new Vec3(  0, -b, -a),
        new Vec3(  a,  0, -b),
        new Vec3( -a,  0, -b),
        new Vec3(  b, -a,  0),
        new Vec3( -b, -a,  0)
      ];
    
      vertices = vertices.map(function(v) { return v.normalize().scale(r); })
    
      var faces = [
        [  1,  0,  2 ],
        [  2,  3,  1 ],
        [  4,  3,  5 ],
        [  6,  3,  4 ],
        [  7,  0,  8 ],
        [  9,  0,  7 ],
        [ 10,  4, 11 ],
        [ 11,  7, 10 ],
        [  5,  2,  9 ],
        [  9, 11,  5 ],
        [  8,  1,  6 ],
        [  6, 10,  8 ],
        [  5,  3,  2 ],
        [  1,  3,  6 ],
        [  2,  0,  9 ],
        [  8,  0,  1 ],
        [  9,  7, 11 ],
        [ 10,  7,  8 ],
        [ 11,  4,  5 ],
        [  6,  4, 10 ]
      ];
    
      var edges = [
        [ 0,  1 ],
        [ 0,  2 ],
        [ 0,  7 ],
        [ 0,  8 ],
        [ 0,  9 ],
        [ 1,  2 ],
        [ 1,  3 ],
        [ 1,  6 ],
        [ 1,  8 ],
        [ 2,  3 ],
        [ 2,  5 ],
        [ 2,  9 ],
        [ 3,  4 ],
        [ 3,  5 ],
        [ 3,  6 ],
        [ 4,  5 ],
        [ 4,  6 ],
        [ 4, 10 ],
        [ 4, 11 ],
        [ 5,  9 ],
        [ 5, 11 ],
        [ 6,  8 ],
        [ 6, 10 ],
        [ 7,  8 ],
        [ 7,  9 ],
        [ 7, 10 ],
        [ 7, 11 ],
        [ 8, 10 ],
        [ 9, 11 ],
        [10, 11 ]
      ];
    
      Geometry.call(this, { vertices: vertices, faces: faces, edges: edges });
    }
    
    Icosahedron.prototype = Object.create(Geometry.prototype);
    
    module.exports = Icosahedron;