【发布时间】:2020-08-20 14:06:15
【问题描述】:
我正在研究 ConvexHull 问题,我需要识别凸包的顶点。我正在使用 Apache commons-math's - ConvexHull2D。这是我到目前为止所拥有的
public static void main(String[] args) {
Vector2D v1 = new Vector2D(1, 3);
Vector2D v2 = new Vector2D(-1, 3);
Vector2D v3 = new Vector2D(0, -2);
Vector2D v4 = new Vector2D(-1, -3);
Vector2D v5 = new Vector2D(-12, -13);
Vector2D v6 = new Vector2D(-10, -30);
Vector2D[] vertices = {v1,v2,v3,v4,v5,v6};
double tolerance = 1;
ConvexHull2D ch = new ConvexHull2D(vertices, tolerance);
vertices =ch.getVertices();
System.out.println(vertices);
}
但是使用这段代码我看到了这个异常
Exception in thread "main" org.apache.commons.math3.exception.MathIllegalArgumentException: vertices do not form a convex hull in CCW winding
at org.apache.commons.math3.geometry.euclidean.twod.hull.ConvexHull2D.<init>(ConvexHull2D.java:69)
at run_ootb_templates.LongitudeLatitudeTest.main(LongitudeLatitudeTest.java:22)
我对凸包的理解是空间中的任意 3 个点都可以形成一个凸包,除这 3 个点之外的任何其他点都可以容纳在这个凸包的边界内。
感谢您对解决问题的任何帮助,以及任何示例数据集,以便我理解这一点
【问题讨论】:
标签: java geometry convex-hull apache-commons-math