BoundingBox { public BoundingBox setToSector(Sector sector, Globe globe, float minHeight, float maxHeight) { if (sector == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "BoundingBox", "setToSector", "missingSector")); } if (globe == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "BoundingBox", "setToSector", "missingGlobe")); } int numLat = 3; int numLon = 3; int count = numLat * numLon; float[] heights = new float[count]; Arrays.fill(heights, maxHeight); heights[0] = heights[2] = heights[6] = heights[8] = minHeight; float[] points = new float[count * 3]; globe.geographicToCartesianGrid(sector, numLat, numLon, heights, 1.0f, null, points, 0, 0); double centroidLat = sector.centroidLatitude(); double centroidLon = sector.centroidLongitude(); Matrix4 matrix = globe.geographicToCartesianTransform(centroidLat, centroidLon, 0, new Matrix4()); double m[] = matrix.m; this.r.set(m[0], m[4], m[8]); this.s.set(m[1], m[5], m[9]); this.t.set(m[2], m[6], m[10]); double rExtremes[] = {Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}; double sExtremes[] = {Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}; double tExtremes[] = {Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}; Vec3 p = new Vec3(); for (int idx = 0, len = points.length; idx < len; idx += 3) { p.set(points[idx], points[idx + 1], points[idx + 2]); adjustExtremes(this.r, rExtremes, this.s, sExtremes, this.t, tExtremes, p); } if (rExtremes[1] - rExtremes[0] < sExtremes[1] - sExtremes[0]) { swapAxes(this.r, rExtremes, this.s, sExtremes); } if (sExtremes[1] - sExtremes[0] < tExtremes[1] - tExtremes[0]) { swapAxes(this.s, sExtremes, this.t, tExtremes); } if (rExtremes[1] - rExtremes[0] < sExtremes[1] - sExtremes[0]) { swapAxes(this.r, rExtremes, this.s, sExtremes); } double rLen = rExtremes[1] - rExtremes[0]; double sLen = sExtremes[1] - sExtremes[0]; double tLen = tExtremes[1] - tExtremes[0]; double rSum = rExtremes[1] + rExtremes[0]; double sSum = sExtremes[1] + sExtremes[0]; double tSum = tExtremes[1] + tExtremes[0]; double cx = 0.5 * (this.r.x * rSum + this.s.x * sSum + this.t.x * tSum); double cy = 0.5 * (this.r.y * rSum + this.s.y * sSum + this.t.y * tSum); double cz = 0.5 * (this.r.z * rSum + this.s.z * sSum + this.t.z * tSum); double rx_2 = 0.5 * this.r.x * rLen; double ry_2 = 0.5 * this.r.y * rLen; double rz_2 = 0.5 * this.r.z * rLen; this.center.set(cx, cy, cz); this.topCenter.set(cx + rx_2, cy + ry_2, cz + rz_2); this.bottomCenter.set(cx - rx_2, cy - ry_2, cz - rz_2); this.r.multiply(rLen); this.s.multiply(sLen); this.t.multiply(tLen); this.radius = 0.5 * Math.sqrt(rLen * rLen + sLen * sLen + tLen * tLen); return this; } BoundingBox(); @Override String toString(); boolean isUnitBox(); BoundingBox setToUnitBox(); BoundingBox setToPoints(float[] array, int count, int stride); BoundingBox setToSector(Sector sector, Globe globe, float minHeight, float maxHeight); BoundingBox translate(double x, double y, double z); double distanceTo(Vec3 point); boolean intersectsFrustum(Frustum frustum);  }
@Test public void testSetToSector() throws Exception { BoundingBox boundingBox = new BoundingBox(); double centerLat = 0; double centerLon = 0; Sector smallSector = sectorFromCentroid(centerLat, centerLon, 0.0001, 0.0001); Sector largeSector = sectorFromCentroid(centerLat, centerLon, 1d, 1d); Vec3 point = globe.geographicToCartesian(centerLat, centerLon, 0, new Vec3()); float minElevation = 0; float maxElevation = 100; boundingBox.setToSector(smallSector, globe, minElevation, maxElevation); assertEquals("small center x", point.x, boundingBox.center.x, 1e-1); assertEquals("small center y", point.y, boundingBox.center.y, 1e-1); assertEquals("small center z", point.z + maxElevation / 2, boundingBox.center.z, 1e-1); minElevation = 0; maxElevation = 0; boundingBox.setToSector(largeSector, globe, minElevation, maxElevation); assertEquals("large center x", point.x, boundingBox.center.x, 1e-1); assertEquals("large center y", point.y, boundingBox.center.y, 1e-1); assertEquals("large center z", point.z, boundingBox.center.z, 300); }