Giter Site home page Giter Site logo

sharp3dbinpacking's Introduction

3D bin packing algorithms

NuGet Codacy Badge

Bin packing problem.

This library is translated from https://github.com/krris/3d-bin-packing.

Example

The coordinates are defined as:

       o--------o
      /|       /|
     / |      / |
  h o--------o  |
  e |  o-----|--o h
y i | /      | / t
  g |/       |/ p z
  h o--------o e
  t | width   d
    |  x
 (0, 0, 0)

Example code:

// Define the size of bin
var binWidth = 1000;
var binHeight = 1000;
var binDepth = 1000;

// Define the cuboids to pack
var parameter = new BinPackParameter(binWidth, binHeight, binDepth, new[]
{
	new Cuboid(150, 100, 150),
	new Cuboid(500, 500, 500),
	new Cuboid(500, 550, 700),
	new Cuboid(350, 350, 350),
	new Cuboid(650, 750, 850),
});

// Create a bin packer instance
// The default bin packer will test all algorithms and try to find the best result
// BinPackerVerifyOption is used to avoid bugs, it will check whether the result is correct
var binPacker = BinPacker.GetDefault(BinPackerVerifyOption.BestOnly);

// The result contains bins which contains packed cuboids whith their coordinates
var result = binPacker.Pack(parameter);
foreach (var bins in result.BestResult)
{
	Console.WriteLine("Bin:");
	foreach (var cuboid in bins)
	{
		Console.WriteLine(cuboid);
	}
}

Outputs:

Bin:
Cuboid(X: 0, Y: 0, Z:0, Width: 750, Height:850, Depth:650, Weight: 0, Tag: )
Cuboid(X: 0, Y: 0, Z:650, Width: 350, Height:350, Depth:350, Weight: 0, Tag: )
Cuboid(X: 750, Y: 0, Z:0, Width: 150, Height:150, Depth:100, Weight: 0, Tag: )
Bin:
Cuboid(X: 0, Y: 0, Z:0, Width: 700, Height:500, Depth:550, Weight: 0, Tag: )
Cuboid(X: 0, Y: 500, Z:0, Width: 500, Height:500, Depth:500, Weight: 0, Tag: )

License

MIT License
Copyright © 2018 303248153@github
If you have any license issue please contact [email protected].

sharp3dbinpacking's People

Contributors

dudes-come avatar 303248153 avatar arastookhajehee avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.