/**
  * Superduperformula.
  *
  * @param r0 the r0
  * @param u the u
  * @param v the v
  * @param c1 the c1
  * @param c2 the c2
  * @param c3 the c3
  * @param m1 the m1
  * @param n11 the n11
  * @param n12 the n12
  * @param n13 the n13
  * @param m2 the m2
  * @param n21 the n21
  * @param n22 the n22
  * @param n23 the n23
  * @param t1 the t1
  * @param t2 the t2
  * @param d1 the d1
  * @param d2 the d2
  * @return the w b_ point3d
  */
 private WB_Point superduperformula(
     final double r0,
     double u,
     double v,
     final double c1,
     final double c2,
     final double c3,
     final double m1,
     final double n11,
     final double n12,
     final double n13,
     final double m2,
     final double n21,
     final double n22,
     final double n23,
     final double t1,
     double t2,
     double d1,
     double d2) {
   final double t2c = (r0 * Math.pow(c2, d2) * t2 * c1) / 2;
   t2 = t2 * c1 * u;
   d1 = Math.pow(u * c1, d1);
   d2 = Math.pow(u * c2, d2);
   u = lerp(-Math.PI, Math.PI, u) * c1;
   v = lerp(-Math.PI / 2, Math.PI / 2, v) * c2;
   final double v2 = v + (c3 * u);
   final double r1 = superformula(u, 1, 1, m1, n11, n12, n13);
   final double r2 = superformula(v, 1, 1, m2, n21, n22, n23);
   final double x = r0 * r1 * (t1 + (d1 * r2 * Math.cos(v2))) * Math.sin(u);
   final double y = r0 * r1 * (t1 + (d1 * r2 * Math.cos(v2))) * Math.cos(u);
   final double z = (r0 * d2 * ((r2 * Math.sin(v2)) - t2)) + t2c;
   return new WB_Point(x, y, z);
 }
Esempio n. 2
1
  public double totalLength() {
    double totalDistance = 0;

    for (int j = 0; j < trkpts.size() - 1; j++) {
      GPXtrkpt pt1 = trkpts.get(j);
      GPXtrkpt pt2 = trkpts.get(j + 1);

      // convert lat and lon from degrees to radians
      double lat1 = pt1.getLatitude() * 2 * Math.PI / 360.0;
      double lon1 = pt1.getLongitude() * 2 * Math.PI / 360.0;
      double lat2 = pt2.getLatitude() * 2 * Math.PI / 360.0;
      double lon2 = pt2.getLongitude() * 2 * Math.PI / 360.0;

      // use the spherical law of cosines to figure out 2D distance
      double d =
          Math.acos(
                  Math.sin(lat1) * Math.sin(lat2)
                      + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1))
              * R;
      // now we need to take the change in elevation into account
      double ele1 = pt1.getElevation();
      double ele2 = pt2.getElevation();

      // calculate the 3D distance
      double distance = Math.sqrt(d * d + (ele1 - ele2) * (ele1 - ele2));

      // add it to the running total
      totalDistance += distance;
    }
    return totalDistance;
  }
  private double[] rtll(double lon, double lat, double lonSp, double latSp) {
    double[] all = new double[2];

    double dtr = Math.PI / 180.;

    double pole_lat = 90.0 + latSp;
    double pole_lon = lonSp;

    double ctph0 = Math.cos(pole_lat * dtr);
    double stph0 = Math.sin(pole_lat * dtr);

    double stph = Math.sin(lat * dtr);
    double ctph = Math.cos(lat * dtr);
    double ctlm = Math.cos(lon * dtr);
    double stlm = Math.sin(lon * dtr);

    // aph=asin(stph0.*ctph.*ctlm+ctph0.*stph);
    double aph = Math.asin((stph0 * ctph * ctlm) + (ctph0 * stph));

    // cph=cos(aph);
    double cph = Math.cos(aph);

    // almd=tlm0d+asin(stlm.*ctph./cph)/dtr;
    all[0] = pole_lon + (Math.asin((stlm * ctph) / cph) / dtr);
    // aphd=aph/dtr;
    all[1] = aph / dtr;

    return all;
  }
Esempio n. 4
1
  public static int getDistance(
      double latitude1, double longitude1, double latitude2, double longitude2) {
    double lat1 = latitude1 * Math.PI / 180;
    double lat2 = latitude2 * Math.PI / 180;
    double long1 = longitude1 * Math.PI / 180;
    double long2 = longitude2 * Math.PI / 180;

    double cosl1 = Math.cos(lat1);
    double cosl2 = Math.cos(lat2);
    double sinl1 = Math.sin(lat1);
    double sinl2 = Math.sin(lat2);

    double delta = long2 - long1;
    double cosdelta = Math.cos(delta);
    double sindelta = Math.sin(delta);

    double y =
        Math.sqrt(
            Math.pow(cosl2 * sindelta, 2) + Math.pow(cosl1 * sinl2 - sinl1 * cosl2 * cosdelta, 2));
    double x = sinl1 * sinl2 + cosl1 * cosl2 * cosdelta;
    double ad = Math.atan2(y, x);
    double dist = ad * radius;

    return (int) dist;
  }
Esempio n. 5
0
  public void closeSumWithChamfer(
      double startAngle, double endAngle, double size, boolean rounded) {
    if (endAngle > AngleUtil.RIGHT || startAngle > endAngle) {
      throw new IllegalArgumentException();
    }

    double angle = endAngle - startAngle;

    int nbFaces;
    if (rounded) {
      nbFaces = 5;
    } else {
      nbFaces = 1;
    }

    double currentHorOffset = -size * (1 - Math.cos(startAngle));
    double currentVertOffset = size * Math.sin(startAngle);
    for (int i = 0; i < nbFaces; i++) {
      double horOffset = -size * (1 - Math.cos(startAngle + angle / nbFaces * (i + 1)));
      double vertOffset = size * Math.sin(startAngle + angle / nbFaces * (i + 1));

      if (nbFaces != 1) {
        setHorizontalNormal(
            startAngle + angle / nbFaces * (i + 1), startAngle + angle / nbFaces * i);
      }
      extrudeToFrustum(horOffset - currentHorOffset, top + vertOffset - currentVertOffset);

      currentHorOffset = horOffset;
      currentVertOffset = vertOffset;
    }
    closeSum();
  }
Esempio n. 6
0
  public Complex tanh() {
    double scalar;
    double temp1Re, temp1Im;
    double temp2Re, temp2Im;
    Complex sinRes, cosRes;
    //  tanh(z)  =  sinh(z) / cosh(z)

    scalar = Math.exp(re);
    temp1Re = scalar * Math.cos(im);
    temp1Im = scalar * Math.sin(im);

    scalar = Math.exp(-re);
    temp2Re = scalar * Math.cos(-im);
    temp2Im = scalar * Math.sin(-im);

    temp1Re -= temp2Re;
    temp1Im -= temp2Im;

    sinRes = new Complex(0.5 * temp1Re, 0.5 * temp1Im);

    scalar = Math.exp(re);
    temp1Re = scalar * Math.cos(im);
    temp1Im = scalar * Math.sin(im);

    scalar = Math.exp(-re);
    temp2Re = scalar * Math.cos(-im);
    temp2Im = scalar * Math.sin(-im);

    temp1Re += temp2Re;
    temp1Im += temp2Im;

    cosRes = new Complex(0.5 * temp1Re, 0.5 * temp1Im);

    return sinRes.div(cosRes);
  }
Esempio n. 7
0
  /** Returns the sine of this complex number. */
  public Complex sin() {
    double izRe, izIm;
    double temp1Re, temp1Im;
    double temp2Re, temp2Im;
    double scalar;

    //  sin(z)  =  ( exp(i*z) - exp(-i*z) ) / (2*i)
    izRe = -im;
    izIm = re;

    // first exp
    scalar = Math.exp(izRe);
    temp1Re = scalar * Math.cos(izIm);
    temp1Im = scalar * Math.sin(izIm);

    // second exp
    scalar = Math.exp(-izRe);
    temp2Re = scalar * Math.cos(-izIm);
    temp2Im = scalar * Math.sin(-izIm);

    temp1Re -= temp2Re;
    temp1Im -= temp2Im;

    return new Complex(0.5 * temp1Im, -0.5 * temp1Re);
  }
Esempio n. 8
0
 static void drawTorus(float r, float R, int nsides, int rings) {
   float ringDelta = 2.0f * (float) Math.PI / rings;
   float sideDelta = 2.0f * (float) Math.PI / nsides;
   float theta = 0.0f, cosTheta = 1.0f, sinTheta = 0.0f;
   for (int i = rings - 1; i >= 0; i--) {
     float theta1 = theta + ringDelta;
     float cosTheta1 = (float) Math.cos(theta1);
     float sinTheta1 = (float) Math.sin(theta1);
     GL11.glBegin(GL11.GL_QUAD_STRIP);
     float phi = 0.0f;
     for (int j = nsides; j >= 0; j--) {
       phi += sideDelta;
       float cosPhi = (float) Math.cos(phi);
       float sinPhi = (float) Math.sin(phi);
       float dist = R + r * cosPhi;
       GL11.glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
       GL11.glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, r * sinPhi);
       GL11.glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
       GL11.glVertex3f(cosTheta * dist, -sinTheta * dist, r * sinPhi);
     }
     GL11.glEnd();
     theta = theta1;
     cosTheta = cosTheta1;
     sinTheta = sinTheta1;
   }
 }
  public Point2D.Double projectInverse(double xyx, double xyy, Point2D.Double out) {
    double t = 0;

    double lpphi = RYC * xyy;
    if (Math.abs(lpphi) > 1.) {
      if (Math.abs(lpphi) > ONETOL) {
        throw new ProjectionException("I");
      } else if (lpphi < 0.) {
        t = -1.;
        lpphi = -Math.PI;
      } else {
        t = 1.;
        lpphi = Math.PI;
      }
    } else {
      lpphi = 2. * Math.asin(t = lpphi);
    }
    out.x = RXC * xyx / (1. + 2. * Math.cos(lpphi) / Math.cos(0.5 * lpphi));
    lpphi = RC * (t + Math.sin(lpphi));
    if (Math.abs(lpphi) > 1.) {
      if (Math.abs(lpphi) > ONETOL) {
        throw new ProjectionException("I");
      } else {
        lpphi = lpphi < 0. ? -MapMath.HALFPI : MapMath.HALFPI;
      }
    } else {
      lpphi = Math.asin(lpphi);
    }
    out.y = lpphi;
    return out;
  }
Esempio n. 10
0
  // Tests to make sure the turret is not shooting another enemy.
  private boolean noFriendlyFire() {
    double xd = range * Math.cos(horizontalDir) * Math.cos(verticalDir),
        yd = range * Math.sin(horizontalDir) * Math.cos(verticalDir),
        zd = range * Math.sin(verticalDir);

    double t = w.getCollision().getBulletCollision(x, y, z + shotHeight, xd, yd, zd);
    double t2 = 1; // Bullet distance traveled before first detected collision
    Damageable entityToDamage = null;

    for (Entity entity : w.getEntities()) {
      if (entity == this) continue;
      if (!(entity instanceof Damageable) || entity == this) continue;

      Damageable e = (Damageable) entity;

      // tTest must be less than t2 to update it.
      double tTest =
          w.getCollision()
              .getEntityBulletCollision(x, y, z + shotHeight, xd * t, yd * t, zd * t, e);

      if (tTest < t2) {
        entityToDamage = e;
        t2 = tTest;
      }
    }

    if (t2 == 1) return true;

    if (entityToDamage instanceof Player) return true;

    return false;
  }
Esempio n. 11
0
  private void drawPointerArrow(Canvas canvas) {

    int centerX = getWidth() / 2;
    int centerY = getHeight() / 2;

    double tipAngle = (colorHSV[2] - 0.5f) * Math.PI;
    double leftAngle = tipAngle + Math.PI / 96;
    double rightAngle = tipAngle - Math.PI / 96;

    double tipAngleX = Math.cos(tipAngle) * outerWheelRadius;
    double tipAngleY = Math.sin(tipAngle) * outerWheelRadius;
    double leftAngleX = Math.cos(leftAngle) * (outerWheelRadius + arrowPointerSize);
    double leftAngleY = Math.sin(leftAngle) * (outerWheelRadius + arrowPointerSize);
    double rightAngleX = Math.cos(rightAngle) * (outerWheelRadius + arrowPointerSize);
    double rightAngleY = Math.sin(rightAngle) * (outerWheelRadius + arrowPointerSize);

    arrowPointerPath.reset();
    arrowPointerPath.moveTo((float) tipAngleX + centerX, (float) tipAngleY + centerY);
    arrowPointerPath.lineTo((float) leftAngleX + centerX, (float) leftAngleY + centerY);
    arrowPointerPath.lineTo((float) rightAngleX + centerX, (float) rightAngleY + centerY);
    arrowPointerPath.lineTo((float) tipAngleX + centerX, (float) tipAngleY + centerY);

    valuePointerArrowPaint.setColor(Color.HSVToColor(colorHSV));
    valuePointerArrowPaint.setStyle(Style.FILL);
    canvas.drawPath(arrowPointerPath, valuePointerArrowPaint);

    valuePointerArrowPaint.setStyle(Style.STROKE);
    valuePointerArrowPaint.setStrokeJoin(Join.ROUND);
    valuePointerArrowPaint.setColor(Color.BLACK);
    canvas.drawPath(arrowPointerPath, valuePointerArrowPaint);
  }
Esempio n. 12
0
  public void rotate(Direction direction, ArrayList<Quad> quads) {
    double theta;

    switch (direction) {
      case SOUTH:
        theta = (3 / 2) * Math.PI;
        break;
      case WEST:
        theta = Math.PI;
        break;
      case NORTH:
        theta = (1 / 2) * Math.PI;
        break;
      default:
        theta = 1;
    }

    for (int i = 0; i < quads.size(); i++) {
      Quad nq = new Quad(i, subtex);
      Quad q = quads.get(i);

      for (int j = 0; i < 4; i++) {
        Vertex v = q.getVertex(i);
        float x = (float) (v.getX() * Math.cos(theta) + v.getZ() * Math.sin(theta));
        float y = v.getY();
        float z = (float) (v.getX() * -Math.sin(theta) + v.getZ() * Math.cos(theta));
        nq.addVertex(j, x, y, z);
      }
      tempNewQuads.set(i, nq);
    }
  }
  @Override
  public void renderTileEntityAt(
      TileEntity tileentity, double d0, double d1, double d2, float partialTicks) {
    TileAnimationTablet tile = (TileAnimationTablet) tileentity;

    int meta = tile.getBlockMetadata() & 7;
    if (meta < 2) meta = 2; // Just in case

    int rotation = meta == 2 ? 270 : meta == 3 ? 90 : meta == 4 ? 0 : 180;

    GL11.glPushMatrix();
    GL11.glTranslated(d0, d1, d2);
    renderOverlay(tile, overlayCenter, -1, false, false, 0.65, 0.13F, 0F);
    if (tile.leftClick) renderOverlay(tile, overlayLeft, 1, false, true, 1, 0.13F, 0F);
    else renderOverlay(tile, overlayRight, 1, false, true, 1, 0.131F, 0F);
    renderOverlay(tile, overlayIndent, 0, false, false, 0.5F, 0.13F, rotation + 90F);

    GL11.glRotatef(rotation, 0F, 1F, 0F);
    GL11.glTranslated(0.1, 0.2 + Math.cos(System.currentTimeMillis() / 600D) / 18F, 0.5);
    float[] translations = TRANSLATIONS[meta - 2];
    GL11.glTranslatef(translations[0], translations[1], translations[2]);
    GL11.glScalef(0.8F, 0.8F, 0.8F);
    GL11.glTranslatef(0.5F, 0F, 0.5F);
    GL11.glRotatef(tile.swingProgress, 0F, 0F, 1F);
    GL11.glTranslatef(-0.5F, 0F, -0.5F);
    GL11.glTranslatef(-tile.swingProgress / 250F, tile.swingProgress / 1000F, 0F);
    GL11.glRotatef((float) Math.cos(System.currentTimeMillis() / 400F) * 5F, 1F, 0F, 1F);
    renderItem(tile);
    GL11.glPopMatrix();
  }
Esempio n. 14
0
  /**
   * Internal conversion routine.
   *
   * @param ned vector
   * @param latitude in radians.
   * @param longitude in radians
   * @param ecef vector
   */
  public void ned2ecef(double ned[], double latitude, double longitude, double ecef[]) {

    double temp[][] = new double[3][3];

    double clat = Math.cos(latitude);
    double clon = Math.cos(longitude);
    double slat = Math.sin(latitude);
    double slon = Math.sin(longitude);

    ned[0] = this.x;
    ned[1] = this.y;
    ned[2] = this.z;

    temp[0][0] = -slat * clon;
    temp[1][0] = -slat * slon;
    temp[2][0] = clat;

    temp[0][1] = -slon;
    temp[1][1] = clon;
    temp[2][1] = 0.0;

    temp[0][2] = -clat * clon;
    temp[1][2] = -clat * slon;
    temp[2][2] = -slat;

    for (int j = 0; j < 3; ++j) {
      ecef[j] = 0.0;
      for (int i = 0; i < 3; i++) ecef[j] += temp[j][i] * ned[i];
    }
  }
Esempio n. 15
0
  /**
   * Internal conversion routine.
   *
   * @param ned vector
   * @param latitude in radians.
   * @param longitude in radians
   * @param ecef vector
   */
  public void ecef2ned(double ned[], double latitude, double longitude, double ecef[]) {

    double temp[][] = new double[3][3];

    double clat = Math.cos(latitude);
    double clon = Math.cos(longitude);
    double slat = Math.sin(latitude);
    double slon = Math.sin(longitude);

    temp[0][0] = -slat * clon;
    temp[0][1] = -slat * slon;
    temp[0][2] = clat;

    temp[1][0] = -slon;
    temp[1][1] = clon;
    temp[1][2] = 0.0;

    temp[2][0] = -clat * clon;
    temp[2][1] = -clat * slon;
    temp[2][2] = -slat;

    for (int j = 0; j < 3; ++j) {
      ned[j] = 0.0;
      for (int i = 0; i < 3; i++) ned[j] += temp[j][i] * ecef[i];
    }
  }
Esempio n. 16
0
  public void drawHand(GraphicsContext gc, double speed) {
    int cx = width / 2;
    int cy = height / 2;

    gc.setFill(Color.BLACK);

    double Needle_angle = getRadFromSpeed(speed);

    int BigAxeX = (int) (0.8 * (((double) width) / 2.0));
    int BigAxeY = (int) (0.8 * (((double) height) / 2.0));
    int SmallAxeX = (int) (0.05 * (((double) width) / 2.0));
    int SmallAxeY = (int) (0.05 * (((double) height) / 2.0));

    int Nx = (int) ((double) BigAxeX * Math.sin(Needle_angle) + (double) cx);
    int Ny = (int) ((double) BigAxeY * Math.cos(Needle_angle) + (double) cy);
    int Sx = (int) ((double) SmallAxeX * Math.sin(Needle_angle - Math.PI) + (double) cx);
    int Sy = (int) ((double) SmallAxeX * Math.cos(Needle_angle - Math.PI) + (double) cy);
    int Ex = (int) ((double) SmallAxeX * Math.sin(Needle_angle - Math.PI / 2.0) + (double) cx);
    int Ey = (int) ((double) SmallAxeY * Math.cos(Needle_angle - Math.PI / 2.0) + (double) cy);
    int Wx = (int) ((double) SmallAxeX * Math.sin(Needle_angle + Math.PI / 2.0) + (double) cx);
    int Wy = (int) ((double) SmallAxeY * Math.cos(Needle_angle + Math.PI / 2.0) + (double) cy);

    gc.setFill(Color.RED);
    gc.fillPolygon(new double[] {Nx, Ex, Sx, Wx}, new double[] {Ny, Ey, Sy, Wy}, 4);
  }
Esempio n. 17
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    int width = this.getBounds().width;
    int height = this.getBounds().height;

    Graphics2D g2 = (Graphics2D) g;

    g2.setStroke(new BasicStroke(3.0f));
    g2.drawOval(width / 3, height / 5, width / 3, height / 2);

    int x1 = width / 2;
    int y1 = height * 3 / 10;
    int x2 = x1 + (int) (height / 5 * Math.sin(anguloVela));
    int y2 = y1 + (int) (height / 5 * Math.cos(anguloVela));
    if (focusVela) {
      g2.setColor(Color.RED);
      g2.drawLine(x1, y1, x2, y2);
      g2.setColor(Color.BLACK);
    } else {
      g2.drawLine(x1, y1, x2, y2);
    }

    y1 = height * 7 / 10;
    x2 = x1 + (int) (height / 10 * Math.sin(anguloTimon));
    y2 = y1 + (int) (height / 10 * Math.cos(anguloTimon));
    if (focusTimon) {
      g2.setColor(Color.RED);
      g2.drawLine(x1, y1, x2, y2);
      g2.setColor(Color.BLACK);
    } else {
      g2.drawLine(x1, y1, x2, y2);
    }
  }
Esempio n. 18
0
  public static double calcDistFromLonmLatm(
      double lonm1, double latm1, double lonm2, double latm2) {
    double lon1R = lonm1 * .000001 / 180 * Math.PI;
    double lat1R = latm1 * .000001 / 180 * Math.PI;
    double lon2R = lonm2 * .000001 / 180 * Math.PI;
    double lat2R = latm2 * .000001 / 180 * Math.PI;

    // from http://www.movable-type.co.uk/scripts/latlong.html
    //		var R = 6371; // km
    //		var dLat = (lat2-lat1).toRad();
    //		var dLon = (lon2-lon1).toRad();
    //		var lat1 = lat1.toRad();
    //		var lat2 = lat2.toRad();
    //
    //		var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
    //		        Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
    //		var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    //		var d = R * c;

    double dLatR = lat2R - lat1R;
    double dLonR = lon2R - lon1R;

    double a =
        Math.sin(dLatR / 2) * Math.sin(dLatR / 2)
            + Math.sin(dLonR / 2) * Math.sin(dLonR / 2) * Math.cos(lat1R) * Math.cos(lat2R);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    return EARTH_RADIUS_M * c;
  }
Esempio n. 19
0
  public static GeneralPath createArrowLine(double x0, double y0, double x1, double y1) {

    float theta = (float) Math.atan((double) (y1 - y0) / (double) (x1 - x0));
    float len = (float) Math.sqrt(Math.pow((x1 - x0), 2) + Math.pow((y1 - y0), 2));
    float side = (x1 < x0) ? -1 : 1;

    // Ideally, we should use a fixed distance from the end point,
    // rather than try and calculate a percentage, as that mucks it up
    // for shorter lengths...The easiest way would be to "draw" a
    // circle around the point (x1,y1) and then compute the
    // line-circle intersection point.  I'm too lazy to do the math
    // right now, though...

    GeneralPath gp = new GeneralPath();
    gp.reset();
    gp.moveTo((float) x0, (float) y0);
    gp.lineTo((float) (x0 + ((x1 - x0) * 0.9725f)), (float) (y0 + ((y1 - y0) * 0.9725f)));
    gp.moveTo((float) x1, (float) y1);
    gp.lineTo(
        (float) (x1 - side * ALEN * (float) Math.cos(theta + AANG)),
        (float) (y1 - side * ALEN * (float) Math.sin(theta + AANG)));
    gp.quadTo(
        (float) (x0 + ((x1 - x0) * 0.9725f)),
        (float) (y0 + ((y1 - y0) * 0.9725f)),
        (float) (x1 - side * ALEN * Math.cos(theta - AANG)),
        (float) (y1 - side * ALEN * Math.sin(theta - AANG)));
    gp.closePath();
    return gp;
  }
 private void drawTick(double angle) {
   tick.setLine(
       13 + 37 * Math.cos(angle),
       27 - 37 * Math.sin(angle),
       13 + 43 * Math.cos(angle),
       27 - 43 * Math.sin(angle));
 }
Esempio n. 21
0
 // 방위각 구하는 부분
 public static short bearingP1toP2(
     double P1_latitude, double P1_longitude, double P2_latitude, double P2_longitude) {
   // 현재 위치 : 위도나 경도는 지구 중심을 기반으로 하는 각도이기 때문에
   // 라디안 각도로 변환한다.
   double Cur_Lat_radian = P1_latitude * (3.141592 / 180);
   double Cur_Lon_radian = P1_longitude * (3.141592 / 180);
   // 목표 위치 : 위도나 경도는 지구 중심을 기반으로 하는 각도이기 때문에
   // 라디안 각도로 변환한다.
   double Dest_Lat_radian = P2_latitude * (3.141592 / 180);
   double Dest_Lon_radian = P2_longitude * (3.141592 / 180);
   // radian distance
   double radian_distance = 0;
   radian_distance =
       Math.acos(
           Math.sin(Cur_Lat_radian) * Math.sin(Dest_Lat_radian)
               + Math.cos(Cur_Lat_radian)
                   * Math.cos(Dest_Lat_radian)
                   * Math.cos(Cur_Lon_radian - Dest_Lon_radian));
   // 목적지 이동 방향을 구한다.(현재 좌표에서 다음 좌표로 이동하기 위해서는
   // 방향을 설정해야 한다. 라디안값이다.
   double radian_bearing =
       Math.acos(
           (Math.sin(Dest_Lat_radian) - Math.sin(Cur_Lat_radian) * Math.cos(radian_distance))
               / (Math.cos(Cur_Lat_radian) * Math.sin(radian_distance)));
   // acos의 인수로 주어지는 x는 360분법의 각도가 아닌 radian(호도)값이다.
   double true_bearing = 0;
   if (Math.sin(Dest_Lon_radian - Cur_Lon_radian) < 0) {
     true_bearing = radian_bearing * (180 / 3.141592);
     true_bearing = 360 - true_bearing;
   } else {
     true_bearing = radian_bearing * (180 / 3.141592);
   }
   return (short) true_bearing;
 }
Esempio n. 22
0
 public static String calc_distance(Context context, String start_longlat, String end_longlat) {
   double sLat = Double.parseDouble(start_longlat.substring(0, start_longlat.indexOf(",") - 1));
   double sLng = Double.parseDouble(start_longlat.substring(start_longlat.indexOf(",") + 1));
   double eLat = Double.parseDouble(end_longlat.substring(0, end_longlat.indexOf(",") - 1));
   double eLng = Double.parseDouble(end_longlat.substring(end_longlat.indexOf(",") + 1));
   double dis;
   double jrk;
   String distance = null;
   double d2r = (Math.PI / 180);
   double dLat = (eLat - sLat) * d2r;
   double dLon = (eLng - sLng) * d2r;
   double a =
       Math.sin(dLat / 2) * Math.sin(dLat / 2)
           + Math.cos(sLat * d2r) * Math.cos(eLat * d2r) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
   double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
   dis = EARTH_RADIUS_KM * c * 1000;
   if (dis > 10000) {
     jrk = Double.valueOf(Math.round(dis / 1000));
     distance = Double.toString(jrk) + " Km";
   } else if (dis > 0 && dis < 100) {
     jrk = Double.valueOf(Math.round(dis));
     distance = Double.toString(jrk) + " m";
   } else if (dis > 200 && dis < 1000) {
     jrk = Double.valueOf(Math.round(dis / 10));
     distance = Double.toString(jrk) + " Km";
   } else {
     jrk = Double.valueOf(Math.round(dis / 1000));
     distance = Double.toString(jrk) + " Km";
   }
   return distance;
 }
Esempio n. 23
0
  /** Returns the cosine of this complex number. */
  public Complex cos() {
    double izRe, izIm;
    double temp1Re, temp1Im;
    double temp2Re, temp2Im;
    double scalar;

    //  cos(z)  =  ( exp(i*z) + exp(-i*z) ) / 2
    izRe = -im;
    izIm = re;

    // first exp
    scalar = Math.exp(izRe);
    temp1Re = scalar * Math.cos(izIm);
    temp1Im = scalar * Math.sin(izIm);

    // second exp
    scalar = Math.exp(-izRe);
    temp2Re = scalar * Math.cos(-izIm);
    temp2Im = scalar * Math.sin(-izIm);

    temp1Re += temp2Re;
    temp1Im += temp2Im;

    return new Complex(0.5 * temp1Re, 0.5 * temp1Im);
  }
Esempio n. 24
0
 private void animateRotate(View left, View right, float positionOffset, boolean up) {
   if (mState != State.IDLE) {
     if (left != null) {
       manageLayer(left, true);
       mRot = (up ? 1 : -1) * (ROT_MAX * positionOffset);
       mTrans =
           (up ? -1 : 1)
               * (float)
                   (getMeasuredHeight() - getMeasuredHeight() * Math.cos(mRot * Math.PI / 180.0f));
       ViewHelper.setPivotX(left, left.getMeasuredWidth() * 0.5f);
       ViewHelper.setPivotY(left, up ? 0 : left.getMeasuredHeight());
       ViewHelper.setTranslationY(left, mTrans);
       ViewHelper.setRotation(left, mRot);
     }
     if (right != null) {
       manageLayer(right, true);
       mRot = (up ? 1 : -1) * (-ROT_MAX + ROT_MAX * positionOffset);
       mTrans =
           (up ? -1 : 1)
               * (float)
                   (getMeasuredHeight() - getMeasuredHeight() * Math.cos(mRot * Math.PI / 180.0f));
       ViewHelper.setPivotX(right, right.getMeasuredWidth() * 0.5f);
       ViewHelper.setPivotY(right, up ? 0 : right.getMeasuredHeight());
       ViewHelper.setTranslationY(right, mTrans);
       ViewHelper.setRotation(right, mRot);
     }
   }
 }
Esempio n. 25
0
 public double calculationByDistance(GeoPoint gpOrigem, GeoPoint gpDestino) {
   int Radius = 6371; // radius of earth in Km
   double c = 0f;
   if (gpOrigem != null && gpDestino != null) {
     double lat1 = gpOrigem.getLatitudeE6() / 1E6;
     double lat2 = gpDestino.getLatitudeE6() / 1E6;
     double lon1 = gpOrigem.getLongitudeE6() / 1E6;
     double lon2 = gpDestino.getLongitudeE6() / 1E6;
     double dLat = Math.toRadians(lat2 - lat1);
     double dLon = Math.toRadians(lon2 - lon1);
     double a =
         Math.sin(dLat / 2) * Math.sin(dLat / 2)
             + Math.cos(Math.toRadians(lat1))
                 * Math.cos(Math.toRadians(lat2))
                 * Math.sin(dLon / 2)
                 * Math.sin(dLon / 2);
     c = 2 * Math.asin(Math.sqrt(a));
     double valueResult = Radius * c;
     double km = valueResult / 1;
     DecimalFormat newFormat = new DecimalFormat("####");
     Integer kmInDec = Integer.valueOf(newFormat.format(km));
     double meter = valueResult % 1000;
     double meterInDec = Integer.valueOf(newFormat.format(meter));
     Log.i("Radius Value", "" + valueResult + "   KM  " + kmInDec + " Meter   " + meterInDec);
   }
   return Radius * c;
 }
Esempio n. 26
0
  @Override
  public SystemPositionAndAttitude step(SystemPositionAndAttitude state, double timestep) {
    model.setState(state);
    double distToDestination = state.getPosition().getDistanceInMeters(destination);
    if (loiterType.equalsIgnoreCase("circular")) {

      if (distToDestination - 2 > radius) {
        model.guide(
            destination, speed, destination.getDepth() >= 0 ? null : -destination.getDepth());
        if (!enteredLoiter) loiterTime = 0;
      } else {
        enteredLoiter = true;
        double perpend = state.getPosition().getXYAngle(destination) + Math.PI / 2;
        LocationType loc = new LocationType(state.getPosition());
        loc.setDepth(destination.getDepth());
        if (clockwise) loc.translatePosition(Math.cos(perpend) * -20, Math.sin(perpend) * -20, 0);
        else loc.translatePosition(Math.cos(perpend) * 20, Math.sin(perpend) * 20, 0);
        model.guide(loc, speed, destination.getDepth() >= 0 ? null : -destination.getDepth());
        loiterTime += timestep;
      }
    } else {
      if (distToDestination < speed * 2) loiterTime += timestep;
      else
        model.guide(
            destination, speed, destination.getDepth() >= 0 ? null : -destination.getDepth());
    }

    model.advance(timestep);

    if (loiterTime > duration) finished = true;

    return model.getState();
  }
  public void renderParticle(
      Tessellator tess, float ptt, float rotX, float rotXZ, float rotZ, float rotYZ, float rotXY) {
    brightness = brightnessFade.updateFade(particleAge);

    float progress = (float) particleAge / particleMaxAge;

    // tess.draw();

    // glPushMatrix();

    glDepthMask(false);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    Minecraft.getMinecraft().renderEngine.bindTexture(tex);

    float scale = data.size;

    float[] pos = FXHelper.trackingParticleLocale(this, ptt);
    float[] rot = new float[] {rotX, rotXZ, rotZ, rotYZ, rotXY};

    pos[0] += data.xRad * Math.cos(2 * Math.PI * progress);
    pos[1] += 0.5 * data.yRad * Math.cos(2 * Math.PI * progress) * Math.sin(2 * Math.PI * progress);
    pos[2] += data.zRad * Math.sin(2 * Math.PI * progress);

    draw(tess, pos, scale, rot);

    glDisable(GL_BLEND);
    glDepthMask(true);

    // glPopMatrix();
    Minecraft.getMinecraft().renderEngine.bindTexture(FXHelper.getParticleTexture());

    // tess.startDrawingQuads();
  }
Esempio n. 28
0
  private Location calculateNextLocation(Location loc, double distance) {
    Random rand = new Random();
    int minAngle = 0;
    int maxAngle = 360;
    int randomAngle = rand.nextInt((maxAngle - minAngle) + 1) + minAngle;
    double bearing = Math.toRadians(randomAngle);

    double lat1 = Math.toRadians(loc.Latitude);
    double lon1 = Math.toRadians(loc.Longtitude);

    double lat2 =
        Math.asin(
            Math.sin(lat1) * Math.cos(distance / EarthRadius)
                + Math.cos(lat1) * Math.sin(distance / EarthRadius) * Math.cos(bearing));

    double lon2 =
        lon1
            + Math.atan2(
                Math.sin(bearing) * Math.sin(distance / EarthRadius) * Math.cos(lat1),
                Math.cos(distance / EarthRadius) - Math.sin(lat1) * Math.sin(lat2));

    lat2 = Math.toDegrees(lat2);
    lon2 = Math.toDegrees(lon2);

    return LatLongToXYZ(lat2, lon2);
  }
Esempio n. 29
0
  /**
   * Set the values, all constructors uses this function
   *
   * @param loc location of the view
   * @param maxDistance how far it checks for blocks
   * @param viewHeight where the view is positioned in y-axis
   * @param checkDistance how often to check for blocks, the smaller the more precise
   */
  private void setValues(
      Location loc,
      int maxDistance,
      double viewHeight,
      double checkDistance,
      TIntHashSet transparent) {
    this.maxDistance = maxDistance;
    this.checkDistance = checkDistance;
    curDistance = 0;
    int xRotation = (int) (loc.getYaw() + 90) % 360;
    int yRotation = (int) loc.getPitch() * -1;

    double h = checkDistance * Math.cos(Math.toRadians(yRotation));

    offset =
        new Vector(
            (h * Math.cos(Math.toRadians(xRotation))),
            (checkDistance * Math.sin(Math.toRadians(yRotation))),
            (h * Math.sin(Math.toRadians(xRotation))));

    targetPosDouble = loc.add(0, viewHeight, 0).toVector();
    targetPos = targetPosDouble.toBlockVector();
    prevPos = targetPos;
    transparentBlocks = transparent;
    if (transparentBlocks == null) {
      transparentBlocks = new TIntHashSet(new int[] {0});
    }
  }
Esempio n. 30
0
 public void inputMovement(Point2D.Float acceleration) {
   oldPosition = this.getPosition();
   if (acceleration.x == 0 && acceleration.y == 0) {
     velocity.x *= slowDown;
     velocity.y *= slowDown;
   } else {
     float accelerationAbs =
         (float) Math.sqrt(acceleration.x * acceleration.x + acceleration.y * acceleration.y);
     velocity.x += acceleration.x * accelerationScale / accelerationAbs;
     velocity.y += acceleration.y * accelerationScale / accelerationAbs;
     float speed = (float) Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y);
     if (speed > maxSpeed) {
       velocity.x = velocity.x * maxSpeed / speed;
       velocity.y = velocity.y * maxSpeed / speed;
     }
   }
   if (collision == null) {
   } else {
     // revert the position and bounce a little bit
     position.x += (position.x - collision.x) / 2;
     position.y += (position.y - collision.y) / 2;
     Point2D.Float proj = new Point2D.Float();
     float collisionDirection = getRadiansTo(collision);
     float movementDirection = (float) Math.atan2(velocity.y, velocity.x);
     float angleBetween = movementDirection - collisionDirection;
     float velocityAbs = (float) Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y);
     float cosAB = (float) Math.cos(angleBetween); // angle between
     velocity.x -= velocityAbs * cosAB * (float) Math.cos(collisionDirection) * 1.1;
     velocity.y -= velocityAbs * cosAB * (float) Math.sin(collisionDirection) * 1.1;
     resetCollision();
   }
   incrementPosition(velocity.x, velocity.y);
 }