我有一个ArrayList
个2D点。如何使用java?
ArrayList
点是:
[277.0,275.0,269.0,271.0,260.0,268.0,184.0,277.0,160.0,288.0,137.0,303.0,115.0,319.0,97.0,337.0,80.0,357.0,67.0,375.0,59.0,394.0,55.0, 413.0,53.0,433.0,55.0,456.0,59.0,482.0,66.0,507.0,77.0,534.0,90.0,558.0,103.0,578.0,117.0,594.0,131.0,607.0,147.0,616.0,163.0,622.0,179.0,624.0, 198.0,623.0,221.0,618.0,244.0,608.0,266.0,595.0,284.0,581.0,300.0,565.0,360.0,548.0,329.0,530.0,339.0,511.0,348.0,493.0,350.0,473.0,361.0,454.0,364.0, 436.0,367.0,420.0,368.0,403.0,367.0,388.0,366.0,371.0,360.0,338.0,356.0,330.0,349.0,309.0,343.0,298.0,337.0,289.0,329.0,283.0,320.0,280.0,309.0,281.0, 299.0,282.0,299.0,282.0,277.0,275.0]
答案 0 :(得分:0)
在列表中查找最小和最大x和y坐标。您的边界框将具有以下角落:
(x min ,y min ),(x min ,y max ),(x max ,y max ),(x max ,y min )
答案 1 :(得分:0)
你以一种糟糕的方式解释了你的问题。我必须猜测你的积分有哪种类型。不过,您可以使用Java Api中的Rectangle2D
类。有关详细信息,请单击here。
关于某些点的边界框的一般想法是:
计算每个维度的所有点的最大值和最小值并保存。您的边界框由具有坐标值的点组成。对于2D情况,这将是以下四点:
(xmin,ymin),(xmin,ymax),(xmax,ymax),(xmax,ymin)。
代码片段:
// Constructs a new Rectangle whose upper-left corner is
// specified by the Point argument, and whose width and
// height are specified by the Dimension argument.
Rectangle2D rect = new Rectangle(new Point(3, 4), new Dimension(200, 200));
// For a Rectangle with double Coordinates
Rectangle2D floatRect = new Rectangle2D.Double(3.0, 4.0, width, height);