# Object positioning algorithm

Good afternoon.
It is necessary to place the models when loading next to the already loaded models. The first model should be loaded in the center of the plane, and the rest should be located next to it.
Also, they should not overlap each other.
Can someone share an example of how this can be implemented?
Or thoughts in which direction to move

There is an example of how this is done in Cura, but I don’t understand python

I don’t have an example, and I don’t have the time to write some. Generally, my suggestion would be the following:

• when placing a model, take its bounding box and try to fit it – this will make computations much easier, at the cost of leaving some gaps (I hope you do not need compact and perfect arrangement)
• having this done, the problem is reduced to placing rectangles in a plane – there are several algorithms for this, collectively they are called “2D nesting algorithms”
• option 1: find some existing JS library that implements such algorithm
• option 2: implement by yourself one of the 2D nesting algorithms (this might be hard to do)
• option 3: implement some naive form of nesting, which will be fine if you do not have too many objects. One naive approach is this: split the plane into squares. Each object occupies several full squares (i.e. no objects share the same square). When you place an object, find a place with enough free squares. After placing the object mark its squares as occupied.
• option 4: put all objects in groups depending on their size. Arrange objects from each group into a grid adjusted to their size.
• option 5: use physics engine, put the models in a sparse grid, make horizontal gravitation force, and the objects will pack “automatically”
1 Like

just use something like this with the models bounding box projections on the ground

5 Likes

(I gave it a test drive)

3 Likes

Thanks, bro. I’ve sketched out a very simple option for loading stl models with subsequent positioning. Perhaps you will have the time and desire to watch.

You won’t need anything except the nest2DArrange function here.
If I load models of the same size, then there are no problems, but if they are different, then overlap begins. An example is shown in the screenshot.