Java源码示例:org.apache.commons.math3.geometry.euclidean.twod.hull.MonotoneChain

示例1
public static ConvexHull2D getConvexHull(Matrix matrix) throws IOException {
  double[][] data = matrix.getData();
  List<Vector2D> points = new ArrayList<>(data.length);
  if(data[0].length == 2) {
    for(double[] row : data) {
      points.add(new Vector2D(row[0], row[1]));
    }

    MonotoneChain monotoneChain = new MonotoneChain();
    ConvexHull2D convexHull2D = monotoneChain.generate(points);
    return convexHull2D;
  } else {
    throw new IOException("The convexHull function operates on a matrix of 2D vectors");
  }
}