填充直线多边形矩形 [英] filling a rectilinear polygon with rectangles

查看:97
本文介绍了填充直线多边形矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个多边形,完全由矩形创建的,由点的阵列,其中该边缘总是与轴线对齐定义:

我试图确定一个快速的算法来找到一个小数目的矩形可以在这种形状填补。这是我做的手,显示矩形我所描述的集合:

编辑: 下面是一些简单的处理 code创建这种形状(当然,接近它)。

 浮法[] xpts = {0,50,50,100,100,150,150,250,250,300,300,325,325,300,300,250, 250,210,210,250,250,125,125,25,25,50,50,0};
浮[] ypts = {100,100,80,80,10,10,80,80,75,75,80,80,200,200,300,300,275,275,260,260,200,200, 270,270,165,165,125,125};


无效设置()
{
  尺寸(350,350);
}

无效的draw()
{

中风(0);
strokeWeight(1.5);

浮像素= xpts [0];
浮吡= ypts [0];
的for(int i = 1; I< xpts.length;我++)
{
  浮NX = xpts [I]
  浮NY = ypts [I]
  行(PX,PY,NX,NY);


  PX = xpts [I]
  吡啶= ypts [I];
}
浮为nx = xpts [0];
浮NY = ypts [0];

行(PX,PY,NX,NY);
}
 

解决方案

构建KD树利用现有边的分流面而忽略了完全的多边形之外的递归过程中的区域。然后,叶节点将组成一个长方形的分解。

获得了良好的分解仅仅是在递归的每一步选择哪个分流的问题。你可能会想使用一种简单的规则是减半的剩余区域的每一步。如果你愿意,你也可以只尝试一些不同的分离器!

下面是一些伪code:

 函数makeRects(矩形R,多边形P)

  如果p是空的
    如果R是你原来的多边形内
      加上R结果

  其他
    选择好分路器小号

    makeRects(相对于S R的左侧部分,相对于与s的p左侧部分)
    makeRects(相对于S R的右部,相对于标磷右部)
 

Given a polygon, created entirely from rectangles, and defined by an array of points, where the edges are always aligned with the axis:

I am trying to determine a quick algorithm to find a small number of rectangles which can fill in this shape. This is something I did by hand to show the collection of rectangles I am describing:

EDIT: Here is some simple processing code to create this shape (well, close to it).

float[] xpts = {0,    50,  50,  100, 100, 150, 150, 250, 250, 300, 300, 325, 325, 300, 300, 250, 250, 210, 210, 250, 250, 125, 125, 25, 25,   50,  50,  0 };
float[] ypts = {100, 100,  80,   80, 10,   10,  80, 80,  75,  75, 80,   80,  200, 200, 300, 300, 275, 275, 260, 260, 200, 200, 270, 270, 165, 165, 125, 125};


void setup( )
{
  size( 350, 350 );
}

void draw( )
{

stroke( 0 );
strokeWeight( 1.5 );

float px = xpts[0];
float py = ypts[0];
for (int i=1; i < xpts.length; i++)
{
  float nx = xpts[i];
  float ny = ypts[i];
  line( px, py, nx, ny );


  px = xpts[i];
  py = ypts[i];
}
float nx = xpts[0];
float ny = ypts[0];

line( px, py, nx, ny );
}

解决方案

Build a KD-Tree using existing edges as the splitter planes and ignore regions that are completely outside of the polygon during recursion. The leaf nodes will then make up a rectangular decomposition.

Getting a good decomposition is simply a matter of which splitter to choose in each step of the recursion. You might wanna use a simple heuristic that halves the remaining area each step. If you want, you can also just try a few different splitters!

Here's some pseudo code:

function makeRects(Rect r, Polygon p)

  if p is empty
    if r is inside your original polygon
      add r to results

  else
    choose good splitter s

    makeRects(left part of r relative to s, left part of p relative to s)
    makeRects(right part of r relative to s, right part of p relative to s)

这篇关于填充直线多边形矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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