Example #1
0
 public static LatLonPoint getLatLonForPixel(
     double startLat, double startLon, double differenceX, double differenceY, float scale) {
   double startY = 20925.5249D * Math.toRadians(startLat);
   double startX = 20925.5249D * Math.cos(Math.toRadians(startLat)) * Math.toRadians(startLon);
   differenceX /= scale;
   differenceY /= scale;
   double endX = differenceX / 1000D + startX;
   double endY = (differenceY / 1000D - startY) * -1D;
   double endLat = Math.toDegrees(endY / 20925.5249D);
   double endLon = Math.toDegrees(endX / (20925.5249D * Math.cos(Math.toRadians(startLat))));
   return new LatLonPoint(endLat, endLon);
 }
Example #2
0
  public static BufferedImage rotateImage(BufferedImage image, double theta) {
    int degrees = (int) Math.abs(Math.toDegrees(theta));
    double xCenter = image.getWidth() / 2;
    double yCenter = image.getHeight() / 2;
    AffineTransform rotateTransform = AffineTransform.getRotateInstance(-theta, xCenter, yCenter);

    // Translation adjustments so image still centered after rotate width/height changes
    if (image.getHeight() != image.getWidth() && degrees != 180 && degrees != 0) {
      Point2D origin = new Point2D.Double(0.0, 0.0);
      origin = rotateTransform.transform(origin, null);
      double yTranslate = origin.getY();

      Point2D yMax = new Point2D.Double(0, image.getHeight());
      yMax = rotateTransform.transform(yMax, null);
      double xTranslate = yMax.getX();

      AffineTransform translationAdjustment =
          AffineTransform.getTranslateInstance(-xTranslate, -yTranslate);
      rotateTransform.preConcatenate(translationAdjustment);
    }

    AffineTransformOp op = new AffineTransformOp(rotateTransform, AffineTransformOp.TYPE_BILINEAR);
    // Have to recopy image because of JDK bug #4723021, AffineTransformationOp throwing exception
    // sometimes
    image = copyImage(image, BufferedImage.TYPE_INT_ARGB);

    // Need to create filter dest image ourselves since AffineTransformOp's own dest image creation
    // throws exceptions in some cases.
    Rectangle bounds = op.getBounds2D(image).getBounds();
    BufferedImage finalImage =
        new BufferedImage(
            (int) bounds.getWidth(), (int) bounds.getHeight(), BufferedImage.TYPE_INT_ARGB);

    return op.filter(image, finalImage);
  }
Example #3
0
  protected void runData() {
    CompassDataMsg data;
    double orientation;
    double varOrientation;

    data = compass.getData();

    if (data != null) {
      orientation = Math.rint(Math.toDegrees(data.orientation) * 10.0) / 10.0;
      varOrientation = Math.rint(Math.toDegrees(data.varOrientation) * 10.0) / 10.0;
      orientationLabel.setText(orientation + "deg");
      varOrientationLabel.setText(varOrientation + "deg");

      setEnabled(true);
    } else {
      setEnabled(false);
    }
  }
  /* CALCULATE VALUES QUADRANTS: Calculate x-y values where direction is not
  parallel to eith x or y axis. */
  public static void calcValuesQuad(int x1, int y1, int x2, int y2) {
    double arrowAng = Math.toDegrees(Math.atan((double) haw / (double) al));
    double dist = Math.sqrt(al * al + aw);
    double lineAng =
        Math.toDegrees(Math.atan(((double) Math.abs(x1 - x2)) / ((double) Math.abs(y1 - y2))));

    // Adjust line angle for quadrant
    if (x1 > x2) {
      // South East
      if (y1 > y2) lineAng = 180.0 - lineAng;
    } else {
      // South West
      if (y1 > y2) lineAng = 180.0 + lineAng;
      // North West
      else lineAng = 360.0 - lineAng;
    }

    // Calculate coords
    xValues[0] = x2;
    yValues[0] = y2;
    calcCoords(1, x2, y2, dist, lineAng - arrowAng);
    calcCoords(2, x2, y2, dist, lineAng + arrowAng);
  }
Example #5
0
  private static LinkedList<Point2D> getCirclePoints(
      double centerLat, double centerLong, int numberOfPoints, double radius) {

    LinkedList<Point2D> Point2Ds = new LinkedList<Point2D>();

    double lat1, long1;
    double d_rad;
    double delta_pts;
    double radial, lat_rad, dlon_rad, lon_rad;

    // convert coordinates to radians
    lat1 = Math.toRadians(centerLat);
    long1 = Math.toRadians(centerLong);

    // radius is in meters
    d_rad = radius / 6378137;

    // loop through the array and write points
    for (int i = 0; i <= numberOfPoints; i++) {
      delta_pts = 360 / (double) numberOfPoints;
      radial = Math.toRadians((double) i * delta_pts);

      // This algorithm is limited to distances such that dlon < pi/2
      lat_rad =
          Math.asin(
              Math.sin(lat1) * Math.cos(d_rad)
                  + Math.cos(lat1) * Math.sin(d_rad) * Math.cos(radial));
      dlon_rad =
          Math.atan2(
              Math.sin(radial) * Math.sin(d_rad) * Math.cos(lat1),
              Math.cos(d_rad) - Math.sin(lat1) * Math.sin(lat_rad));
      lon_rad = ((long1 + dlon_rad + Math.PI) % (2 * Math.PI)) - Math.PI;

      Point2Ds.add(new Point2D.Double(Math.toDegrees(lat_rad), Math.toDegrees(lon_rad)));
    }
    return Point2Ds;
  }
Example #6
0
 public static java.awt.geom.Point2D.Float rotatePoint(
     java.awt.geom.Point2D.Float centerPoint, java.awt.geom.Point2D.Float point, float angle) {
   double radius =
       Math.sqrt(Math.pow(point.x - centerPoint.x, 2D) + Math.pow(point.y - centerPoint.y, 2D));
   double angleB1 = Math.toDegrees(Math.acos((double) (point.x - centerPoint.x) / radius));
   double x;
   double y;
   if (point.x <= centerPoint.x && point.y <= centerPoint.y) {
     x = (double) centerPoint.x + radius * Math.cos(Math.toRadians(angleB1 - (double) angle));
     y = (double) centerPoint.y - radius * Math.sin(Math.toRadians(angleB1 - (double) angle));
   } else if (point.x > centerPoint.x && point.y <= centerPoint.y) {
     x = (double) centerPoint.x + radius * Math.cos(Math.toRadians(angleB1 - (double) angle));
     y = (double) centerPoint.y - radius * Math.sin(Math.toRadians(angleB1 - (double) angle));
   } else if (point.x > centerPoint.x && point.y > centerPoint.y) {
     x = (double) centerPoint.x + radius * Math.cos(Math.toRadians(angleB1 + (double) angle));
     y = (double) centerPoint.y + radius * Math.sin(Math.toRadians(angleB1 + (double) angle));
   } else {
     x = (double) centerPoint.x + radius * Math.cos(Math.toRadians(angleB1 + (double) angle));
     y = (double) centerPoint.y + radius * Math.sin(Math.toRadians(angleB1 + (double) angle));
   }
   return new java.awt.geom.Point2D.Float((float) x, (float) y);
 }