Search Unity

Tricky Math/Geometry question

Discussion in 'Scripting' started by aubergine, May 28, 2015.

  1. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    Untitled-1.jpg
    According to the above image;

    There is one big rectangle(borders) and there are the small ones. All the width and lengths are variable and may change.
    Question is; how can i calculate how many from each small rectangle i can fit inside the big rectanglewithout overlapping and with the most efficient way?
    EDIT: Most efficient way means leaving the smallest unused empty space inside big rectangle AND using the biggest tiles possible.

    Any help is appreciated.
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    If it's me, and I'm doing what I'm pretty sure you're doing, I use the Sprite Packer to do all the work for me ;)

    This is a non-trivial problem, and there's no magic bullet. AFAIK most solutions consist of placing the biggest one in a corner, then placing the next biggest nestled in a corner near it in different positions until it fits, and so on down the line.
     
  3. aubergine

    aubergine

    Joined:
    Sep 12, 2009
    Posts:
    2,880
    I dont know what sprite packer is, but i am sure it is slightly different than what i require.
    My problem is very smiliar to Cutting stock problem as the data(rectangles) and canvas are all variables and canvas should not be enlarged like you would pack textures (i.e. lightmapping). Further more, data might be 3D in some cases. Too bad i dont understand the formula there :(
     
  4. ThermalFusion

    ThermalFusion

    Joined:
    May 1, 2011
    Posts:
    906