【问题标题】:Finding all points withing a bounding box查找边界框内的所有点
【发布时间】:2013-11-29 23:05:43
【问题描述】:

我已经在互联网上搜索了大约一天,但我似乎无法找到一种算法来查找边界框中的所有点。

图片:

精度也需要8位小数。

示例: (0,0) (0,0.00000001) (0,0.00000002) 等等.. (80,80.45356433)

【问题讨论】:

  • 问题到底是什么?您可以在任何精度级别上迭代所有点。
  • 你想做什么?也许这是实现您想要的另一种方式?
  • 就像 Simeon Visser 所说的那样。使用边界框遍历所有点
  • 到目前为止你有什么?你想在屏幕上打印点还是写入文件?
  • 这些角在什么样的坐标系中?我试着计算那里有多少“点”,粒度为 1 亿 ppu,但我无法计算出宽度和高度。

标签: java algorithm


【解决方案1】:

我不知道你说的找到一个盒子里的所有点到底是什么意思。实在是太多了!

我建议使用 Identifier 函数,即,给定一个点 (x, y),当且仅当点 (x, y) 在内部时,I(x, y) = 1你的盒子。

在您的示例中调用标识符需要 $4$ 比较。

    public class Box {
          /**
           * Identifier function.
           * @param x  x-coordinate of input point
           * @param y  y-coordinate of input point
           * @return True if and only if the given point is inside the box.
           */
          public boolean IsInside(double x, double y) {
              return (this.x_min <= x) && (this.x_max >= x) &&
                     (this.y_max >= y) && (this.y_min <= y);
           }
          double x_min, x_max, y_min, y_max; // or do it with left top width and height 
     }   

希望对你有帮助。

【讨论】:

    【解决方案2】:
        long p = (long)Math.pow(10, 8);
        long start = 90 * p;
        long end = 180 * p;
        for (long i = start; i < end; i++) {
            for (long j = start; j < end; j++) {
                System.out.println("(" + (double)i / p + "," + (double)j / p + ")");
            }
        }
    

    需要一段时间

    【讨论】:

    • 不要使用双精度数,最好使用长整数——这样会更快更精确
    猜你喜欢
    • 2022-01-10
    • 2014-02-08
    • 2023-02-01
    • 2016-10-12
    • 2015-01-18
    • 2016-12-21
    • 2017-07-10
    • 2013-06-03
    • 1970-01-01
    相关资源
    最近更新 更多