0

I'm building a solution to fit a number of objects most efficiently into a box. I hope to implement more efficient algorithms soon, but to start out with I'm going to use the brute force method, checking every possible position. This is fine for now since the box is small, with a very few number of items. Later, the complexity will grow.

I'm using Unity to allow the user to see how the items ultimately fit in the box. My initial thought was to also use Unity's physics and collision detection to implement the best fit algorithm; but, with a huge potential number of locations and positions to check, is this a bad approach? Am I much better off running my algorithm in a data structure instead? A 10x10x10 box with even three 1x1x1 objects have almost a billion possible positions...

I'm new to Unity so any advice is welcome; thanks!

Update: right, so this problem is definitely in the bin-packing set of problems, which I know is NP hard. I'm assuming a rectangular box, filled with rectangular box-shaped items of random dimensions.

My question is...

My question is: given my particular algorithm, when we ask, "is there currently something in this x,y,z space?" would it be more efficient to figure that out via code, or to use Unity objects with collision-detection.

Based on the answers I've seen, I can see using Unity would be profoundly inefficient.

Community
  • 1
  • 1
Trever
  • 13
  • 5
  • No, dont use physics for that. I strongly recomend not to use it. It will just kill performance. – Jerry Switalski Mar 22 '16 at 19:51
  • Absolutely do not use unity's physics for this, it just not intended for this amount of precision or number of collisions. Fake as much of the calculation as you can (eg assumptions about the box being Axis-Aligned, or objects being able to fit in a similarly sized shape will help), so you ideally won't have to use the physics engine at all. – Happy Apple Mar 22 '16 at 21:55
  • As everyone has told you, this has utterly no connection to PhysX. – Fattie Mar 23 '16 at 13:32
  • Note that "box packing" is sort of the relevant software/academic term here. (Not to be confused with "space filling" which I accidentally typed before, which is totally unrelated - sorry about that.) – Fattie Mar 23 '16 at 14:28
  • Yessir - see my update in the original post. Thanks for your input. – Trever Apr 05 '16 at 19:05
  • 1
    Ah, been too long since I've used this site. I gave your answer an upvote but didn't click the checkmark. Done! – Trever Apr 08 '16 at 16:39

1 Answers1

2

If you LITERALLY want to know:

"is there currently something in this x,y,z space?"

the best possible way to do that, is to simply use Unity's engine. So, you trivially check the AABB to see if a point is inside it (or perhaps just check for intersection). You can use one of many

I understand that the question "is there currently something in this x,y,z space?" is or could be one important part of whatever solution you are planning. And indeed the best way to do that is to let Unity's engine do that. It's absolutely impossible you or I could write anything as efficient -- to begin with it comes right off the quaternion cloud in the GPU.

That is the actual answer to what you have now stated is your specific question.

Now regarding the more general issue, which I first fully explained when that was the question you were asking :)


Here are some of my thoughts on trivial "box packing" algorithms in 2D, at the level useful in video games.

https://stackoverflow.com/a/35228592/294884

Regarding 3D "box packing" it's absolutely impossible to offer any guidance unless you include a screen shot of what you are trying to do and fully explain the shapes and constraints involved.

If you are a matheatician and looking for the latest in algorithmic thinking on the matter, just google something like "3d box packing algorithm"

example , example

enter image description here

Again, readers here have utterly no clue what shapes/etc you are dealing with, so please click Edit and explain!

Note too that sphere packing is a really fascinating scientific problem, if that's what you are talking about:

https://en.wikipedia.org/wiki/Close-packing_of_equal_spheres

Community
  • 1
  • 1
Fattie
  • 27,874
  • 70
  • 431
  • 719