查找边界框内的所有点

时间:2013-11-29 23:05:43

标签: java algorithm

我一直在网上搜索大约一天,我似乎无法找到一个算法来查找边界框内的所有点。

照片:

准确度也需要8位十进制数。

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

2 个答案:

答案 0 :(得分:1)

我不知道在框内找到所有点究竟是什么意思。有太多了!

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

在您的示例中调用标识符需要$ 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 
     }   

我希望它有所帮助。

答案 1 :(得分:0)

    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 + ")");
        }
    }

需要一段时间

相关问题