var geom = require('pex-geom');
var Vec3 = geom.Vec3;
var Geometry = geom.Geometry;
Octahedron geometry generator. Based on http://paulbourke.net/geometry/platonic/
var geom = require('pex-geom');
var Vec3 = geom.Vec3;
var Geometry = geom.Geometry;
function Octahedron(r) {
r = r || 0.5;
var a = 1 / (2 * Math.sqrt(2));
var b = 1 / 2;
var s3 = Math.sqrt(3);
var s6 = Math.sqrt(6);
var vertices = [
new Vec3(-a, 0, a), //front left
new Vec3( a, 0, a), //front right
new Vec3( a, 0,-a), //back right
new Vec3(-a, 0,-a), //back left
new Vec3( 0, b, 0), //top
new Vec3( 0,-b, 0) //bottom
];
vertices = vertices.map(function(v) { return v.normalize().scale(r); })
var faces = [
[3, 0, 4],
[2, 3, 4],
[1, 2, 4],
[0, 1, 4],
[3, 2, 5],
[0, 3, 5],
[2, 1, 5],
[1, 0, 5]
];
var edges = [
[0, 1],
[1, 2],
[2, 3],
[3, 0],
[0, 4],
[1, 4],
[2, 4],
[3, 4],
[0, 5],
[1, 5],
[2, 5],
[3, 5]
];
Geometry.call(this, { vertices: vertices, faces: faces, edges: edges });
}
Octahedron.prototype = Object.create(Geometry.prototype);
module.exports = Octahedron;