1. <legend id='OEbF2'><style id='OEbF2'><dir id='OEbF2'><q id='OEbF2'></q></dir></style></legend>

    <tfoot id='OEbF2'></tfoot>

      <bdo id='OEbF2'></bdo><ul id='OEbF2'></ul>

    1. <i id='OEbF2'><tr id='OEbF2'><dt id='OEbF2'><q id='OEbF2'><span id='OEbF2'><b id='OEbF2'><form id='OEbF2'><ins id='OEbF2'></ins><ul id='OEbF2'></ul><sub id='OEbF2'></sub></form><legend id='OEbF2'></legend><bdo id='OEbF2'><pre id='OEbF2'><center id='OEbF2'></center></pre></bdo></b><th id='OEbF2'></th></span></q></dt></tr></i><div id='OEbF2'><tfoot id='OEbF2'></tfoot><dl id='OEbF2'><fieldset id='OEbF2'></fieldset></dl></div>

      <small id='OEbF2'></small><noframes id='OEbF2'>

      非重叠矩形中的命中测试算法

      Algorithm for hit test in non-overlapping rectangles(非重叠矩形中的命中测试算法)
        <tbody id='7BsMi'></tbody>
      <tfoot id='7BsMi'></tfoot>

    2. <i id='7BsMi'><tr id='7BsMi'><dt id='7BsMi'><q id='7BsMi'><span id='7BsMi'><b id='7BsMi'><form id='7BsMi'><ins id='7BsMi'></ins><ul id='7BsMi'></ul><sub id='7BsMi'></sub></form><legend id='7BsMi'></legend><bdo id='7BsMi'><pre id='7BsMi'><center id='7BsMi'></center></pre></bdo></b><th id='7BsMi'></th></span></q></dt></tr></i><div id='7BsMi'><tfoot id='7BsMi'></tfoot><dl id='7BsMi'><fieldset id='7BsMi'></fieldset></dl></div>
    3. <small id='7BsMi'></small><noframes id='7BsMi'>

          <legend id='7BsMi'><style id='7BsMi'><dir id='7BsMi'><q id='7BsMi'></q></dir></style></legend>

              <bdo id='7BsMi'></bdo><ul id='7BsMi'></ul>

              1. 本文介绍了非重叠矩形中的命中测试算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一组不重叠的矩形,它们覆盖了一个封闭的矩形.找到鼠标单击的包含矩形的最佳方法是什么?

                I have a collection of non-overlapping rectangles that cover an enclosing rectangle. What is the best way to find the containing rectangle for a mouse click?

                显而易见的答案是有一个矩形数组并按顺序搜索它们,使得搜索 O(n).有没有办法按位置对它们进行排序,使算法小于 O(n),比如 O(log n) 或 O(sqrt(n))?

                The obvious answer is to have an array of rectangles and to search them in sequence, making the search O(n). Is there some way to order them by position so that the algorithm is less than O(n), say, O(log n) or O(sqrt(n))?

                推荐答案

                您可以将矩形组织成四边形或 kd-tree.这给了你 O(log n).这是主流的方法.

                You can organize your rectangles in a quad or kd-tree. That gives you O(log n). That's the mainstream method.

                这个问题的另一个有趣的数据结构是 R-trees.如果您必须处理大量矩形,这些会非常有效.

                Another interesting data-structure for this problem are R-trees. These can be very efficient if you have to deal with lots of rectangles.

                http://en.wikipedia.org/wiki/R-tree

                然后是 O(1) 方法,只需生成与屏幕大小相同的位图,用无矩形"的占位符填充它,然后将命中矩形索引绘制到该位图中.查找变得如此简单:

                And then there is the O(1) method of simply generating a bitmap at the same size as your screen, fill it with a place-holder for "no rectangle" and draw the hit-rectangle indices into that bitmap. A lookup becomes as simple as:

                  int id = bitmap_getpixel (mouse.x, mouse.y)
                  if (id != -1)
                  {
                    hit_rectange (id);
                  }
                  else
                  {
                    no_hit();
                  }
                

                显然,只有当您的矩形不经常更改并且您可以为位图腾出内存时,该方法才有效.

                Obviously that method only works well if your rectangles don't change that often and if you can spare the memory for the bitmap.

                这篇关于非重叠矩形中的命中测试算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                How to store delegates in a List(如何将代表存储在列表中)
                How delegates work (in the background)?(代表如何工作(在后台)?)
                Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                Func Delegate vs Function(函数委托与函数)
                CreateDelegate with unknown types(具有未知类型的 CreateDelegate)
                  <tbody id='QnhTg'></tbody>

                1. <i id='QnhTg'><tr id='QnhTg'><dt id='QnhTg'><q id='QnhTg'><span id='QnhTg'><b id='QnhTg'><form id='QnhTg'><ins id='QnhTg'></ins><ul id='QnhTg'></ul><sub id='QnhTg'></sub></form><legend id='QnhTg'></legend><bdo id='QnhTg'><pre id='QnhTg'><center id='QnhTg'></center></pre></bdo></b><th id='QnhTg'></th></span></q></dt></tr></i><div id='QnhTg'><tfoot id='QnhTg'></tfoot><dl id='QnhTg'><fieldset id='QnhTg'></fieldset></dl></div>
                2. <legend id='QnhTg'><style id='QnhTg'><dir id='QnhTg'><q id='QnhTg'></q></dir></style></legend>

                3. <tfoot id='QnhTg'></tfoot>

                      <small id='QnhTg'></small><noframes id='QnhTg'>

                        <bdo id='QnhTg'></bdo><ul id='QnhTg'></ul>