sector.java
来自「world wind java sdk 源码」· Java 代码 · 共 1,046 行 · 第 1/3 页
JAVA
1,046 行
*/ public final Angle getMinLongitude() { return minLongitude; } /** * Returns the sector's maximum latitude. * * @return The sector's maximum latitude. */ public final Angle getMaxLatitude() { return maxLatitude; } /** * Returns the sector's maximum longitude. * * @return The sector's maximum longitude. */ public final Angle getMaxLongitude() { return maxLongitude; } /** * Returns the angular difference between the sector's minimum and maximum latitudes: max - min * * @return The angular difference between the sector's minimum and maximum latitudes. */ public final Angle getDeltaLat() { return this.deltaLat;//Angle.fromDegrees(this.maxLatitude.degrees - this.minLatitude.degrees); } public final double getDeltaLatDegrees() { return this.deltaLat.degrees;//this.maxLatitude.degrees - this.minLatitude.degrees; } public final double getDeltaLatRadians() { return this.deltaLat.radians;//this.maxLatitude.radians - this.minLatitude.radians; } /** * Returns the angular difference between the sector's minimum and maximum longitudes: max - min. * * @return The angular difference between the sector's minimum and maximum longitudes */ public final Angle getDeltaLon() { return this.deltaLon;//Angle.fromDegrees(this.maxLongitude.degrees - this.minLongitude.degrees); } public final double getDeltaLonDegrees() { return this.deltaLon.degrees;//this.maxLongitude.degrees - this.minLongitude.degrees; } public final double getDeltaLonRadians() { return this.deltaLon.radians;//this.maxLongitude.radians - this.minLongitude.radians; } public boolean isWithinLatLonLimits() { return this.minLatitude.degrees >= -90 && this.maxLatitude.degrees <= 90 && this.minLongitude.degrees >= -180 && this.maxLongitude.degrees <= 180; } public boolean isSameSector(Iterable<? extends LatLon> corners) { if (corners == null) { String message = Logging.getMessage("nullValue.LocationsListIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (!isSector(corners)) return false; Sector s = Sector.boundingSector(corners); return s.equals(this); } @SuppressWarnings({"RedundantIfStatement"}) public static boolean isSector(Iterable<? extends LatLon> corners) { if (corners == null) { String message = Logging.getMessage("nullValue.LocationsListIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } LatLon[] latlons = new LatLon[5]; int i = 0; for (LatLon ll : corners) { if (i > 4 || ll == null) return false; latlons[i++] = ll; } if (!latlons[0].getLatitude().equals(latlons[1].getLatitude())) return false; if (!latlons[2].getLatitude().equals(latlons[3].getLatitude())) return false; if (!latlons[0].getLongitude().equals(latlons[3].getLongitude())) return false; if (!latlons[1].getLongitude().equals(latlons[2].getLongitude())) return false; if (i == 5 && !latlons[4].equals(latlons[0])) return false; return true; } /** * Returns the latitude and longitude of the sector's angular center: (minimum latitude + maximum latitude) / 2, * (minimum longitude + maximum longitude) / 2. * * @return The latitude and longitude of the sector's angular center */ public LatLon getCentroid() { Angle la = Angle.fromDegrees(0.5 * (this.getMaxLatitude().degrees + this.getMinLatitude().degrees)); Angle lo = Angle.fromDegrees(0.5 * (this.getMaxLongitude().degrees + this.getMinLongitude().degrees)); return new LatLon(la, lo); } /** * Computes the Cartesian coordinates of a Sector's center. * * @param globe The globe associated with the sector. * @param exaggeration The vertical exaggeration to apply. * @return the Cartesian coordinates of the sector's center. * @throws IllegalArgumentException if <code>globe</code> is null. */ public Vec4 computeCenterPoint(Globe globe, double exaggeration) { if (globe == null) { String msg = Logging.getMessage("nullValue.GlobeIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } double lat = 0.5 * (this.minLatitude.degrees + this.maxLatitude.degrees); double lon = 0.5 * (this.minLongitude.degrees + this.maxLongitude.degrees); Angle cLat = Angle.fromDegrees(lat); Angle cLon = Angle.fromDegrees(lon); return globe.computePointFromPosition(cLat, cLon, exaggeration * globe.getElevation(cLat, cLon)); } /** * Computes the Cartesian coordinates of a Sector's corners. * * @param globe The globe associated with the sector. * @param exaggeration The vertical exaggeration to apply. * @return an array of four Cartesian points. * @throws IllegalArgumentException if <code>globe</code> is null. */ public Vec4[] computeCornerPoints(Globe globe, double exaggeration) { if (globe == null) { String msg = Logging.getMessage("nullValue.GlobeIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } Vec4[] corners = new Vec4[4]; Angle minLat = this.minLatitude; Angle maxLat = this.maxLatitude; Angle minLon = this.minLongitude; Angle maxLon = this.maxLongitude; corners[0] = globe.computePointFromPosition(minLat, minLon, exaggeration * globe.getElevation(minLat, minLon)); corners[1] = globe.computePointFromPosition(minLat, maxLon, exaggeration * globe.getElevation(minLat, maxLon)); corners[2] = globe.computePointFromPosition(maxLat, maxLon, exaggeration * globe.getElevation(maxLat, maxLon)); corners[3] = globe.computePointFromPosition(maxLat, minLon, exaggeration * globe.getElevation(maxLat, minLon)); return corners; } /** * Returns a sphere that minimally surrounds the sector at a specified vertical exaggeration. * * @param globe the globe the sector is associated with * @param verticalExaggeration the vertical exaggeration to apply to the globe's elevations when computing the * sphere. * @param sector the sector to return the bounding sphere for. * @return The minimal bounding sphere in Cartesian coordinates. * @throws IllegalArgumentException if <code>globe</code> or <code>sector</code> is null */ static public Extent computeBoundingSphere(Globe globe, double verticalExaggeration, Sector sector) { if (globe == null) { String msg = Logging.getMessage("nullValue.GlobeIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } if (sector == null) { String msg = Logging.getMessage("nullValue.SectorIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } LatLon center = sector.getCentroid(); double[] minAndMaxElevations = globe.getMinAndMaxElevations(sector); double minHeight = minAndMaxElevations[0] * verticalExaggeration; double maxHeight = minAndMaxElevations[1] * verticalExaggeration; Vec4[] points = new Vec4[9]; points[0] = globe.computePointFromPosition(center.getLatitude(), center.getLongitude(), maxHeight); points[1] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMinLongitude(), maxHeight); points[2] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMaxLongitude(), maxHeight); points[3] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMinLongitude(), maxHeight); points[4] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMaxLongitude(), maxHeight); points[5] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMinLongitude(), minHeight); points[6] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMaxLongitude(), minHeight); points[7] = globe.computePointFromPosition(sector.getMinLatitude(), sector.getMinLongitude(), minHeight); points[8] = globe.computePointFromPosition(sector.getMaxLatitude(), sector.getMaxLongitude(), minHeight); return Sphere.createBoundingSphere(points); } public final boolean contains(Angle latitude, Angle longitude) { if (latitude == null || longitude == null) { String message = Logging.getMessage("nullValue.LatLonIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } return containsDegrees(latitude.degrees,longitude.degrees); } /** * Determines whether a latitude/longitude position is within the sector. The sector's angles are assumed to be * normalized to +/- 90 degrees latitude and +/- 180 degrees longitude. The result of the operation is undefined if * they are not. * * @param latLon the position to test, with angles normalized to +/- π latitude and +/- 2π longitude. * @return <code>true</code> if the position is within the sector, <code>false</code> otherwise. * @throws IllegalArgumentException if <code>latlon</code> is null. */ public final boolean contains(LatLon latLon) { if (latLon == null) { String message = Logging.getMessage("nullValue.LatLonIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } return this.contains(latLon.getLatitude(), latLon.getLongitude()); } /** * Determines whether a latitude/longitude postion expressed in radians is within the sector. The sector's angles * are assumed to be normalized to +/- 90 degrees latitude and +/- 180 degrees longitude. The result of the * operation is undefined if they are not. * * @param radiansLatitude the latitude in radians of the position to test, normalized +/- π. * @param radiansLongitude the longitude in radians of the position to test, normalized +/- 2π. * @return <code>true</code> if the position is within the sector, <code>false</code> otherwise. */ public boolean containsRadians(double radiansLatitude, double radiansLongitude) { return radiansLatitude >= this.minLatitude.radians && radiansLatitude <= this.maxLatitude.radians && radiansLongitude >= this.minLongitude.radians && radiansLongitude <= this.maxLongitude.radians; } public boolean containsDegrees(double degreesLatitude, double degreesLongitude) { return degreesLatitude >= this.minLatitude.degrees && degreesLatitude <= this.maxLatitude.degrees && degreesLongitude >= this.minLongitude.degrees && degreesLongitude <= this.maxLongitude.degrees; } /** * Determines whether another sectror is fully contained within this one. The sector's angles are assumed to be * normalized to +/- 90 degrees latitude and +/- 180 degrees longitude. The result of the operation is undefined if * they are not. * * @param that the sector to test for containment. * @return <code>true</code> if this sector fully contains the input sector, otherwise <code>false</code>. */ public boolean contains(Sector that) { if (that == null) return false; // Assumes normalized angles -- [-180, 180], [-90, 90] if (that.minLongitude.degrees < this.minLongitude.degrees) return false; if (that.maxLongitude.degrees > this.maxLongitude.degrees) return false; if (that.minLatitude.degrees < this.minLatitude.degrees) return false; //noinspection RedundantIfStatement if (that.maxLatitude.degrees > this.maxLatitude.degrees) return false; return true; } /** * Determines whether this sector intersects another sector's range of latitude and longitude. The sector's angles * are assumed to be normalized to +/- 90 degrees latitude and +/- 180 degrees longitude. The result of the * operation is undefined if they are not. * * @param that the sector to test for intersection. * @return <code>true</code> if the sectors intersect, otherwise <code>false</code>. */ public boolean intersects(Sector that) { if (that == null) return false; // Assumes normalized angles -- [-180, 180], [-90, 90] if (that.maxLongitude.degrees < this.minLongitude.degrees) return false; if (that.minLongitude.degrees > this.maxLongitude.degrees) return false; if (that.maxLatitude.degrees < this.minLatitude.degrees) return false; //noinspection RedundantIfStatement if (that.minLatitude.degrees > this.maxLatitude.degrees) return false; return true; } /** * Returns a new sector whose angles are the extremes of the this sector and another. The new sector's minimum * latitude and longitude will be the minimum of the two sectors. The new sector's maximum latitude and longitude
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?