📄 surfaceellipse.java
字号:
/* Copyright (C) 2001, 2009 United States Government as represented bythe Administrator of the National Aeronautics and Space Administration.All Rights Reserved.*/package gov.nasa.worldwind.render;import gov.nasa.worldwind.geom.*;import gov.nasa.worldwind.globes.Globe;import gov.nasa.worldwind.util.*;/** * @author dcollins * @version $Id: SurfaceEllipse.java 10899 2009-05-06 01:02:39Z dcollins $ */public class SurfaceEllipse extends SurfaceConcaveShape{ protected static final int ELLIPSE_MIN_NUM_INTERVALS = 8; protected static final int ELLIPSE_DEFAULT_NUM_INTERVALS = 32; protected LatLon center; protected double majorRadius; protected double minorRadius; protected Angle heading; private int intervals; public SurfaceEllipse(ShapeAttributes attributes, LatLon center, double majorRadius, double minorRadius, Angle heading, int intervals) { super(attributes); if (center == null) { String message = Logging.getMessage("nullValue.CenterIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (majorRadius < 0) { String message = Logging.getMessage("generic.ArgumentOutOfRange", "majorRadius < 0"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (minorRadius < 0) { String message = Logging.getMessage("generic.ArgumentOutOfRange", "minorRadius < 0"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (heading == null) { String message = Logging.getMessage("nullValue.HeadingIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (intervals < ELLIPSE_MIN_NUM_INTERVALS) { String message = Logging.getMessage("generic.ArgumentOutOfRange", "intervals < " + ELLIPSE_MIN_NUM_INTERVALS); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.center = center; this.majorRadius = majorRadius; this.minorRadius = minorRadius; this.heading = heading; this.intervals = intervals; } public SurfaceEllipse(ShapeAttributes attributes, LatLon center, double majorRadius, double minorRadius, Angle heading) { this(attributes, center, majorRadius, minorRadius, heading, ELLIPSE_DEFAULT_NUM_INTERVALS); } public SurfaceEllipse(ShapeAttributes attributes, int intervals) { this(attributes, LatLon.ZERO, 0, 0, Angle.ZERO, intervals); } public SurfaceEllipse(ShapeAttributes attributes) { this(attributes, ELLIPSE_DEFAULT_NUM_INTERVALS); } public SurfaceEllipse(LatLon center, double majorRadius, double minorRadius, Angle heading, int intervals) { this(new BasicShapeAttributes(), center, majorRadius, minorRadius, heading, intervals); } public SurfaceEllipse(LatLon center, double majorRadius, double minorRadius, Angle heading) { this(center, majorRadius, minorRadius, heading, ELLIPSE_DEFAULT_NUM_INTERVALS); } public SurfaceEllipse() { this(new BasicShapeAttributes(), ELLIPSE_DEFAULT_NUM_INTERVALS); } public LatLon getCenter() { return this.center; } public void setCenter(LatLon center) { if (center == null) { String message = Logging.getMessage("nullValue.CenterIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.center = center; this.onShapeChanged(); } public double getMajorRadius() { return this.majorRadius; } public double getMinorRadius() { return this.minorRadius; } public void setMajorRadius(double radius) { if (radius < 0) { String message = Logging.getMessage("generic.ArgumentOutOfRange", "radius < 0"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.majorRadius = radius; this.onShapeChanged(); } public void setMinorRadius(double radius) { if (radius < 0) { String message = Logging.getMessage("generic.ArgumentOutOfRange", "radius < 0"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.minorRadius = radius; this.onShapeChanged(); } public void setRadii(double majorRadius, double minorRadius) { this.setMajorRadius(majorRadius); this.setMinorRadius(minorRadius); } public Angle getHeading() { return this.heading; } public void setHeading(Angle heading) { if (heading == null) { String message = Logging.getMessage("nullValue.HeadingIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.heading = heading; this.onShapeChanged(); } public int getIntervals() { return this.intervals; } public void setIntervals(int intervals) { if (intervals < ELLIPSE_MIN_NUM_INTERVALS) { String message = Logging.getMessage("generic.ArgumentOutOfRange", "intervals < " + ELLIPSE_MIN_NUM_INTERVALS); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.intervals = intervals; this.onShapeChanged(); } public Iterable<? extends Sector> getSectors(DrawContext dc) { if (dc == null) { String message = Logging.getMessage("nullValue.GlobeIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } Iterable<? extends Sector> sectors = this.computeBoundingSectors(dc.getGlobe()); sectors = getSurfaceShapeSupport().adjustSectorsByBorderWidth(sectors, this.getAttributes()); return sectors; } public Position getReferencePosition() { return new Position(this.center, 0); } protected void doMoveTo(Position oldReferencePosition, Position newReferencePosition) { Angle heading = LatLon.greatCircleAzimuth(oldReferencePosition, this.center); Angle pathLength = LatLon.greatCircleDistance(oldReferencePosition, this.center); this.setCenter(LatLon.greatCircleEndPosition(newReferencePosition, heading, pathLength)); } protected LatLon computeLocationFor(Globe globe, Angle angle) { if (globe == null) { String message = Logging.getMessage("nullValue.GlobeIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (angle == null) { String message = Logging.getMessage("nullValue.AngleIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } double xLength = this.majorRadius * Math.cos(angle.radians); double yLength = this.minorRadius * Math.sin(angle.radians); double distance = Math.sqrt(xLength * xLength + yLength * yLength); double globeRadius = globe.getRadiusAt(this.center.getLatitude(), this.center.getLongitude()); // azimuth runs positive clockwise from north and through 360 degrees. double azimuth = (Math.PI / 2.0) - (Math.acos(xLength/distance) * Math.signum(yLength) - this.heading.radians); return LatLon.greatCircleEndPosition(this.center, azimuth, distance / globeRadius); } protected Iterable<? extends Sector> computeBoundingSectors(Globe globe) { if (globe == null) { String message = Logging.getMessage("nullValue.GlobeIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } // TODO: Compute a better fitting bounding sector for SurfaceEllipse. double radius = Math.max(this.majorRadius, this.minorRadius); return java.util.Arrays.asList(Sector.splitBoundingSectors(globe, this.center, radius)); } protected void computeLocations(Globe globe, int intervals, java.util.List<LatLon> locations) { if (globe == null) { String message = Logging.getMessage("nullValue.GlobeIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (locations == null) { String message = Logging.getMessage("nullValue.LocationsListIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } int numPositions = 1 + Math.max(ELLIPSE_MIN_NUM_INTERVALS, intervals); double da = (2 * Math.PI) / (numPositions - 1); for (int i = 0; i < numPositions; i++) { double angle = (i != numPositions - 1) ? i * da : 0; locations.add(this.computeLocationFor(globe, Angle.fromRadians(angle))); } } protected void computeLocations(Globe globe, java.util.List<LatLon> locations) { this.computeLocations(globe, this.intervals, locations); } protected void computeDrawLocations(Globe globe, double edgeIntervalsPerDegree, java.util.List<LatLon> locations) { if (globe == null) { String message = Logging.getMessage("nullValue.GlobeIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (locations == null) { String message = Logging.getMessage("nullValue.LocationsListIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } int intervals = this.computeNumIntervals(globe, edgeIntervalsPerDegree); this.computeLocations(globe, intervals, locations); } protected int computeNumIntervals(Globe globe, double edgeIntervalsPerDegree) { if (globe == null) { String message = Logging.getMessage("nullValue.GlobeIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } int numEdgeIntervals = this.computeNumEdgeIntervals(globe, edgeIntervalsPerDegree); return numEdgeIntervals * this.intervals; } protected int computeNumEdgeIntervals(Globe globe, double edgeIntervalsPerDegree) { if (globe == null) { String message = Logging.getMessage("nullValue.GlobeIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } int numPositions = 1 + Math.max(ELLIPSE_MIN_NUM_INTERVALS, intervals); double radius = Math.max(this.majorRadius, this.minorRadius); double da = (2 * Math.PI) / (numPositions - 1); Angle edgePathLength = Angle.fromRadians(da * radius / globe.getRadiusAt(this.center)); double edgeIntervals = WWMath.clamp(edgeIntervalsPerDegree * edgePathLength.degrees, this.minEdgeIntervals, this.maxEdgeIntervals); return (int) Math.ceil(edgeIntervals); } //**************************************************************// //******************** Restorable State ***********************// //**************************************************************// protected void doGetRestorableState(RestorableSupport rs, RestorableSupport.StateObject context) { super.doGetRestorableState(rs, context); rs.addStateValueAsLatLon(context, "center", this.getCenter()); rs.addStateValueAsDouble(context, "majorRadius", this.getMajorRadius()); rs.addStateValueAsDouble(context, "minorRadius", this.getMinorRadius()); rs.addStateValueAsDouble(context, "headingDegrees", this.getHeading().degrees); rs.addStateValueAsInteger(context, "intervals", this.getIntervals()); } protected void doRestoreState(RestorableSupport rs, RestorableSupport.StateObject context) { super.doRestoreState(rs, context); LatLon ll = rs.getStateValueAsLatLon(context, "center"); if (ll != null) this.setCenter(ll); Double d = rs.getStateValueAsDouble(context, "majorRadius"); if (d != null) this.setMajorRadius(d); d = rs.getStateValueAsDouble(context, "minorRadius"); if (d != null) this.setMinorRadius(d); d = rs.getStateValueAsDouble(context, "headingDegrees"); if (d != null) this.setHeading(Angle.fromDegrees(d)); Integer i = rs.getStateValueAsInteger(context, "intervals"); if (d != null) this.setIntervals(i); } protected void legacyRestoreState(RestorableSupport rs, RestorableSupport.StateObject context) { super.legacyRestoreState(rs, context); // These properties has not changed since the last version, but they're shown here for reference. //Double major = rs.getStateValueAsDouble(context, "majorRadius"); //Double minor = rs.getStateValueAsDouble(context, "minorRadius"); //if (major != null && minor != null) // this.setAxisLengths(major, minor); // This property has not changed since the last version, but it's shown here for reference. //LatLon center = rs.getStateValueAsLatLon(context, "center"); //if (center != null) // this.setCenter(center); // This property has not changed since the last version, but it's shown here for reference. //Integer intervals = rs.getStateValueAsInteger(context, "intervals"); //if (intervals != null) // this.setIntervals(intervals); Double od = rs.getStateValueAsDouble(context, "orientationDegrees"); if (od != null) this.setHeading(Angle.fromDegrees(od)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -