【问题标题】:Extracting the Silhouettes Coordinates提取轮廓坐标
【发布时间】:2015-07-16 03:40:04
【问题描述】:

从我在那里发布的图像中,我将图 C 中这些矩形的所有坐标保存在 Figure 类的数组中。

图:

public abstract class Figure {

    private int left, right, height;
    protected Coordinates[] coords;

    public Figure() {

    }

    public Figure(int left, int right, int height, Coordinates[] coords) {

        this.left = left;
        this.right = right;
        this.height = height;
        this.coords = coords;
    }

    public int getRight() {
        return right;
    }

    public int getLeft() {
        return left;
    }

    public int getHeight() {
        return height;
    }

    public Coordinates[] getCoords() {
        return coords;
    }

    public abstract void setCoordinates();

    public abstract void showCoordinates();
}

坐标:

public class Coordinates {

    private float x, y;

    public Coordinates() {

    }

    public Coordinates(float x, float y) {
        this.x = x;
        this.y = y;
    }

    public float getX() {
        return x;
    }

    public float getY() {
        return y;
    }
}

问题是,我必须使用已经提到的数组中的坐标从整个图中找到轮廓的坐标,就像它在图 D (see the image) 中的方式一样。

示例(参见图片参考):

 1st Rectangle Coordinates are: (1,0)(1,11)(5,11)(5,0)
 2nd Rectangle Coordinates are: (2,0)(2,6)(7,6)(7,0)
 3rd Rectangle Coordinates are: (3,0)(3,13)(9,13)(9,0)
 4th Rectangle Coordinates are: (12,0)(12,7)(16,7)(7,0)
 5th Rectangle Coordinates are: (14,0)(14,3)(25,3)(25,0)
 6th Rectangle Coordinates are: (19,0)(19,18)(22,18)(22,0)
 7th Rectangle Coordinates are: (23,0)(23,13)(29,13)(29,0)
 8th Rectangle Coordinates are: (24,0)(24,4)(28,4)(28,0)


 The Coordinates of the Silhouettes from all those rectangles should be:
 (1,11)(3,13)(9,0)(12,7)(16,3)(19,18)(22,3)(23,13)(29,0)
 This is where I'm stuck thinking how I'll get these coordinates.

我不是要求别人为我做这件事或类似的事情,我只是想从哪里开始,因为到目前为止我尝试过的所有方法都失败了,所以任何提示或想法都会派上用场!非常感谢你!晚安。

【问题讨论】:

    标签: java coordinates rectangles


    【解决方案1】:

    您似乎正在尝试获取每个重叠矩形簇的并集。 Java 的java.awt.geom.Rectangle 类有一个createUnion(Rectangle2D) 方法,可以将第二个矩形“吸收”到第一个矩形中(通过“联合”)。但是,这并不能解决您的聚类问题。

    如果您尝试处理的矩形数量相对较少,并且只需要在一维(即水平)上进行聚类,那么最直接的方法是保留尚未处理过的矩形列表聚类,遍历每个非聚类矩形,将第一个矩形移除到它自己的新“聚类”中,然后与所有其他非聚类矩形执行相交以确定该对是否应该聚类。 java.awt.geom.Rectangle2D.intersects(Rectangle) 方法非常适合这种情况。如果它们相交,则相交的矩形应从未聚类矩形列表中删除并添加到当前聚类中。

    Rectangle2D 类与您的坐标存储不太匹配,但映射将相当简单。

    一旦你有了你的集群矩形集,你仍然需要找到每个多边形的路径,它限制了给定集群中的所有矩形。如果您的示例图片指示所有矩形,使得它们的底边都处于相同的“高度”并且您的矩形都没有不同的旋转,这将容易得多。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-24
      • 2017-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-24
      相关资源
      最近更新 更多