fun computePolygonAreaFromVertices(points: Iterable<Vec4?>?): Double { if (points == null) { val message: String = Logging.getMessage("nullValue.IterableIsNull") Logging.logger().severe(message) throw IllegalArgumentException(message) } val iter: Iterator<Vec4?> = points.iterator() if (!iter.hasNext()) { return 0 } var area = 0.0 val firstPoint: Vec4? = iter.next() var point: Vec4? = firstPoint while (iter.hasNext()) { val nextLocation: Vec4? = iter.next() area += point.x * nextLocation.y area -= nextLocation.x * point.y point = nextLocation } if (!point.equals(firstPoint)) { area += point.x * firstPoint.y area -= firstPoint.x * point.y } area /= 2.0 return area }
Returns the area enclosed by the specified ( x , y ) points ( the z and w coordinates are ignored ) . If the specified points do not define a closed loop , then the loop is automatically closed by simulating appending the first point to the last point .