Density/Price Calculation

Discussion in 'ShapeJS' started by AlanHudson, Dec 30, 2013.

  1. AlanHudson
    AlanHudson Shapeways Employee Dev Team
    I needed to get the density of an object recently. The script contains a few things I thought useful to share.

    One is the importPackage command. This exposes more of the packages in AbFab3D to the javascript. We're still deciding if we should expose all of them or just let users import them. In this example I'm exposing the grid package. I do this so I can get the VoxelClasses class. I then use this to call findCount(Grid,VoxelClasses.INSIDE) on the grid. This tallies the total number of filled voxels in the grid. Knowing the width/height/depth in voxels of the grid you can use that to find the density of the object.

    You can also use this to calculate the rough price of an object. We know WSF costs $1.40 + $1.50 per CM^3 at today's prices. We can take the number of filled voxels * voxelSize / 100 to get CM^3. This will be a rough price. Since we are turning voxels into triangles the final price will be different but this gives you an idea of the price of the object(and an idea of how much more accurate it will be when you communicate voxels instead of triangles!).

    importPackage(Packages.abfab3d.grid);

    function main(args) {
    var voxelSize = 0.1*MM;
    var grid = createGrid(-16*MM,16*MM,-16*MM,16*MM,-16*MM,16*MM,voxelSize) ;
    var box = new Box(1,1,1);
    var intersect = new Intersection();
    intersect.add(new VolumePatterns.Gyroid(10*MM, 0.75*MM));
    var maker = new GridMaker();
    maker.setSource(intersect);
    maker.makeGrid(grid);

    var voxels = grid.getWidth() * grid.getHeight() * grid.getDepth();
    var filled = grid.findCount(Grid.VoxelClasses.INSIDE);
    var volumeCM3 = filled * voxelSize / 100;

    print("Voxels: " + voxels);
    print("Filled: " + filled);
    print("Density: " + filled / voxels);
    print("VolumeCM^3: " + volumeCM3);
    print("WSF Price: " + (1.50 + 1.40 * volumeCM3));

    return grid;
    }
     
    Last edited: Dec 30, 2013
  2. stannum
    stannum Well-Known Member
    Bug! Handling fee 1.50. Per cm3 1.40.
     
  3. AlanHudson
    AlanHudson Shapeways Employee Dev Team
    Oops, you right. Post updated, thanks!