Esempio n. 1
1
  public void onSurfaceChanged(GL10 gl, int w, int h) {
    wViewport = w;
    hViewPort = h;

    // ViewPort
    gl.glViewport(0, 0, w, h);
    // Projection
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    //  GLU.gluPerspective(gl, 30, ratio, 1, 4000); Android source Bugged !! Should be :
    //  GLU.gluPerspective(gl, 30, (float) w /h, 1, 4000);
    //  600 1200 semble OK mais le zoom coupe l'image...
    float ratio = (float) w / h, fov = 30.0f, near = 60, far = 12000, top, bottom, left, right;
    if (ratio >= 1.0f) {
      top = near * (float) Math.tan(fov * (Math.PI / 360.0));
      bottom = -top;
      left = bottom * ratio;
      right = top * ratio;
    } else {
      right = near * (float) Math.tan(fov * (Math.PI / 360.0));
      left = -right;
      top = right / ratio;
      bottom = left / ratio;
    }
    gl.glFrustumf(left, right, bottom, top, near, far);
    gl.glPushMatrix();
  }
Esempio n. 2
1
  /**
   * Calculates next Center for turtle and next Location for line ending/pixel calculations if
   * Turtle overruns to bottom on move.
   */
  private Location[] overrunBottom() {
    Location nextLocation;
    Location nextCenter;

    // exact calculation for exact 90 degree heading directions (don't want trig functions
    // handling this)
    if (getHeading() == ONE_QUARTER_TURN_DEGREES) {
      nextLocation = new Location(getX(), myCanvasBounds.getHeight());
      nextCenter = new Location(getX(), 0);
      return new Location[] {nextLocation, nextCenter};
    }

    double angle = getHeading();
    if (getHeading() > ONE_QUARTER_TURN_DEGREES) {
      angle = -(HALF_TURN_DEGREES - getHeading());
    }
    angle = Math.toRadians(angle);
    nextLocation =
        new Location(
            getX() + (myCanvasBounds.getHeight() - getY()) / Math.tan(angle),
            myCanvasBounds.getHeight());
    nextCenter = new Location(getX() + (myCanvasBounds.getHeight() - getY()) / Math.tan(angle), 0);

    // eliminates race condition - if next location overruns left/right AND top/bottom it checks
    // to see which is overrun first and corrects
    if (nextLocation.getX() > myCanvasBounds.getWidth())
      // right
      return overrunRight();
    else if (nextLocation.getX() < 0) // left
    return overrunLeft();
    return new Location[] {nextLocation, nextCenter};
  }
Esempio n. 3
1
    private Location NextEdge(double direction) {
      direction = AcceptableAngle(direction);
      Double topleftangle = AcceptableAngle(myCenter.difference(TOP_LEFT).getDirection());
      Double toprightangle = AcceptableAngle(myCenter.difference(TOP_RIGHT).getDirection());
      Double bottomleftangle = AcceptableAngle(myCenter.difference(BOTTOM_LEFT).getDirection());
      Double bottomrightangle = AcceptableAngle(myCenter.difference(BOTTOM_RIGHT).getDirection());

      if (direction >= topleftangle && direction < toprightangle) {
        double Xcoordinate =
            myCenter.getX() + myCenter.getY() * Math.tan(Math.toRadians(direction - 270));
        return new Location(Xcoordinate, MIN_Y);
      } else if (direction < bottomrightangle || direction >= toprightangle) {
        double Ycoordinate =
            myCenter.getY() + (MAX_X - myCenter.getX()) * Math.tan(Math.toRadians(direction));
        return new Location(MAX_X, Ycoordinate);
      } else if (direction >= bottomrightangle && direction < bottomleftangle) {
        double Xcoordinate =
            myCenter.getX() - (MAX_Y - myCenter.getY()) * Math.tan(Math.toRadians(direction - 90));
        return new Location(Xcoordinate, MAX_Y);
      } else {
        double Ycoordinate =
            myCenter.getY() - myCenter.getX() * Math.tan(Math.toRadians(direction - 180));
        return new Location(MIN_X, Ycoordinate);
      }
    }
Esempio n. 4
1
  /**
   * @param tiles
   * @param distance
   * @param lat
   * @param lon
   * @return
   */
  private DataTile processTile(
      ArrayList<ArrayList<DataTile>> tiles, int distance, double lat, double lon) {
    int rankAverage;
    int rankTotal = 0;
    Integer finalLat;
    Integer finalLon;
    Double finalHeight;
    Double heightTotal = 0d;

    ArrayList<Integer> rankArray = new ArrayList<Integer>();
    ArrayList<Double> heightArray = new ArrayList<Double>();

    if (tiles.size() == 0) {
      // Theres missing data so return null :(
      return null;
    }

    for (int x = 0; x < tiles.size() - 1; x++) {

      ArrayList<DataTile> tileRow = tiles.get(x);

      for (int y = 0; y < tileRow.size() - 1; y++) {

        Double slope;
        Double opp;
        Double centre = tileRow.get(y).getHeight();
        Double right = tileRow.get(y + 1).getHeight();
        Double below = tiles.get(x).get(y).getHeight();

        heightArray.add(centre);

        // Calc right slope first
        opp = centre - right;
        slope = Math.toDegrees(Math.tan((opp / distance)));
        rankArray.add(calcSlopeRank(slope));

        // Calc below slope
        opp = centre - below;
        slope = Math.toDegrees(Math.tan((opp / distance)));
        rankArray.add(calcSlopeRank(slope));
      }
    }

    // Calculate rank
    for (Integer rank : rankArray) {
      rankTotal += rank;
    }
    rankAverage = rankTotal / rankArray.size();

    for (Double height : heightArray) {
      heightTotal += height;
    }
    finalHeight = heightTotal / heightArray.size();

    // truncate lat/lon
    finalLat = (int) lat;
    finalLon = (int) lon;

    return new DataTile(finalLat.doubleValue(), finalLon.doubleValue(), rankAverage, finalHeight);
  }
  public Geographic2dCoordinate destination(
      final double latitude,
      final double longitude,
      final double initialBearing,
      final double distance) {

    final double b = Math.toRadians(initialBearing);
    final double d = distance / sphere.getRadius();
    final double lat1 = Math.toRadians(latitude);
    final double lon1 = Math.toRadians(longitude);

    double lat2 = lat1 + d * Math.cos(b);
    final double dLat = lat2 - lat1;
    final double dPhi =
        Math.log(Math.tan(lat2 / 2 + Math.PI / 4) / Math.tan(lat1 / 2 + Math.PI / 4));
    final double q =
        (!Double.isNaN(dLat / dPhi)) ? dLat / dPhi : Math.cos(lat1); // E-W line gives dPhi=0

    final double dLon = d * Math.sin(b) / q;

    // check for some daft bugger going past the pole, normalise latitude if
    // so
    if (Math.abs(lat2) > Math.PI / 2) {
      lat2 = lat2 > 0 ? Math.PI - lat2 : -(Math.PI - lat2);
    }

    final double lon2 = (lon1 + dLon + Math.PI) % (2 * Math.PI) - Math.PI;

    return new Geographic2dCoordinate(Math.toDegrees(lat2), Math.toDegrees(lon2));
  }
Esempio n. 6
1
 /**
  * Computes the perimeter point on this shape, lying on the line from a given source point in the
  * direction of a target point. If the source and target point coincide, the point to the east of
  * the source point is returned.
  *
  * @param bounds bounds of the shape
  * @param px x-coordinate of source point;
  * @param py y-coordinate of source point;
  * @param q target point
  */
 Point2D getPerimeterPoint(Rectangle2D bounds, double px, double py, Point2D q) {
   // distances from source point to left, right, top and bottom edge
   double dxRight = bounds.getMaxX() - px;
   double dxLeft = px - bounds.getMinX();
   double dyBottom = bounds.getMaxY() - py;
   double dyTop = py - bounds.getMinY();
   // angles from source point to upper left, upper right, bottom left, bottom right corner
   double urPhi = Math.atan2(-dyTop, dxRight);
   double ulPhi = Math.atan2(-dyTop, -dxLeft);
   double brPhi = Math.atan2(dyBottom, dxRight);
   double blPhi = Math.atan2(dyBottom, -dxLeft);
   // compute angle from source to nextPoint
   double dx = q.getX() - px; // Compute Angle
   double dy = q.getY() - py;
   double alpha = Math.atan2(dy, dx);
   double x, y;
   double pi = Math.PI;
   if (alpha < ulPhi || alpha > blPhi) { // Left edge
     x = px - dxLeft;
     y = py - dxLeft * Math.tan(alpha);
   } else if (alpha < urPhi) { // Top Edge
     y = py - dyTop;
     x = px - dyTop * Math.tan(pi / 2 - alpha);
   } else if (alpha < brPhi) { // Right Edge
     x = px + dxRight;
     y = py + dxRight * Math.tan(alpha);
   } else { // Bottom Edge
     y = py + dyBottom;
     x = px + dyBottom * Math.tan(pi / 2 - alpha);
   }
   return new Point2D.Double(x, y);
 }
Esempio n. 7
1
  /**
   * <u>Berechnen des Tangens der komplexen Zahl</u><br>
   *
   * @param comp Komplexe Zahl
   * @return R&uuml;ckgabe eines Objektes vom Typ Complex mit L&ouml;sung aus tan(<u>z</u>)
   */
  public static Complex tan(Complex comp) {
    double real, imag;
    double nn =
        1d
            + Math.pow(
                Math.tan(comp.getReal()) * Math.tanh(comp.getImag()), 2); // Nenner der Brueche

    real = (Math.tan(comp.getReal()) * (1 - Math.pow(Math.tanh(comp.getImag()), 2))) / nn;
    imag = (Math.tanh(comp.getImag()) * (1 + Math.pow(Math.tan(comp.getReal()), 2))) / nn;

    return new Complex(real, imag);
  }
  /*
   * Draws gnomon with base at bottom.  Again, coordinate system is translated to commonly used coordinate system.
   */
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D img = (Graphics2D) g;

    img.translate(0, this.getHeight());
    img.drawString("Gnomon angle", 20, -5);
    img.scale(1.0, -1.0);
    double x, y;

    // baseLine is the bottom, hLine is the height of the gnomon, angleLine is the style (diagonal
    // portion)
    Line2D baseLine, hLine, angleLine;

    if (gnomonAngle
        < Math.atan(
            this.getHeight() / (this.getWidth() / 2))) { // style will extend to center of image
      y = Math.tan(gnomonAngle) * (this.getWidth() / 2);
      baseLine = new Line2D.Double(0, 0, this.getWidth() / 2, 0);
      hLine = new Line2D.Double(this.getWidth() / 2, 0, this.getWidth() / 2, y);
      angleLine = new Line2D.Double(0, 0, this.getWidth() / 2, y);
    } else { // style needs to be closer to maintain the angle
      x = this.getHeight() / Math.tan(gnomonAngle);
      baseLine = new Line2D.Double(0, 0, x, 0);
      hLine = new Line2D.Double(x, 0, x, this.getHeight());
      angleLine = new Line2D.Double(0, 0, x, this.getHeight());
    }

    img.draw(baseLine);
    img.draw(hLine);
    img.draw(angleLine);
  }
Esempio n. 9
0
  @Override
  protected void transformInverse(int x, int y, float[] out) {
    float dx = x - icentreX;
    float dy = y - icentreY;
    float x2 = dx * dx;
    float y2 = dy * dy;
    if (y2 >= (b2 - (b2 * x2) / a2)) {
      out[0] = x;
      out[1] = y;
    } else {
      float rRefraction = 1.0f / refractionIndex;

      float z = (float) Math.sqrt((1.0f - x2 / a2 - y2 / b2) * (a * b));
      float z2 = z * z;

      float xAngle = (float) Math.acos(dx / Math.sqrt(x2 + z2));
      float angle1 = ImageMath.HALF_PI - xAngle;
      float angle2 = (float) Math.asin(Math.sin(angle1) * rRefraction);
      angle2 = ImageMath.HALF_PI - xAngle - angle2;
      out[0] = x - (float) Math.tan(angle2) * z;

      float yAngle = (float) Math.acos(dy / Math.sqrt(y2 + z2));
      angle1 = ImageMath.HALF_PI - yAngle;
      angle2 = (float) Math.asin(Math.sin(angle1) * rRefraction);
      angle2 = ImageMath.HALF_PI - yAngle - angle2;
      out[1] = y - (float) Math.tan(angle2) * z;
    }
  }
  /**
   * Get the x destination based on the velocity
   *
   * @param xValue
   * @param yValue
   * @return
   * @since 1.0
   */
  private int[] getDestScrollPos(int xValue, int yValue) {

    int[] pos = new int[2];

    if (mIsOpen) {
      return pos;
    } else {

      switch (mScreenSide) {
        case STICK_TO_RIGHT:
          pos[0] = -getWidth() + mOffsetWidth;
          break;
        case STICK_TO_LEFT:
          pos[0] = getWidth() - mOffsetWidth;
          break;
        case STICK_TO_TOP:
          pos[1] = getHeight() - mOffsetWidth;
          break;
        case STICK_TO_BOTTOM:
          pos[1] = -getHeight() + mOffsetWidth;
          break;
        case STICK_TO_MIDDLE:

          // Calculate slope m to get direction of swiping and apply the same vector until the end
          // of the
          // animation
          float m = 1;

          // If no veocity nor translation (difficult to get) the target is random
          if (xValue == 0 && yValue == 0) {
            m = mRandom != null ? (float) Math.tan(mRandom.nextFloat() * Math.PI - Math.PI / 2) : 1;
          } else if (xValue == 0) {
            // Avoid division by 0 (Get the max value of the tan which is equivalent)
            m = (float) Math.tan(Math.PI / 2);
          } else {
            // Get slope
            m = yValue / (float) xValue;
          }

          if (Math.abs(m) >= 1) {
            pos[0] =
                Math.round(
                    getOperationSignForDiffMeasure(xValue) * getHeight() / Math.abs(m)
                        - (mLastX - getWidth() / 2));
            pos[1] = Math.round(getOperationSignForDiffMeasure(yValue) * getHeight());
          } else {
            pos[0] = Math.round(getOperationSignForDiffMeasure(xValue) * getWidth());
            pos[1] =
                Math.round(
                    getOperationSignForDiffMeasure(yValue) * getWidth() * Math.abs(m)
                        - (mLastY - getHeight() / 2));
          }
          break;
      }

      return pos;
    }
  }
Esempio n. 11
0
 /**
  * Returns the <a href="http://en.wikipedia.org/wiki/Rhumb_line">rhumb line</a> bearing from the
  * current location to the GeoLocation passed in.
  *
  * @param location destination location
  * @return the bearing in degrees
  */
 public double getRhumbLineBearing(GeoLocation location) {
   double dLon = Math.toRadians(location.getLongitude() - getLongitude());
   double dPhi =
       Math.log(
           Math.tan(Math.toRadians(location.getLatitude()) / 2 + Math.PI / 4)
               / Math.tan(Math.toRadians(getLatitude()) / 2 + Math.PI / 4));
   if (Math.abs(dLon) > Math.PI) dLon = dLon > 0 ? -(2 * Math.PI - dLon) : (2 * Math.PI + dLon);
   return Math.toDegrees(Math.atan2(dLon, dPhi));
 }
Esempio n. 12
0
  private double[] createSides() {

    double sideA = this.base;
    double sideB = (Math.abs(this.height / Math.sin(this.angle)));
    double sideC =
        Math.sqrt(
            (this.base - this.height / Math.tan(this.angle))
                    * (this.base - this.height / Math.tan(this.angle))
                + this.height * this.height);
    double[] arrayOfSides = {sideA, sideB, sideC};
    return arrayOfSides;
  }
Esempio n. 13
0
  public static void main(String[] args) {
    // scale of the coordinate system
    StdDraw.setXscale(-1.0, 1.0);
    StdDraw.setYscale(-1.0, 1.0);

    double rx = 0.0, ry = 0.0;
    double rx2 = rx + 0.10, ry2 = ry + 0.10;
    double rx3 = rx2 + 0.10, ry3 = ry2 + 0.10;
    double vx = 0.005, vy = 0.003;
    double vx2 = vx + 0.05, vy2 = vy + 0.05;
    double vx3 = vx2 + 0.05, vy3 = vy2 + 0.05;
    double radius = 0.10;

    // main loop
    while (true) {
      // bounce off wall according to law of elastic collision
      if (Math.abs(rx + vx) > 1.0 - radius) vx = -vx;
      if (Math.abs(ry + vy) > 1.0 - radius) vy = -vy;
      if (Math.abs(rx2 + vx2) > 1.0 - radius) vx2 = -vx2;
      if (Math.abs(ry2 + vy2) > 1.0 - radius) vy2 = -vy2;
      if (Math.abs(rx3 + vx3) > 1.0 - radius) vx3 = -vx3;
      if (Math.abs(ry3 + vy3) > 1.0 - radius) vy3 = -vy3;

      // position
      rx += vx;
      ry += vy;

      rx2 = vx2 / Math.tan(vy / vx);
      ry2 = vy2 / Math.tan(vy / vx);

      rx3 += vx3;
      ry3 += vy3;

      // clear
      StdDraw.setPenColor(StdDraw.GRAY);
      StdDraw.filledSquare(0, 0, 1.0);

      // ball
      StdDraw.setPenColor(StdDraw.BLUE);
      StdDraw.filledCircle(rx, ry, radius);

      // ball2
      StdDraw.setPenColor(StdDraw.BLACK);
      StdDraw.filledCircle(rx2, ry2, radius / 2);

      // ball3
      StdDraw.setPenColor(StdDraw.YELLOW);
      StdDraw.filledCircle(rx3, ry3, radius / 2);

      // display and pause for 20 ms
      StdDraw.show(20);
    }
  }
Esempio n. 14
0
  public void prect(Coord c, Coord ul, Coord br, double a) {
    st.set(cur2d);
    apply();
    gl.glEnable(GL2.GL_POLYGON_SMOOTH);
    gl.glBegin(GL.GL_TRIANGLE_FAN);
    vertex(c);
    vertex(c.add(0, ul.y));
    double p2 = Math.PI / 2;
    all:
    {
      float tc;

      tc = (float) (Math.tan(a) * -ul.y);
      if ((a > p2) || (tc > br.x)) {
        vertex(c.x + br.x, c.y + ul.y);
      } else {
        vertex(c.x + tc, c.y + ul.y);
        break all;
      }

      tc = (float) (Math.tan(a - (Math.PI / 2)) * br.x);
      if ((a > p2 * 2) || (tc > br.y)) {
        vertex(c.x + br.x, c.y + br.y);
      } else {
        vertex(c.x + br.x, c.y + tc);
        break all;
      }

      tc = (float) (-Math.tan(a - Math.PI) * br.y);
      if ((a > p2 * 3) || (tc < ul.x)) {
        vertex(c.x + ul.x, c.y + br.y);
      } else {
        vertex(c.x + tc, c.y + br.y);
        break all;
      }

      tc = (float) (-Math.tan(a - (3 * Math.PI / 2)) * -ul.x);
      if ((a > p2 * 4) || (tc < ul.y)) {
        vertex(c.x + ul.x, c.y + ul.y);
      } else {
        vertex(c.x + ul.x, c.y + tc);
        break all;
      }

      tc = (float) (Math.tan(a) * -ul.y);
      vertex(c.x + tc, c.y + ul.y);
    }
    gl.glEnd();
    gl.glDisable(GL2.GL_POLYGON_SMOOTH);
    checkerr();
  }
 public double count() throws Exception {
   Deque<Double> ans = new ArrayDeque(10);
   for (Elem elem : deq) {
     if (elem.type == ElemType.NUM) {
       ans.addLast((Double) elem.value);
     } else if (elem.type == ElemType.VAR) {
       String f = (String) elem.value;
       if (f.equalsIgnoreCase("t")) {
         ans.addLast((double) time);
       } else if (f.equalsIgnoreCase("w")) {
         ans.addLast((double) w);
       } else if (f.equalsIgnoreCase("pi")) {
         ans.addLast(Math.PI);
       } else {
         throw new Exception("Unknown variable: \'" + f + "\'");
       }
     } else {
       String f = (String) elem.value;
       if (f.equals("+")) {
         ans.addLast(ans.pollLast() + ans.pollLast());
       } else if (f.equals("-")) {
         ans.addLast(-ans.pollLast() + ans.pollLast());
       } else if (f.equals("*")) {
         ans.addLast(ans.pollLast() * ans.pollLast());
       } else if (f.equals("/")) {
         ans.addLast(1d / ans.pollLast() * ans.pollLast());
       } else if (f.equalsIgnoreCase("cos")) {
         ans.addLast(Math.cos(ans.pollLast()));
       } else if (f.equalsIgnoreCase("sin")) {
         ans.addLast(Math.sin(ans.pollLast()));
       } else if (f.equalsIgnoreCase("tg") || f.equalsIgnoreCase("tan")) {
         ans.addLast(Math.tan(ans.pollLast()));
       } else if (f.equalsIgnoreCase("ctg")) {
         ans.addLast(1d / Math.tan(ans.pollLast()));
       } else if (f.equalsIgnoreCase("abs")) {
         ans.addLast(Math.abs(ans.pollLast()));
       } else if (f.equalsIgnoreCase("sign")) {
         ans.addLast(Math.signum(ans.pollLast()));
       } else if (f.equalsIgnoreCase("exp")) {
         ans.addLast(Math.exp(ans.pollLast()));
       } else if (f.equalsIgnoreCase("ln")) {
         ans.addLast(Math.log(ans.pollLast()));
       } else if (f.equalsIgnoreCase("lg")) {
         ans.addLast(Math.log10(ans.pollLast()));
       } else {
         throw new Exception("Unknown function: \'" + f + "\'");
       }
     }
   }
   return ans.getFirst();
 }
 private EyeViewport initViewportForEye(final FieldOfView fov, final float xOffset) {
   final float left = (float) Math.tan(Math.toRadians(fov.getLeft()));
   final float right = (float) Math.tan(Math.toRadians(fov.getRight()));
   final float bottom = (float) Math.tan(Math.toRadians(fov.getBottom()));
   final float top = (float) Math.tan(Math.toRadians(fov.getTop()));
   final EyeViewport vp = new EyeViewport();
   vp.x = xOffset;
   vp.y = 0.0f;
   vp.width = left + right;
   vp.height = bottom + top;
   vp.eyeX = left + xOffset;
   vp.eyeY = bottom;
   return vp;
 }
Esempio n. 17
0
 /**
  * Returns the <a href="http://en.wikipedia.org/wiki/Rhumb_line">rhumb line</a> distance from the
  * current location to the GeoLocation passed in.
  *
  * @param location the destination location
  * @return the distance in Meters
  */
 public double getRhumbLineDistance(GeoLocation location) {
   double R = 6371; // earth's mean radius in km
   double dLat = Math.toRadians(location.getLatitude() - getLatitude());
   double dLon = Math.toRadians(Math.abs(location.getLongitude() - getLongitude()));
   double dPhi =
       Math.log(
           Math.tan(Math.toRadians(location.getLongitude()) / 2 + Math.PI / 4)
               / Math.tan(Math.toRadians(getLatitude()) / 2 + Math.PI / 4));
   double q = (Math.abs(dLat) > 1e-10) ? dLat / dPhi : Math.cos(Math.toRadians(getLatitude()));
   // if dLon over 180° take shorter rhumb across 180° meridian:
   if (dLon > Math.PI) dLon = 2 * Math.PI - dLon;
   double d = Math.sqrt(dLat * dLat + q * q * dLon * dLon);
   return d * R;
 }
Esempio n. 18
0
  static double getAssr(double lat, double dec, int mathhab) {
    double part1, part2, part3, part4;
    double rlat = Astronomy.DEG_TO_RAD(lat);

    part1 = mathhab + Math.tan(rlat - dec);
    if ((part1 < 1) || (lat < 0)) part1 = mathhab - Math.tan(rlat - dec);

    part2 = (Astronomy.PI / 2.0) - mMath.atan(part1);
    part3 = Math.sin(part2) - Math.sin(rlat) * Math.sin(dec);
    part4 = (part3 / (Math.cos(rlat) * Math.cos(dec)));

    if (part4 < -Astronomy.INVALID_TRIGGER || part4 > Astronomy.INVALID_TRIGGER) return 99;

    return Astronomy.DEG_TO_10_BASE * Astronomy.RAD_TO_DEG(mMath.acos(part4));
  }
Esempio n. 19
0
 /** {@inheritDoc} */
 @Override
 double distanceBetween(
     double latitude1, double longitude1, double latitude2, double longitude2) {
   double lat1 = Math.toRadians(latitude1);
   double lat2 = Math.toRadians(latitude2);
   double dLat = Math.toRadians(latitude2 - latitude1);
   double dLon = Math.toRadians(Math.abs(longitude2 - longitude1));
   double dPhi = Math.log(Math.tan(lat2 / 2 + Math.PI / 4) / Math.tan(lat1 / 2 + Math.PI / 4));
   double q = dPhi == 0 ? Math.cos(lat1) : dLat / dPhi;
   // if dLon over 180 take shorter rhumb across 180 meridian:
   if (dLon > Math.PI) {
     dLon = 2 * Math.PI - dLon;
   }
   return Math.sqrt(dLat * dLat + q * q * dLon * dLon) * EARTH_MEAN_RADIUS_KM * 1000;
 }
Esempio n. 20
0
  // turn the camera in its current plane
  private void turnYaw(double roll) {
    // Up cross focus for left vector
    Vec3 left = persp.cross(up);

    // Normalize left vector
    left = left.normalize();

    // Move up vector
    persp.x += (Math.tan(roll) * left.x);
    persp.y += (Math.tan(roll) * left.y);
    persp.z += (Math.tan(roll) * left.z);

    // Normalize persp vector
    persp = persp.normalize();
  }
Esempio n. 21
0
  public IsoHDPerspective(ConfigurationNode configuration) {
    name = configuration.getString("name", null);
    if (name == null) {
      Log.severe("Perspective definition missing name - must be defined and unique");
      return;
    }
    azimuth =
        configuration.getDouble("azimuth", 135.0); /* Get azimuth (default to classic kzed POV */
    inclination = configuration.getDouble("inclination", 60.0);
    if (inclination > MAX_INCLINATION) inclination = MAX_INCLINATION;
    if (inclination < MIN_INCLINATION) inclination = MIN_INCLINATION;
    scale = configuration.getDouble("scale", MIN_SCALE);
    if (scale < MIN_SCALE) scale = MIN_SCALE;
    if (scale > MAX_SCALE) scale = MAX_SCALE;
    /* Get max and min height */
    maxheight = configuration.getInteger("maximumheight", 127);
    if (maxheight > 127) maxheight = 127;
    minheight = configuration.getInteger("minimumheight", 0);
    if (minheight < 0) minheight = 0;

    /* Generate transform matrix for world-to-tile coordinate mapping */
    /* First, need to fix basic coordinate mismatches before rotation - we want zero azimuth to have north to top
     * (world -X -> tile +Y) and east to right (world -Z to tile +X), with height being up (world +Y -> tile +Z)
     */
    Matrix3D transform = new Matrix3D(0.0, 0.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    /* Next, rotate world counterclockwise around Z axis by azumuth angle */
    transform.rotateXY(180 - azimuth);
    /* Next, rotate world by (90-inclination) degrees clockwise around +X axis */
    transform.rotateYZ(90.0 - inclination);
    /* Finally, shear along Z axis to normalize Z to be height above map plane */
    transform.shearZ(0, Math.tan(Math.toRadians(90.0 - inclination)));
    /* And scale Z to be same scale as world coordinates, and scale X and Y based on setting */
    transform.scale(scale, scale, Math.sin(Math.toRadians(inclination)));
    world_to_map = transform;
    /* Now, generate map to world tranform, by doing opposite actions in reverse order */
    transform = new Matrix3D();
    transform.scale(1.0 / scale, 1.0 / scale, 1 / Math.sin(Math.toRadians(inclination)));
    transform.shearZ(0, -Math.tan(Math.toRadians(90.0 - inclination)));
    transform.rotateYZ(-(90.0 - inclination));
    transform.rotateXY(-180 + azimuth);
    Matrix3D coordswap = new Matrix3D(0.0, -1.0, 0.0, 0.0, 0.0, 1.0, -1.0, 0.0, 0.0);
    transform.multiply(coordswap);
    map_to_world = transform;
    /* Scaled models for non-cube blocks */
    modscale = (int) Math.ceil(scale);
    scalemodels = HDBlockModels.getModelsForScale(modscale);
    ;
  }
Esempio n. 22
0
  /**
   * Set the projection matrix, similar to glmLocalTranslationerspective.
   *
   * @param fovy Field of view angle in y coordinate
   * @param width Width of screen
   * @param height Height of screen
   * @param zNear Distance to near-plane
   * @param zFar Distance to far-plane
   */
  public static void setPerspective(
      float fovy, float width, float height, float zNear, float zFar) {
    float tan_fovy_half = (float) Math.tan((fovy * DEG_TO_RAD) / 2);
    Camera.mNearHeight = zNear * tan_fovy_half;
    Camera.mZNear = zNear;
    Camera.mHeight = height;
    Camera.mHalfWidth = width / 2;
    Camera.mHalfHeight = height / 2;
    Camera.mAspect = width / height;
    mProjectionMatrix[5] = 1 / tan_fovy_half; // = cot(fovy/2)

    // Remember, column major matrix
    mProjectionMatrix[0] = mProjectionMatrix[5] / mAspect;
    mProjectionMatrix[1] = 0.0f;
    mProjectionMatrix[2] = 0.0f;
    mProjectionMatrix[3] = 0.0f;

    mProjectionMatrix[4] = 0.0f;
    // project[5] = 1 / near_height;  // already set
    mProjectionMatrix[6] = 0.0f;
    mProjectionMatrix[7] = 0.0f;

    mProjectionMatrix[8] = 0.0f;
    mProjectionMatrix[9] = 0.0f;
    mProjectionMatrix[10] = (zFar + zNear) / (zNear - zFar);
    mProjectionMatrix[11] = -1.0f;

    mProjectionMatrix[12] = 0.0f;
    mProjectionMatrix[13] = 0.0f;
    mProjectionMatrix[14] = (2 * zFar * zNear) / (zNear - zFar);
    mProjectionMatrix[15] = 0.0f;
  }
Esempio n. 23
0
  @Test
  public void testOperators() {
    try {
      assertEquals(2d, Expression.evaluate("1 + 1").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(0d, Expression.evaluate("1 - 1").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(2d, Expression.evaluate("1 * 2").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(2d, Expression.evaluate("6 / 3").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(2d, Expression.evaluate("6 % 4").toDouble(), FuzzyEquals.TOLERANCE);

      assertTrue(Expression.evaluate("true && true").toBoolean());
      assertFalse(Expression.evaluate("true AND false").toBoolean());
      assertTrue(Expression.evaluate("true || true").toBoolean());
      assertTrue(Expression.evaluate("true OR false").toBoolean());
      assertFalse(Expression.evaluate("not(true)").toBoolean());

      assertEquals(6d, Expression.evaluate("max(2,3,6)").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(2d, Expression.evaluate("min(2,3,6)").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(2d, Expression.evaluate("floor(2.2)").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(4d, Expression.evaluate("ceil(3.6)").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(-3d, Expression.evaluate("neg(3)").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(3d, Expression.evaluate("abs(neg(3))").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(
          Math.cos(Math.toRadians(180)),
          Expression.evaluate("cos(rad(180))").toDouble(),
          FuzzyEquals.TOLERANCE);
      assertEquals(
          Math.sin(Math.toRadians(90)),
          Expression.evaluate("sin(rad(90))").toDouble(),
          FuzzyEquals.TOLERANCE);
      assertEquals(
          Math.tan(Math.toRadians(45)),
          Expression.evaluate("tan(rad(45))").toDouble(),
          FuzzyEquals.TOLERANCE);
      assertEquals(Math.acos(0), Expression.evaluate("acos(0)").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(
          Math.asin(180), Expression.evaluate("asin(180)").toDouble(), FuzzyEquals.TOLERANCE);
      assertEquals(Math.atan(1), Expression.evaluate("atan(1)").toDouble(), FuzzyEquals.TOLERANCE);

      assertTrue(Expression.evaluate("1 == 1").toBoolean());
      assertTrue(Expression.evaluate("1 > 0").toBoolean());
      assertTrue(Expression.evaluate("1 < 2").toBoolean());
      assertTrue(Expression.evaluate("1 <= 2").toBoolean());

      assertTrue(Expression.evaluate("1 >= 1").toBoolean());

      assertEquals("b", Expression.evaluate("substr(abcd,1,2)").toString());

      Expression exp = new Expression("dateDifference(01/01/2006, 01/05/2006, |DAY|)");
      exp.setResolver(new SimpleResolver());
      assertEquals(4d, exp.evaluate().toDouble(), FuzzyEquals.TOLERANCE);

      exp = new Expression("max(1, 2, NULL)");
      exp.setResolver(new SimpleResolver());
      assertEquals("max(1, 2, NULL)", exp.evaluate().toString());

    } catch (InvalidExpressionException e) {
      e.printStackTrace();
      fail();
    }
  }
Esempio n. 24
0
 public Point findPositionToShootFrom(Point goal, Point ball) {
   int height = Math.abs(goal.y - ball.y);
   int width = Math.abs(goal.x - ball.x);
   double angle = Math.toDegrees(Math.tan(height / width));
   Point c = new Point((int) (50 * Math.cos(angle)), (int) (50 * Math.sin(angle)));
   return c;
 }
  public ObservationElement tan() {
    if (isCompartment) {
      throw new RuntimeException("not implemented");
    }

    return new ObservationElement((float) Math.tan(value));
  }
Esempio n. 26
0
  public static Transform perspective(
      final double fieldOfView, final double nearPlane, final double farPlane) {
    final Matrix matrix =
        Matrix.newInstance(
            1.0D,
            0.0D,
            0.0D,
            0.0D,
            0.0D,
            1.0D,
            0.0D,
            0.0D,
            0.0D,
            0.0D,
            farPlane / (farPlane - nearPlane),
            -farPlane * nearPlane / (farPlane - nearPlane),
            0.0D,
            0.0D,
            1.0D,
            0.0D);

    final double angle = 1.0D / Math.tan(Math.toRadians(fieldOfView) * 0.5D);

    return scale(angle, angle, 1.0D).multiply(newInstance(matrix));
  }
Esempio n. 27
0
 public void calcul() {
   if (op.equals("+")) {
     nb1 = nb1 + Double.valueOf(lab.getText()).doubleValue();
   }
   if (op.equals("-")) {
     nb1 = nb1 - Double.valueOf(lab.getText()).doubleValue();
   }
   if (op.equals("*")) {
     nb1 = nb1 * Double.valueOf(lab.getText()).doubleValue();
   }
   if (op.equals("%")) {
     nb1 = nb1 % Double.valueOf(lab.getText()).doubleValue();
   }
   if (op.equals("/")) {
     if (Double.valueOf(lab.getText()).doubleValue() == 0) {
       lab.setText("Error: divide by 0");
       return;
     }
     nb1 = nb1 / Double.valueOf(lab.getText()).doubleValue();
   }
   if (op.equals("x²")) nb1 = Math.pow(Double.valueOf(lab.getText()).doubleValue(), 2.0);
   if (op.equals("√")) nb1 = Math.sqrt(Double.valueOf(lab.getText()).doubleValue());
   if (op.equals("log")) nb1 = Math.log(Double.valueOf(lab.getText()).doubleValue());
   if (op.equals("exp")) nb1 = Math.exp(Double.valueOf(lab.getText()).doubleValue());
   if (op.equals("cos")) nb1 = Math.cos(Double.valueOf(lab.getText()).doubleValue());
   if (op.equals("tan")) nb1 = Math.tan(Double.valueOf(lab.getText()).doubleValue());
   if (op.equals("sin")) nb1 = Math.sin(Double.valueOf(lab.getText()).doubleValue());
   int n = do_precision(String.valueOf(nb1));
   lab.setText(String.format("%." + String.valueOf(n) + "f", nb1));
 }
Esempio n. 28
0
 /**
  * @param near near clipping space
  * @param far far clipping space
  * @param fov field of view in degrees
  * @param aspect aspect ratio (width/height)
  * @return a perspective projection matrix
  */
 public static Matrix projectPerspectiveRH(double fov, double aspect, double near, double far) {
   double ymax = near * Math.tan((fov) * 0.5);
   double ymin = -ymax;
   double xmin = ymin * aspect;
   double xmax = ymax * aspect;
   return projectFrustum(xmin, xmax, ymin, ymax, near, far);
 }
Esempio n. 29
0
  protected Point2D getCrossPointWithSide(
      Point2D point,
      double rotationAngleInDegrees,
      double fieldWidth,
      double fieldHeight,
      GameState.SystemSides side) {
    double centerX = point.getX(), centerY = point.getY();

    double angle = (rotationAngleInDegrees + 360) % 360;

    if (angle == 90) {
      return new Point2D(centerX, fieldHeight);
    } else if (angle == 270) {
      return new Point2D(centerX, 0);
    }

    double a = Math.tan(Math.toRadians(angle));
    double b = centerY - a * centerX;

    switch (side) {
      case Right:
        return new Point2D(fieldWidth, a * fieldWidth + b);
      case Down:
        return new Point2D((fieldHeight - b) / a, fieldHeight);
      case Left:
        return new Point2D(0, b);
      case Up:
        return new Point2D(-b / a, 0);
      default:
        return new Point2D(0, 0);
    }
  }
Esempio n. 30
0
 @Test
 public void testTan() {
   for (double doubleValue : DOUBLE_VALUES) {
     assertFunction("tan(" + doubleValue + ")", DOUBLE, Math.tan(doubleValue));
   }
   assertFunction("tan(NULL)", DOUBLE, null);
 }