2d-bin-packing算法在x,y位置放置一个矩形? [英] 2d-bin-packing Algorithm to place a rectangle in x,y location?

查看:664
本文介绍了2d-bin-packing算法在x,y位置放置一个矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在canvas中实现了2d-bin-packing算法。我的任务是将矩形放置在画布上的最佳位置。

I am implementing 2d-bin-packing algorithm in canvas. My task is to place rectangles as optimal as it can be on a canvas.

以下显示如何操作:
http://incise.org/2d-bin-packing-with-javascript-and-canvas .html

但是,它从原点开始。我想告诉算法在哪里放置一个矩形,而下一个不在他的上面。

BUT, it starts with the origin. I would like to tell the algorithm where to put a rectangle and that the next one not to be on top of him.

代码中应该更改什么?

是否有其他算法可供使用?

Is there another algorithm to use for it?

推荐答案

我知道一个更好的算法(在紧凑性方面,而不是速度方面)比你链接的算法称为MaxRects。

I know a better algorithm(in terms of compactness, not speed) than the one you linked to is called MaxRects.

这是我用C ++实现的。虽然速度不快,但在紧凑包装方面非常有效。

This was my implementation of it in C++. While not fast, it was very effective at packing compactly.

这是一个pdf,讨论和比较各种算法的时间和紧凑性。

This is a pdf discussing and comparing all sorts of algorithms in terms of both time and compactness.

编辑:

我把使用MaxRects打包的图片示例放在一起。

I threw together an example of an image packed using MaxRects .

这篇关于2d-bin-packing算法在x,y位置放置一个矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆