Created
November 28, 2013 16:05
-
-
Save christianp/7694200 to your computer and use it in GitHub Desktop.
ShapeJS script to create a Herschel enneahedron. Use with http://shapejs.shapeways.com/creator/. One argument: height scaling factor.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function herschel(h1,size) { | |
var h2 = h1*4/3; | |
var root3 = Math.sqrt(3); | |
var vertices = [ | |
[1/2,0,-h1], | |
[0,0,0], | |
[1/2,0,h1], | |
[1,0,0], | |
[1/2, root3/6,-h2], | |
[1/4,root3/4,-h1], | |
[1/4,root3/4,h1], | |
[1/2,root3/6,h2], | |
[3/4,root3/4,h1], | |
[3/4,root3/4,-h1], | |
[1/2,root3/2,0] | |
]; | |
vertices = vertices.map(function(v) { | |
return new Vector3d((v[0]-0.5)*size,(v[1]-root3/6)*size,v[2]*size); | |
}); | |
var faces = [ | |
[1,7,2], | |
[1,10,6], | |
[6,8,7], | |
[5,9,10], | |
[10,3,8], | |
[2,7,8], | |
[1,4,5], | |
[4,0,3], | |
[1,3,0] | |
]; | |
faces = faces.map(function(f) { | |
return new Plane(vertices[f[0]],vertices[f[2]],vertices[f[1]]); | |
}); | |
var int = new Intersection(faces[0],faces[1]); | |
for(var i=2;i<faces.length;i++) { | |
int.add(faces[i]); | |
} | |
return int; | |
} | |
function main(args) { | |
var grid = createGrid(-16*MM,16*MM,-16*MM,16*MM,-16*MM,16*MM,0.1*MM); | |
var shape = herschel(args[0],15*MM); | |
var maker = new GridMaker(); | |
maker.setSource(shape); | |
maker.makeGrid(grid); | |
return grid; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment