简体   繁体   English

确定矩形(x,y)坐标的算法,以便周围矩形的面积最小?

[英]Algorithm to determine (x,y) coordinates for rectangles so the area of the surrounding rectangle is minimal?

I hope my title makes sense, but here is what I a trying to do: 我希望我的标题有意义,但这是我想要做的:

I have n rectangles, each with widths of W n and heights of H n that I need to arrange so on a two dimensional (x,y) plane the rectangle that they all fit in takes up the least area. 我有n矩形,每个都有宽度为W n ,高度为H n我需要在二维(x,y)平面上排列,它们都适合的矩形占据的面积最小。 I also need to be able to establish what (x,y) corresponds to what rectangle. 我还需要能够确定(x,y)对应于什么矩形。

I would prefer something in psuedo-code, but can work with many languages. 我更喜欢psuedo-code中的某些东西,但可以使用多种语言。

Thanks for helping. 谢谢你的帮助。

This is a difficult problem to be solved optimally, however there are some solutions that are not too hard to implement and that represent a good approximations for many uses (eg for textures). 这是一个要以最佳方式解决的难题,但是有一些解决方案并不太难实现,并且代表了许多用途(例如纹理)的良好近似。 Try googling for "rect(angle) packing" ... you will find a lot of code that solves the problem. 尝试谷歌搜索“矩形(角度)包装”...你会发现很多代码解决了这个问题。

Sounds NP-complete to me. 对我来说听起来很完整。 Kinda like the knapsack problem. 有点像背包问题。 Which means there is no real solution. 这意味着没有真正的解决方案。 Only good approximations. 只有很好的近似值。

It's a variant on 2D bin packing. 它是2D纸盒包装的变种。 The fact that your container is flexible, allows for more optimization as well making it more challenging (as in difficult). 您的容器灵活,允许更多优化,使其更具挑战性(如困难)。 Drools Planner (open source java) can handle this. Drools Planner (开源java)可以处理这个问题。 At least one implementation (see user mailing list) with Drools Planner exists (not open source). 存在至少一个带有Drools Planner的实现(请参阅用户邮件列表)(非开源)。 If you need an open source example to start from, probably the cloud balance in drools-planner-examples is a good example to start from. 如果您需要一个开源示例,那么drools-planner-examples中的云平衡可能就是一个很好的例子。

For an overview of the algorithms you can use, see my answer on a similar question . 有关可以使用的算法的概述,请参阅我对类似问题的回答

Your problem is known as the 2D packing problem. 您的问题被称为2D包装问题。 Even the 1D problem is NP-hard. 即使是一维问题也是NP难题。 See here for a good article on some approaches along with sample C# code. 请参阅此处以获取有关某些方法的优秀文章以及示例C#代码。

Also, see the following questions: 另外,请参阅以下问题:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Math / Algorithm / JS:给定每个矩形的TopLeft(x0,y0)和Bottom-Right(x1,y1),如何确定2个以上的矩形是否相交 - Math/ Algorithm/ JS: How to determine if 2+ rectangles intersect, given the TopLeft(x0, y0) and Bottom-Right(x1, y1) of each rectangle 算法从坐标确定矩形 - algorithm to determine a rectangle from coordinates 算法 - 给定所有其他矩形的 x 和 y 轴,找到足够的空间来绘制矩形 - Algorithm - locating enough space to draw a rectangle given the x and y axis of all other rectangles 返回优化的 x 坐标以标准化/最大化具有定义 y 位置的矩形阵列的区域 - Return Optimized x coordinates to normalize/maximize area for an array of rectangles with defined y positions 确定矩形是否完全被另一组矩形覆盖所需的算法 - Algorithm required to determine if a rectangle is completely covered by another set of rectangles 给出实数 x 和 y。 我们需要判断坐标为(x;y)的点是否属于阴影区域 - Real numbers x and y are given. We need to determine whether or not a point with coordinates (x; y) belong to the shaded area 如何确定百万数据点中的哪些点 (x,y) 位于矩形 (x1, x2, y1, y2) 所描述的区域内? - How to determine which points (x,y) out of million data points lie inside the area described by a rectangle (x1, x2, y1, y2)? 用于消除最小数量的矩形的算法 - Algorithm to dins minimal number of rectangles 确定某事物的x和y以便遵循2个关键帧之间的曲线的算法是什么? - what is the algorithm to determine x and y for something so that it follows a curve between 2 keyframes? 确定 x/y 网格索引的算法 - Algorithm to determine index of x/y grid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM