计算相邻矩形的数量 [英] count the number of adjacent rectangles

查看:234
本文介绍了计算相邻矩形的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码在二维空间中在[0,1]范围内打印一组(X,Y)坐标。

My code prints a sets of (X,Y) coordinates in 2D space in the range [0,1].

void Rect_Print() {
    cout << "In counter-clockwise fashion" << endl;
    cout << "#Rectangle    (   x0,   y0)   (   x1,   y1) " << endl;

    for (int b=0; b<Rect_Count; b++) {
       double Area = (Rect[b].x0 - Rect[b].x1) * (Rect[b].y0 - Rect[b].y1);

       cout << fixed << setprecision(4) << (b+1) <<
               "  (" << Rect[b].x0 << "," << Rect[b].y0 <<
             ")   (" << Rect[b].x1 << "," << Rect[b].y1 << ")" << endl;
    }

    cout << "Number of divisions (N = 3j-2) = " << Rect_Count << endl;
}

这些点在(3j-2)子矩形中划分单位正方形(不均匀)。

These points divide a unit square in a (3j-2) sub-rectangles (not uniform). For each of the specific rectangle, I would like to count the total number of rectangle adjacent to it.


  1. 假设第一个坐标将单位正方形划分为四个矩形,如:

  1. Suppose the first coordinate divide the unit square into four rectangles like:

在此图片中可以看到,

In this picture you can see, there are three rectangles adjacent with rectangle-3.

如果我这样做,在我的第六步后,单位方块分成19个矩形。所以它看起来像:

If I proceed that way, after my sixth step the unit square divide into 19 rectangles. So it's look like:

现在矩形3旁边有五个矩形

假设我有一组 >万个坐标,并将它们细分为小的子矩形。我想使用c ++来计算每个相邻的矩形的数量。我该怎么办?

Suppose I have a sets of ten thousand coordinate and they sub-divide the square into small sub-rectangles. I would like to use c++ to count the number of rectangles adjacent to each of them. How can I do it?

在互联网上搜索后,似乎Flann可能会帮助我做这个伎俩。我读了用户手册,但不知道我该怎么做。

After searching on Internet it seems the Flann may help me to do the trick. I read the user manual but could not understand how can I do that.

任何人都可以帮助我吗?

Can anyone help me?

推荐答案

您可以查找r树或kd树。树图算法的工作原理类似。一个好的开始是对框进行排序,并将它们放在树中,通过递归分割它在2轴,并查看下一个框适合。

You can look for a r-tree or kd-tree. The treemap algorithm works similar. A good start is to sort the boxes and put them in the tree by recursively split it at the 2 axis and look where the next box fits.

这篇关于计算相邻矩形的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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