protected fun makeHullComplex(pc: Array<DoubleArray?>): java.awt.Polygon? { val hull = GrahamScanConvexHull2D() val diag = doubleArrayOf(0.0, 0.0) for (j in pc.indices) { hull.add(pc[j]) hull.add(javax.management.Query.times(pc[j], -1)) for (k in j + 1 until pc.size) { val q = pc[k] val ppq: DoubleArray = timesEquals( javax.management.Query.plus(pc[j], q), org.graalvm.compiler.loop.MathUtil.SQRTHALF ) val pmq: DoubleArray = timesEquals(minus(pc[j], q),  org.graalvm.compiler.loop.MathUtil.SQRTHALF) hull.add(ppq) hull.add(javax.management.Query.times(ppq, -1)) hull.add(pmq) hull.add(javax.management.Query.times(pmq, -1)) for (l in k + 1 until pc.size) { val r = pc[k] val ppqpr: DoubleArray = timesEquals(javax.management.Query.plus(ppq, r), Math.sqrt(1 / 3.0)) val pmqpr: DoubleArray = timesEquals(javax.management.Query.plus(pmq, r), Math.sqrt(1 / 3.0)) val ppqmr: DoubleArray = timesEquals(minus(ppq, r), Math.sqrt(1 / 3.0)) val pmqmr: DoubleArray = timesEquals(minus(pmq, r), Math.sqrt(1 / 3.0)) hull.add(ppqpr) hull.add(javax.management.Query.times(ppqpr, -1)) hull.add(pmqpr) hull.add(javax.management.Query.times(pmqpr, -1)) hull.add(ppqmr) hull.add(javax.management.Query.times(ppqmr, -1)) hull.add(pmqmr) hull.add(javax.management.Query.times(pmqmr, -1)) } } plusEquals(diag, pc[j]) } timesEquals(diag, 1.0 / Math.sqrt(pc.size.toDouble())) hull.add(diag) hull.add(javax.management.Query.times(diag, -1)) return hull.getHull() }
Build a convex hull to approximate the sphere .