/**
  * Creates a new <code>Sector</code> and initializes it to the specified angles. The angles are
  * assumed to be normalized to +/- \u03c0/2 radians latitude and +/- \u03c0 radians longitude, but
  * this method does not verify that.
  *
  * @param minLatitude the sector's minimum latitude in radians.
  * @param maxLatitude the sector's maximum latitude in radians.
  * @param minLongitude the sector's minimum longitude in radians.
  * @param maxLongitude the sector's maximum longitude in radians.
  * @return the new <code>Sector</code>
  */
 public static Sector fromRadians(
     double minLatitude, double maxLatitude, double minLongitude, double maxLongitude) {
   return new Sector(
       Angle.fromRadians(minLatitude),
       Angle.fromRadians(maxLatitude),
       Angle.fromRadians(minLongitude),
       Angle.fromRadians(maxLongitude));
 }
  /**
   * Select the visible grid elements
   *
   * @param dc the current <code>DrawContext</code>.
   */
  protected void selectRenderables(DrawContext dc) {
    if (dc == null) {
      String message = Logging.getMessage("nullValue.DrawContextIsNull");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }
    Sector vs = dc.getVisibleSector();
    OrbitView view = (OrbitView) dc.getView();
    // Compute labels offset from view center
    Position centerPos = view.getCenterPosition();
    Double pixelSizeDegrees =
        Angle.fromRadians(
                view.computePixelSizeAtDistance(view.getZoom())
                    / dc.getGlobe().getEquatorialRadius())
            .degrees;
    Double labelOffsetDegrees = pixelSizeDegrees * view.getViewport().getWidth() / 4;
    Position labelPos =
        Position.fromDegrees(
            centerPos.getLatitude().degrees - labelOffsetDegrees,
            centerPos.getLongitude().degrees - labelOffsetDegrees,
            0);
    Double labelLatDegrees = labelPos.getLatitude().normalizedLatitude().degrees;
    labelLatDegrees = Math.min(Math.max(labelLatDegrees, -76), 78);
    labelPos =
        new Position(
            Angle.fromDegrees(labelLatDegrees), labelPos.getLongitude().normalizedLongitude(), 0);

    if (vs != null) {
      for (GridElement ge : this.gridElements) {
        if (ge.isInView(dc)) {
          if (ge.renderable instanceof GeographicText) {
            GeographicText gt = (GeographicText) ge.renderable;
            if (labelPos.getLatitude().degrees < 72
                || "*32*34*36*".indexOf("*" + gt.getText() + "*") == -1) {
              // Adjust label position according to eye position
              Position pos = gt.getPosition();
              if (ge.type.equals(GridElement.TYPE_LATITUDE_LABEL))
                pos =
                    Position.fromDegrees(
                        pos.getLatitude().degrees,
                        labelPos.getLongitude().degrees,
                        pos.getElevation());
              else if (ge.type.equals(GridElement.TYPE_LONGITUDE_LABEL))
                pos =
                    Position.fromDegrees(
                        labelPos.getLatitude().degrees,
                        pos.getLongitude().degrees,
                        pos.getElevation());

              gt.setPosition(pos);
            }
          }

          this.graticuleSupport.addRenderable(ge.renderable, GRATICULE_UTM);
        }
      }
      // System.out.println("Total elements: " + count + " visible sector: " + vs);
    }
  }
Ejemplo n.º 3
0
  /**
   * Create a set of UPS coordinates for the given <code>Globe</code>.
   *
   * @param hemisphere the hemisphere, either {@link gov.nasa.worldwind.avlist.AVKey#NORTH} or
   *     {@link gov.nasa.worldwind.avlist.AVKey#SOUTH}.
   * @param easting the easting distance in meters
   * @param northing the northing distance in meters.
   * @param globe the <code>Globe</code> - can be null (will use WGS84).
   * @return the corresponding <code>UPSCoord</code>.
   * @throws IllegalArgumentException if the conversion to UPS coordinates fails.
   */
  public static UPSCoord fromUPS(String hemisphere, double easting, double northing, Globe globe) {
    final UPSCoordConverter converter = new UPSCoordConverter(globe);
    long err = converter.convertUPSToGeodetic(hemisphere, easting, northing);

    if (err != UTMCoordConverter.UTM_NO_ERROR) {
      String message = Logging.getMessage("Coord.UTMConversionError");
      Logging.logger().severe(message);
      throw new IllegalArgumentException(message);
    }

    return new UPSCoord(
        Angle.fromRadians(converter.getLatitude()),
        Angle.fromRadians(converter.getLongitude()),
        hemisphere,
        easting,
        northing);
  }
Ejemplo n.º 4
0
  /**
   * The function convertGeodeticToMGRS converts Geodetic (latitude and longitude) coordinates to an
   * MGRS coordinate string, according to the current ellipsoid parameters. If any errors occur, the
   * error code(s) are returned by the function, otherwise MGRS_NO_ERROR is returned.
   *
   * @param latitude Latitude in radians
   * @param longitude Longitude in radian
   * @param precision Precision level of MGRS string
   * @return error code
   */
  public long convertGeodeticToMGRS(double latitude, double longitude, int precision) {
    String Hemisphere = AVKey.NORTH;
    double Easting = 0.0;
    double Northing = 0.0;

    MGRSString = "";

    long error_code = MGRS_NO_ERROR;
    if ((latitude < -PI_OVER_2) || (latitude > PI_OVER_2)) {
        /* Latitude out of range */
      error_code = MGRS_LAT_ERROR;
    }

    if ((longitude < -PI) || (longitude > (2 * PI))) {
        /* Longitude out of range */
      error_code = MGRS_LON_ERROR;
    }

    if ((precision < 0) || (precision > MAX_PRECISION)) error_code = MGRS_PRECISION_ERROR;

    if (error_code == MGRS_NO_ERROR) {
      if ((latitude < MIN_UTM_LAT) || (latitude > MAX_UTM_LAT)) {
        // TODO: polar
        try {
          UPSCoord UPS =
              UPSCoord.fromLatLon(Angle.fromRadians(latitude), Angle.fromRadians(longitude), globe);
          error_code |=
              convertUPSToMGRS(UPS.getHemisphere(), UPS.getEasting(), UPS.getNorthing(), precision);
        } catch (Exception e) {
          error_code = MGRS_UPS_ERROR;
        }
      } else {
        try {
          UTMCoord UTM =
              UTMCoord.fromLatLon(Angle.fromRadians(latitude), Angle.fromRadians(longitude), globe);
          error_code |=
              convertUTMToMGRS(
                  UTM.getZone(), latitude, UTM.getEasting(), UTM.getNorthing(), precision);
        } catch (Exception e) {
          error_code = MGRS_UTM_ERROR;
        }
      }
    }

    return error_code;
  }
Ejemplo n.º 5
0
  protected Angle computeIconRadius(DrawContext dc, double regionPixelSize, Sector drawSector) {
    double minCosLat =
        Math.min(drawSector.getMinLatitude().cos(), drawSector.getMaxLatitude().cos());
    if (minCosLat < 0.001) return Angle.POS180;

    Rectangle2D iconDimension = this.computeDrawDimension(regionPixelSize); // Meter
    double dLat = iconDimension.getHeight() / dc.getGlobe().getRadius();
    double dLon = iconDimension.getWidth() / dc.getGlobe().getRadius() / minCosLat;
    return Angle.fromRadians(Math.sqrt(dLat * dLat + dLon * dLon) / 2);
  }
 protected Angle computePanHeading(OrbitView view, ScreenAnnotation control) {
   // Compute last pick point 'heading' relative to pan control center
   double size = control.getAttributes().getSize().width * control.getAttributes().getScale();
   Vec4 center = new Vec4(control.getScreenPoint().x, control.getScreenPoint().y + size / 2, 0);
   double px = lastPickPoint.x - center.x;
   double py = view.getViewport().getHeight() - lastPickPoint.y - center.y;
   Angle heading = view.getHeading().add(Angle.fromRadians(Math.atan2(px, py)));
   heading = heading.degrees >= 0 ? heading : heading.addDegrees(360);
   return heading;
 }
 protected Angle computeLookPitch(OrbitView view, ScreenAnnotation control, double pitchStep) {
   // Compute last pick point 'pitch' relative to look control center on y
   double size = control.getAttributes().getSize().width * control.getAttributes().getScale();
   Vec4 center = new Vec4(control.getScreenPoint().x, control.getScreenPoint().y + size / 2, 0);
   double py = view.getViewport().getHeight() - lastPickPoint.y - center.y;
   double pickDistanceFactor = Math.min(Math.abs(py) / 3000, 5) * Math.signum(py);
   // New pitch
   Angle pitch = view.getPitch().add(Angle.fromRadians(pitchStep * pickDistanceFactor));
   pitch = pitch.degrees >= 0 ? (pitch.degrees <= 90 ? pitch : Angle.fromDegrees(90)) : Angle.ZERO;
   return pitch;
 }
 protected Angle computeLookHeading(OrbitView view, ScreenAnnotation control, double headingStep) {
   // Compute last pick point 'heading' relative to look control center on x
   double size = control.getAttributes().getSize().width * control.getAttributes().getScale();
   Vec4 center = new Vec4(control.getScreenPoint().x, control.getScreenPoint().y + size / 2, 0);
   double px = lastPickPoint.x - center.x;
   double pickDistanceFactor = Math.min(Math.abs(px) / 3000, 5) * Math.signum(px);
   // New heading
   Angle heading = view.getHeading().add(Angle.fromRadians(headingStep * pickDistanceFactor));
   heading = heading.degrees >= 0 ? heading : heading.addDegrees(360);
   return heading;
 }
Ejemplo n.º 9
0
  /**
   * Compute the amount of rotation to apply to a label in order to keep it oriented toward its
   * orientation position.
   *
   * @param screenPoint Geographic position of the text, projected onto the screen.
   * @param orientationScreenPoint Orientation position, projected onto the screen.
   * @return The rotation angle to apply when drawing the label.
   */
  protected Angle computeRotation(Vec4 screenPoint, Vec4 orientationScreenPoint) {
    // Determine delta between the orientation position and the label position
    double deltaX = screenPoint.x - orientationScreenPoint.x;
    double deltaY = screenPoint.y - orientationScreenPoint.y;

    if (deltaX != 0) {
      double angle = Math.atan(deltaY / deltaX);
      return Angle.fromRadians(angle);
    } else {
      return Angle.POS90; // Vertical label
    }
  }
Ejemplo n.º 10
0
 /**
  * Compute the view range footprint on the globe.
  *
  * @param dc the current <code>DrawContext</code>
  * @param steps the number of steps.
  * @return an array list of <code>LatLon</code> forming a closed shape.
  */
 protected ArrayList<LatLon> computeViewFootPrint(DrawContext dc, int steps) {
   ArrayList<LatLon> positions = new ArrayList<LatLon>();
   Position eyePos = dc.getView().getEyePosition();
   Angle distance =
       Angle.fromRadians(
           Math.asin(
               dc.getView().getFarClipDistance()
                   / (dc.getGlobe().getRadius() + eyePos.getElevation())));
   if (distance.degrees > 10) {
     double headStep = 360d / steps;
     Angle heading = Angle.ZERO;
     for (int i = 0; i <= steps; i++) {
       LatLon p = LatLon.greatCircleEndPosition(eyePos, heading, distance);
       positions.add(p);
       heading = heading.addDegrees(headStep);
     }
     return positions;
   } else return null;
 }
Ejemplo n.º 11
0
    public AppFrame() {
      super(true, true, false);

      IconLayer layer = new IconLayer();
      layer.setPickEnabled(true);
      layer.setAllowBatchPicking(false);
      layer.setRegionCulling(true);

      UserFacingIcon icon =
          new UserFacingIcon(
              "src/images/32x32-icon-nasa.png",
              new Position(Angle.fromRadians(0), Angle.fromRadians(0), 0));
      icon.setSize(new Dimension(24, 24));
      layer.addIcon(icon);

      icon =
          new UserFacingIcon(
              "src/images/32x32-icon-nasa.png",
              new Position(Angle.fromRadians(0.1), Angle.fromRadians(0.0), 0));
      icon.setSize(new Dimension(24, 24));
      layer.addIcon(icon);

      icon =
          new UserFacingIcon(
              "src/images/32x32-icon-nasa.png",
              new Position(Angle.fromRadians(0.0), Angle.fromRadians(0.1), 0));
      icon.setSize(new Dimension(24, 24));
      layer.addIcon(icon);

      icon =
          new UserFacingIcon(
              "src/images/32x32-icon-nasa.png",
              new Position(Angle.fromRadians(0.1), Angle.fromRadians(0.1), 0));
      icon.setSize(new Dimension(24, 24));
      layer.addIcon(icon);

      icon =
          new UserFacingIcon(
              "src/images/32x32-icon-nasa.png",
              new Position(Angle.fromRadians(0), Angle.fromDegrees(180), 0));
      icon.setSize(new Dimension(24, 24));
      layer.addIcon(icon);

      ApplicationTemplate.insertAfterPlacenames(this.getWwd(), layer);

      this.getWwd()
          .addSelectListener(
              new SelectListener() {
                @Override
                public void selected(SelectEvent event) {
                  if (event.getEventAction().equals(SelectEvent.ROLLOVER)) {
                    PickedObjectList pol = event.getObjects();
                    System.out.println(" Picked Objects Size " + pol.size());
                    for (PickedObject po : pol) {
                      System.out.println(
                          " Class "
                              + po.getObject().getClass().getName()
                              + "  isTerrian="
                              + po.isTerrain());
                    }
                  }
                }
              });
      this.getWwd().getSceneController().setDeepPickEnabled(true);
    }
Ejemplo n.º 12
0
 protected Angle computeSectorRadius(Sector sector) {
   double dLat = sector.getDeltaLatRadians();
   double dLon = sector.getDeltaLonRadians();
   return Angle.fromRadians(Math.sqrt(dLat * dLat + dLon * dLon) / 2);
 }
Ejemplo n.º 13
0
 public static Angle atan(
     double tan) { // Tom: this method is not used, should we delete it? (13th Dec 06)
   return Angle.fromRadians(Math.atan(tan));
 }
Ejemplo n.º 14
0
 public static Angle acos(
     double cosine) { // Tom: this method is not used, should we delete it? (13th Dec 06)
   return Angle.fromRadians(Math.acos(cosine));
 }
Ejemplo n.º 15
0
 public final Angle subtractRadians(double radians) {
   return Angle.fromRadians(this.radians - radians);
 }
Ejemplo n.º 16
0
 public final Angle addRadians(double radians) {
   return Angle.fromRadians(this.radians + radians);
 }