private float getCorrectYaw(double tX, double tZ) {
   if (locZ > tZ) return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ))));
   if (locZ < tZ) {
     return (float) (-Math.toDegrees(Math.atan((locX - tX) / (locZ - tZ)))) + 180.0F;
   }
   return yaw;
 }
Esempio n. 2
1
  public Bounds bounds() {

    double mx0 = 0, my0 = 0;
    if (angle == 0 || angle == Math.PI) {
      mx0 = major;
      my0 = minor;
    } else if (major == 0) {
      mx0 = minor * Math.sin(angle);
      my0 = minor * Math.cos(angle);
    } else if (minor == 0) {
      mx0 = major * Math.cos(angle);
      my0 = major * Math.sin(angle);
    } else {
      final double tan = Math.tan(angle);
      final double tx = Math.atan(-minor * tan / major);
      final double ty = Math.atan(minor / (tan * major));
      final double sina = Math.sin(angle);
      final double cosa = Math.cos(angle);
      mx0 = major * cosa * Math.cos(tx) - minor * sina * Math.sin(tx);
      my0 = major * sina * Math.cos(ty) + minor * cosa * Math.sin(ty);
    }
    if (mx0 < 0) mx0 = -mx0;
    if (my0 < 0) my0 = -my0;

    final Bounds bounds = new Bounds();
    bounds.lower.x = x - mx0;
    bounds.lower.y = y - my0;
    bounds.upper.x = x + mx0;
    bounds.upper.y = y + my0;

    return bounds;
  }
  /**
   * Conversión de coordenadas geocéntricas a coordenadas geodésicas
   *
   * @param X coordenada x
   * @param Y coordenada y
   * @param Z coordenada z
   * @param ellipsoid Elipsoide de referencia
   * @return El punto en coordenadas geodésicas calculado
   */
  public static GeodeticPoint fromECEFToGeodetic(double X, double Y, double Z, int ellipsoid) {
    double a = ELLIPSOID_A[ellipsoid]; // Semieje mayor
    double b = ELLIPSOID_B[ellipsoid]; // Semieje menor

    double ecuad = ((a * a) - (b * b)) / (a * a); // Excentricidad al cuadrado
    double e2cuad = ((a * a) - (b * b)) / (b * b); // Segunda excentricidad al cuadrado
    double p = Math.sqrt((X * X) + (Y * Y));
    double theta = Math.atan((Z * a) / (p * b));

    // Latitud y longitud geodésicas
    double latRad =
        Math.atan(
            (Z + e2cuad * b * Math.pow(Math.sin(theta), 3))
                / (p - ecuad * a * Math.pow(Math.cos(theta), 3)));
    double lonRad = Math.atan(Y / X);
    double lat = latRad * 180.0 / Math.PI;
    double lon = lonRad * 180.0 / Math.PI;

    double N =
        (a * a)
            / Math.sqrt(
                (a * a * Math.pow(Math.cos(latRad), 2)) + (b * b * Math.pow(Math.sin(latRad), 2)));
    double alt = (p / Math.cos(latRad)) - N;

    return new GeodeticPoint(lon, lat, alt);
  }
 public static void drawPlayerOnGui(
     Minecraft par0Minecraft, int par1, int par2, int par3, float par4, float par5) {
   GL11.glEnable(GL11.GL_COLOR_MATERIAL);
   GL11.glPushMatrix();
   GL11.glTranslatef((float) par1, (float) par2, 50.0F);
   GL11.glScalef((float) (-par3), (float) par3, (float) par3);
   GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
   float f2 = par0Minecraft.thePlayer.renderYawOffset;
   float f3 = par0Minecraft.thePlayer.rotationYaw;
   float f4 = par0Minecraft.thePlayer.rotationPitch;
   par4 -= 19;
   GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
   RenderHelper.enableStandardItemLighting();
   GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
   GL11.glRotatef(-((float) Math.atan((double) (par5 / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F);
   par0Minecraft.thePlayer.renderYawOffset = (float) Math.atan((double) (par4 / 40.0F)) * 20.0F;
   par0Minecraft.thePlayer.rotationYaw = (float) Math.atan((double) (par4 / 40.0F)) * 40.0F;
   par0Minecraft.thePlayer.rotationPitch = -((float) Math.atan((double) (par5 / 40.0F))) * 20.0F;
   par0Minecraft.thePlayer.rotationYawHead = par0Minecraft.thePlayer.rotationYaw;
   GL11.glTranslatef(0.0F, par0Minecraft.thePlayer.yOffset, 0.0F);
   RenderManager.instance.playerViewY = 180.0F;
   RenderManager.instance.renderEntityWithPosYaw(
       par0Minecraft.thePlayer, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
   par0Minecraft.thePlayer.renderYawOffset = f2;
   par0Minecraft.thePlayer.rotationYaw = f3;
   par0Minecraft.thePlayer.rotationPitch = f4;
   GL11.glPopMatrix();
   RenderHelper.disableStandardItemLighting();
   GL11.glDisable(GL12.GL_RESCALE_NORMAL);
   OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
   GL11.glDisable(GL11.GL_TEXTURE_2D);
   OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
 }
Esempio n. 5
1
 private double cal_angle(float x, float y) {
   if (x >= 0 && y >= 0) return Math.toDegrees(Math.atan(y / x));
   else if (x < 0 && y >= 0) return Math.toDegrees(Math.atan(y / x)) + 180;
   else if (x < 0 && y < 0) return Math.toDegrees(Math.atan(y / x)) + 180;
   else if (x >= 0 && y < 0) return Math.toDegrees(Math.atan(y / x)) + 360;
   return 0;
 }
Esempio n. 6
1
  /**
   * 根据经纬度的来计算角度
   *
   * @param A 雷达的当前位置
   * @param B wifi的位置
   * @return wifi相对于雷达中心的角度
   */
  private double computingAngle(LatLng A, LatLng B) { // 上北左西

    double angle = 0;

    double ya = A.latitude;
    double xa = A.longitude;

    double yb = B.latitude;
    double xb = B.longitude;

    if (xa <= xb && ya <= yb) { // 一
      angle = -Math.atan(Math.abs(ya - yb) / Math.abs(xa - xb)) / Math.PI * 180;
    }

    if (xa < xb && ya > yb) { // 四
      angle = 90 - Math.atan(Math.abs(xa - xb) / Math.abs(ya - yb)) / Math.PI * 180;
    }

    if (xa > xb && ya < yb) { // 二
      angle = Math.atan(Math.abs(ya - yb) / Math.abs(xa - xb)) / Math.PI * 180 + 180;
    }

    if (xa > xb && ya > yb) { // 三
      angle = Math.atan(Math.abs(xa - xb) / Math.abs(ya - yb)) / Math.PI * 180 + 90;
    }

    return angle;
  }
  /**
   * 目的地を示す矢印の角度計算
   *
   * @param deviceLocation デバイスの位置情報
   * @param azimuthAngle 方位角
   */
  private void calcArrowDegrees(@NonNull Location deviceLocation, double azimuthAngle) {
    if (azimuthAngle == INI_DEGREES) {
      return;
    }

    this.mPrevArrowDegrees = this.mArrowDegrees;

    LatLng dstLatLon = this.mDstLatLon;

    // デバイスの座標を(0,0)として相対座標に変換
    double relativeLat = dstLatLon.getLat().doubleValue() - deviceLocation.getLatitude();
    double relativeLng = dstLatLon.getLng().doubleValue() - deviceLocation.getLongitude();

    // 北を向いている時の目的地との角度を算出
    double dBufDegrees;
    if ((relativeLng >= 0) && (relativeLat >= 0)) {
      dBufDegrees = (Math.atan(relativeLng / relativeLat) * 180 / Math.PI);
    } else if ((relativeLng >= 0) && (relativeLat < 0)) {
      relativeLat = relativeLat * -1;
      dBufDegrees = (Math.atan(relativeLat / relativeLng) * 180 / Math.PI) + 90;
    } else if ((relativeLng < 0) && (relativeLat < 0)) {
      relativeLng = relativeLng * -1;
      relativeLat = relativeLat * -1;
      dBufDegrees = 270 - (Math.atan(relativeLat / relativeLng) * 180 / Math.PI);
    } else {
      relativeLng = relativeLng * -1;
      dBufDegrees = (Math.atan(relativeLat / relativeLng) * 180 / Math.PI) + 270;
    }

    // 現在のデバイスが向いている方位から実際の目的地との角度を算出
    this.mArrowDegrees = dBufDegrees - azimuthAngle;
    if (this.mArrowDegrees < 0) {
      this.mArrowDegrees = this.mArrowDegrees + 360;
    }
  }
  public double f1(Vector3f point, Vector3f A, Vector3f B) {
    // ****** basic parameters ******
    Vector3f vec_b = B;
    Vector3f vec_a = A.subtract(vec_b);
    Vector3f vec_r = point;
    double L = vec_a.length();
    Vector3f vec_d = vec_r.subtract(vec_b);
    double d = vec_d.length();
    double h = vec_d.dot(vec_a.normalize());

    // terms
    double s2 = s * s;
    double h2 = h * h;
    double lmh = L - h;
    double d2 = d * d;
    double p2 = 1 + s2 * (d2 - h2);
    double p = Math.sqrt(p2);
    double ww = p2 + s2 * h2;
    double qq = p2 + s2 * lmh * lmh;
    double sdp = s / p;
    double tpp = 2.0 * p2;
    double sp = s * p;
    double term = Math.atan(sdp * h) + Math.atan(sdp * lmh);

    return (h / ww + lmh / qq) / tpp + term / (tpp * sp);
  }
 public int getAngle() {
   if (xPosition > centerX) {
     if (yPosition < centerY) {
       return lastAngle =
           (int) (Math.atan((yPosition - centerY) / (xPosition - centerX)) * RAD + 90);
     } else if (yPosition > centerY) {
       return lastAngle =
           (int) (Math.atan((yPosition - centerY) / (xPosition - centerX)) * RAD) + 90;
     } else {
       return lastAngle = 90;
     }
   } else if (xPosition < centerX) {
     if (yPosition < centerY) {
       return lastAngle =
           (int) (Math.atan((yPosition - centerY) / (xPosition - centerX)) * RAD - 90);
     } else if (yPosition > centerY) {
       return lastAngle =
           (int) (Math.atan((yPosition - centerY) / (xPosition - centerX)) * RAD) - 90;
     } else {
       return lastAngle = -90;
     }
   } else {
     if (yPosition <= centerY) {
       return lastAngle = 0;
     } else {
       if (lastAngle < 0) {
         return lastAngle = -180;
       } else {
         return lastAngle = 180;
       }
     }
   }
 }
Esempio n. 10
0
  @Override
  public void inverse(
      final double x,
      final double y,
      final double[] targetCoordinates,
      final int targetOffset,
      final int targetAxisCount) {
    final double dX = x - this.x0;
    final double dY = y - this.y0;

    final double lambda = dX / this.a + this.lambda0;

    final double t = Math.pow(Math.E, -dY / this.a);
    // TODO phi
    double phi = Angle.PI_OVER_2 - 2 * Math.atan(t);
    double delta = 10e010;
    do {
      final double eSinPhi = this.e * Math.sin(phi);
      final double phi1 =
          Angle.PI_OVER_2 - 2 * Math.atan(t * Math.pow((1 - eSinPhi) / (1 + eSinPhi), this.eOver2));
      delta = Math.abs(phi1 - phi);
      phi = phi1;
    } while (delta > 1.0e-011);

    targetCoordinates[targetOffset * targetAxisCount] = lambda;
    targetCoordinates[targetOffset * targetAxisCount + 1] = phi;
  }
Esempio n. 11
0
  public static Location lookAt(Location loc, Location lookat) {

    loc = loc.clone();

    double dx = lookat.getX() - loc.getX();
    double dy = lookat.getY() - loc.getY();
    double dz = lookat.getZ() - loc.getZ();

    if (dx != 0) {
      if (dx < 0) {
        loc.setYaw((float) (1.5 * Math.PI));
      } else {
        loc.setYaw((float) (0.5 * Math.PI));
      }
      loc.setYaw(loc.getYaw() - (float) Math.atan(dz / dx));
    } else if (dz < 0) {
      loc.setYaw((float) Math.PI);
    }

    double dxz = Math.sqrt(Math.pow(dx, 2) + Math.pow(dz, 2));

    loc.setPitch((float) -Math.atan(dy / dxz));

    loc.setYaw(-loc.getYaw() * 180f / (float) Math.PI);
    loc.setPitch(loc.getPitch() * 180f / (float) Math.PI);

    return loc;
  }
  // Converts a mouse position to a Percentage value
  private float pointToPercentage(MouseEvent e) {
    int centerX = this.getWidth() / 2;
    int centerY = this.getHeight() / 2;
    int mouseX = e.getX() - centerX;
    int mouseY = e.getY() - centerY;
    double l = Math.sqrt(mouseX * mouseX + mouseY * mouseY);
    double lx = mouseX / l;
    double ly = mouseY / l;
    double theta;
    if (lx > 0) {
      theta = Math.atan(ly / lx);
    } else if (lx < 0) {
      theta = -1 * Math.atan(ly / lx);
    } else {
      theta = 0;
    }

    if ((mouseX > 0) && (mouseY < 0)) {
      theta = -1 * theta;
    } else if (mouseX < 0) {
      theta += Math.PI;
    } else {
      theta = 2 * Math.PI - theta;
    }

    return (float) (theta / (2 * Math.PI));
  }
Esempio n. 13
0
 public static double getAngle(double x, double y) {
   if (x > 0) {
     return Math.atan(y / x);
   } else if (x < 0) {
     return Math.atan(y / x) + Math.PI;
   } else {
     return y > 0 ? Math.PI / 2 : -Math.PI / 2;
   }
 }
Esempio n. 14
0
  private void drawAWP(Graphics g, int x, int y) {
    if (System.currentTimeMillis() < shotTime + TAWP.SHOOT_TIME) {
      // System.out.println(true);
      double multi = 1.0 * (System.currentTimeMillis() - shotTime) / TAWP.SHOOT_TIME;
      g.setColor(new Color(255, 255, 255, 255 - (int) (multi * 256)));
      g.fillRect(0, 0, Wuigi.screenWidth, Wuigi.screenHeight);
    }
    if (numBullets <= 0) return;

    BufferedImage img = TAWP.IMAGE.getBuffer();
    AffineTransform xform = new AffineTransform();
    // g2d.setPaint(new TexturePaint(figureOutDrawImage(),
    //		new Rectangle2D.Float(0, 0, 32, 32)));
    // g2d.drawImage(figureOutDrawImage(),0,0,null);
    xform.setToIdentity();
    xform.translate(x - 5, y);

    double diffY = y + height / 2 - ScreenManager.mouse.y;
    double diffX = ScreenManager.mouse.x - x - width / 2;

    double angle;

    if (diffY > 0 && diffX > 0) {
      angle = Math.PI / 2 - Math.atan(diffY / diffX);
    } else if (diffY == 0 && diffX > 0) {
      angle = Math.PI / 2;
    } else if (diffY < 0 && diffX > 0) {
      angle = Math.PI / 2 + Math.atan(-diffY / diffX);
    } else if (diffY < 0 && diffX == 0) {
      angle = Math.PI;
    } else if (diffY < 0 && diffX < 0) {
      angle = 3 * Math.PI / 2 - Math.atan(diffY / diffX);
    } else if (diffY == 0 && diffX < 0) {
      angle = 3 * Math.PI / 2;
    } else if (diffY > 0 && diffX < 0) {
      angle = 3 * Math.PI / 2 + Math.atan(-diffY / diffX);
    } else {
      angle = 0;
    }
    angle -= Math.PI / 2;

    if (angle > Math.PI / 2 && angle < 3 * Math.PI / 2) {
      xform.scale(1, -1);
      xform.translate(0, -TAWP.IMAGE.getHeight());
      angle = -angle;
    }
    // xform.scale(/*width/img.getWidth(),height/img.getHeight()*/);
    xform.rotate(angle, 27, 13);

    ((Graphics2D) g).drawImage(img, xform, null);
    ammo.setPos(x + 10, y - 20);
    ammo.draw(g);
  }
  public void setBulletRotation() {
    float rotVal = 0;

    double arcTan = Math.atan(this.getSpeedX() / Math.abs(this.getSpeedY()));
    if (!theOneWhoShotMe.isFriendly()) {
      arcTan = Math.atan(-this.getSpeedX() / Math.abs(this.getSpeedY()));
      arcTan += Math.PI; // flip bullet image around so it is pointing downwards
    }
    rotVal = (float) Math.toDegrees(arcTan);

    this.setRotation(rotVal);
  }
Esempio n. 16
0
 /**
  * Angle of a 2d vector, x being the side at the angle. (radians).
  *
  * @param x
  * @param z
  * @return
  */
 public static final double angle(final double x, final double z) {
   final double a;
   if (x > 0.0) a = Math.atan(z / x);
   else if (x < 0.0) a = Math.atan(z / x) + Math.PI;
   else {
     if (z < 0.0) a = 3.0 * Math.PI / 2.0;
     else if (z > 0.0) a = Math.PI / 2.0;
     else return Double.NaN;
   }
   if (a < 0.0) return a + 2.0 * Math.PI;
   else return a;
 }
Esempio n. 17
0
 protected double phi2(double ts) {
   double dLat, lat = Constants.halfPi - 2.0 * Math.atan(ts);
   int i = 15;
   do {
     double con = _e * Math.sin(lat);
     dLat =
         Constants.halfPi
             - 2.0 * Math.atan(ts * Math.pow((1.0 - con) / (1.0 + con), _halfE))
             - lat;
     lat += dLat;
   } while (Math.abs(dLat) > 1.0E-10 && --i != 0);
   return (i != 0 ? lat : Double.MAX_VALUE);
 }
Esempio n. 18
0
  /**
   * Conversión de coordenadas UTM a coordenadas geográficas utilizando las ecuaciones de
   * Coticchia-Surace.
   *
   * @param x Coordenada x
   * @param y Coordenada y
   * @param zone Huso o zona UTM
   * @param ellipsoid Elipsoide de referencia
   * @return El punto en coordenadas geográficas calculado
   */
  public static GeodeticPoint fromUTMToGeodetic(double x, double y, int zone, int ellipsoid) {
    /* Calculos sobre la geometría del elipsoide */
    double a = ELLIPSOID_A[ellipsoid]; // Semieje mayor
    double b = ELLIPSOID_B[ellipsoid]; // Semieje menor
    double e2 = Math.sqrt((a * a) - (b * b)) / b; // Segunda excentricidad
    double e2cuad = e2 * e2;
    double c = a * a / b; // Radio polar de curvatura

    /* Tratamiento previo de X e Y */
    x -= 500000; // Eliminar el retranqueo del eje de las X
    // El retranqueo del eje Y lo ignoramos porque suponemos que estamos en el hemisferio Norte

    /* Calculo del meridiano central del huso */
    int meridCentral = (zone * 6) - 183; // Meridiano central del huso

    /* Ecuaciones de Coticchia-Surace */
    /* Calculo de parametros */
    double phi = y / (6366197.724 * 0.9996);
    double v = (c * 0.9996) / Math.sqrt((1 + e2cuad * Math.pow(Math.cos(phi), 2)));
    double A = x / v;
    double A1 = Math.sin(2 * phi);
    double A2 = A1 * Math.pow(Math.cos(phi), 2);
    double J2 = phi + A1 / 2;
    double J4 = (3 * J2 + A2) / 4;
    double J6 = (5 * J4 + A2 * Math.pow(Math.cos(phi), 2)) / 3;
    double alfa = e2cuad * 3 / 4;
    double beta = alfa * alfa * 5 / 3;
    double gamma = Math.pow(alfa, 3) * 35 / 27;
    double B0 = 0.9996 * c * (phi - (alfa * J2) + (beta * J4) - (gamma * J6));
    double B = (y - B0) / v;
    double xi = (e2cuad / 2) * A * A * Math.pow(Math.cos(phi), 2);
    double eps = A * (1 - (xi / 3));
    double nu = B * (1 - xi) + phi;
    double senheps = (Math.exp(eps) - Math.exp(-eps)) / 2;
    double dlambda = Math.atan(senheps / Math.cos(nu));
    double t = Math.atan(Math.cos(dlambda) * Math.tan(nu));

    /* Calculo final de coordenadas */
    double longitud = (dlambda * 180 / Math.PI) + meridCentral;
    double latitud =
        phi
            + (1
                    + e2cuad * Math.pow(Math.cos(phi), 2)
                    - 1.5 * e2cuad * Math.sin(phi) * Math.cos(phi) * (t - phi))
                * (t - phi);
    latitud = latitud * 180 / Math.PI; // pasar a grados decimales

    return new GeodeticPoint(longitud, latitud);
  }
Esempio n. 19
0
  /**
   * Adapted from http://www.ponies.me.uk/maps/GoogleTileUtils.java
   *
   * @param tileX
   * @param tileY
   * @param zoom
   * @return
   */
  private Rectangle2D.Float getLatLong(int tileX, int tileY, int zoom) {
    int pixelX = tileX * 256;
    int pixelY = tileY * 256;
    double twoToZoom = Math.pow(2, zoom);
    double worldX = pixelX / twoToZoom;
    double worldY = pixelY / twoToZoom;

    double x = tileX;
    double y = tileY;

    double lon = -180; // x
    double lonWidth = 360; // width 360

    // double lat = -90; // y
    // double latHeight = 180; // height 180
    double lat = -1;
    double latHeight = 2;

    int tilesAtThisZoom = (int) Math.pow(2, zoom);
    lonWidth = 360.0 / tilesAtThisZoom;
    lon = -180 + (x * lonWidth);
    latHeight = -2.0 / tilesAtThisZoom;
    lat = 1 + (y * latHeight);

    // convert lat and latHeight to degrees in a mercator projection
    // note that in fact the coordinates go from
    // about -85 to +85 not -90 to 90!
    latHeight += lat;
    latHeight = (2 * Math.atan(Math.exp(Math.PI * latHeight))) - (Math.PI / 2);
    latHeight *= (180 / Math.PI);

    lat = (2 * Math.atan(Math.exp(Math.PI * lat))) - (Math.PI / 2);
    lat *= (180 / Math.PI);

    latHeight -= lat;

    if (lonWidth < 0) {
      lon = lon + lonWidth;
      lonWidth = -lonWidth;
    }

    if (latHeight < 0) {
      lat = lat + latHeight;
      latHeight = -latHeight;
    }

    return new Rectangle2D.Float((float) lon, (float) lat, (float) lonWidth, (float) latHeight);
  }
Esempio n. 20
0
  private List<Polygon> generateCurrentPolygons() {
    geoPoints.clear();
    int halfHeight = this.getHeight() / 2;
    int halfWidth = this.getWidth() / 2;
    List<Polygon> polyList = new LinkedList<Polygon>();
    double radius, angle, angleStep;
    int[] xpoints;
    int[] ypoints;
    int i;
    for (List<Geoquant> list : geoList.values()) {
      int size = list.size();
      if (size != 0) {
        xpoints = new int[size];
        ypoints = new int[size];
        angleStep = 2 * Math.PI / size;

        i = 0;
        angle = 0;
        for (Geoquant q : list) {
          radius = (halfHeight / Math.PI) * (Math.atan(q.getValue()) + Math.PI / 2);
          xpoints[i] = (int) (radius * Math.cos(angle) + halfWidth);
          ypoints[i] = (int) (-1 * radius * Math.sin(angle) + halfHeight);

          geoPoints.add(new GeoPoint(xpoints[i], ypoints[i], q.toString()));

          i++;
          angle += angleStep;
        }
        polyList.add(new Polygon(xpoints, ypoints, size));
      }
    }

    return polyList;
  }
Esempio n. 21
0
 public static double point_direction(double x1, double y1, double x2, double y2) {
   double d;
   try {
     d = Math.toDegrees(Math.atan((y2 - y1) / (x2 - x1)));
   } catch (Exception e) {
     d = 0.0D;
   }
   if ((x1 > x2) && (y1 > y2)) {
     return -d + 180.0D;
   }
   if ((x1 < x2) && (y1 > y2)) {
     return -d;
   }
   if (x1 == x2) {
     if (y1 > y2) return 90.0D;
     if (y1 < y2) return 270.0D;
   }
   if ((x1 > x2) && (y1 < y2)) {
     return -d + 180.0D;
   }
   if ((x1 < x2) && (y1 < y2)) {
     return -d + 360.0D;
   }
   if (y1 == y2) {
     if (x1 > x2) return 180.0D;
     if (x1 < x2) return 0.0D;
   }
   return 0.0D;
 }
Esempio n. 22
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;
  }
  /*
   * 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);
  }
 public void drawPlayerOnGui(
     Minecraft par0Minecraft, int par1, int par2, int par3, float par4, float par5) {
   final float pitchBefore = par0Minecraft.thePlayer.rotationPitch;
   GL11.glEnable(GL11.GL_COLOR_MATERIAL);
   GL11.glPushMatrix();
   GL11.glTranslatef(par1, par2, 50.0F);
   GL11.glScalef(-par3, par3, par3);
   GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
   final float var6 = par0Minecraft.thePlayer.renderYawOffset;
   final float var7 = par0Minecraft.thePlayer.rotationYaw;
   final float var8 = par0Minecraft.thePlayer.rotationPitch;
   GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F);
   RenderHelper.enableStandardItemLighting();
   GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
   GL11.glRotatef(-((float) Math.atan(this.rotation / 40.0F)) * 00.0F, 1.0F, 0.0F, 0.0F);
   par0Minecraft.thePlayer.renderYawOffset = this.rotation;
   par0Minecraft.thePlayer.rotationYaw = this.rotation;
   par0Minecraft.thePlayer.rotationPitch = 0;
   par0Minecraft.thePlayer.rotationYawHead = par0Minecraft.thePlayer.rotationYaw;
   GL11.glTranslatef(0.0F, par0Minecraft.thePlayer.yOffset, 0.0F);
   RenderManager.instance.playerViewY = 180.0F;
   RenderManager.instance.renderEntityWithPosYaw(
       par0Minecraft.thePlayer, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F);
   par0Minecraft.thePlayer.renderYawOffset = var6;
   par0Minecraft.thePlayer.rotationYaw = var7;
   //        par0Minecraft.thePlayer.rotationPitch = var8;
   GL11.glPopMatrix();
   RenderHelper.disableStandardItemLighting();
   GL11.glDisable(GL12.GL_RESCALE_NORMAL);
   OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
   GL11.glDisable(GL11.GL_TEXTURE_2D);
   OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
   par0Minecraft.thePlayer.rotationPitch = pitchBefore;
 }
Esempio n. 25
0
  @Override
  public Object eval(Object... params) {

    super.checkNumberOfParams(1, 1, params);

    return Math.atan(super.getDouble(0, params));
  }
Esempio n. 26
0
  public double bearingTo(Placeable p) {
    int xdist, ydist;
    double angle;
    double bearing;

    if (p == null) {
      return 0;
    }

    xdist = p.getX() - xcoord;
    ydist = p.getY() - ycoord;

    angle = Math.atan(((double) ydist) / xdist);
    angle = angle * 180 / Math.PI;

    if (angle < 0) {
      if (xdist < 0) {
        angle = 180 + angle; // 360 + angle - 180
      } else {
        angle = 360 + angle;
      }
    } else if (xdist < 0) {
      angle = 180 + angle;
    }

    if (angle > heading) {
      bearing = angle - heading;
    } else if (angle == heading) {
      bearing = 0;
    } else {
      bearing = angle + 360 - heading;
    }

    return bearing;
  }
Esempio n. 27
0
 /**
  * the cdf function of the Standard Normal distribution
  *
  * @param xx input value
  * @return cdf of standard normal distribution
  */
 double standard_normal_cdf(double xx) {
   double x = xx;
   if (xx < 0) x = -x;
   double b0 = 0.2316419,
       b1 = 0.319381530,
       b2 = -0.356563782,
       b3 = 1.781477937,
       b4 = -1.821255978,
       b5 = 1.330274429;
   double t = 1 / (1 + b0 * x);
   double pi = 4.0 * Math.atan(1.0);
   double pdf =
       1 / Math.sqrt(2 * pi) * Math.exp(-0.5 * x * x); // standard normal distribution's pdf
   if (xx > 0)
     return 1
         - pdf
             * (b1 * t
                 + b2 * t * t
                 + b3 * t * t * t
                 + b4 * t * t * t * t
                 + b5 * t * t * t * t * t);
   else
     return pdf
         * (b1 * t + b2 * t * t + b3 * t * t * t + b4 * t * t * t * t + b5 * t * t * t * t * t);
 }
Esempio n. 28
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. 29
0
  /**
   * Renders an image on the device
   *
   * @param tx the image location on the screen, x coordinate
   * @param ty the image location on the screen, y coordinate
   * @param img the image
   * @param rotation the image rotatation
   */
  private static void renderImage(
      Graphics2D graphics, double x, double y, Image image, double rotation, float opacity) {
    AffineTransform temp = graphics.getTransform();
    AffineTransform markAT = new AffineTransform();
    Point2D mapCentre = new java.awt.geom.Point2D.Double(x, y);
    Point2D graphicCentre = new java.awt.geom.Point2D.Double();
    temp.transform(mapCentre, graphicCentre);
    markAT.translate(graphicCentre.getX(), graphicCentre.getY());

    double shearY = temp.getShearY();
    double scaleY = temp.getScaleY();

    double originalRotation = Math.atan(shearY / scaleY);

    markAT.rotate(rotation);
    graphics.setTransform(markAT);
    graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));

    // we moved the origin to the centre of the image.
    graphics.drawImage(image, -image.getWidth(null) / 2, -image.getHeight(null) / 2, null);

    graphics.setTransform(temp);

    return;
  }
Esempio n. 30
0
  /** Math function arctan if tan45=1 then atan1=45 */
  public static double atan(double a, double b) {
    if (a == 0.0) {
      if (b > 0.0) {
        return 90.0;
      } else {
        return 270.0;
      }
    }

    if (b == 0.0) {
      if (a >= 0) {
        return 0.0;
      } else {
        return 180.0;
      }
    }

    double h = Math.atan(b / a) * 180.0 / Math.PI;
    if (a < 0.0) {
      h = h + 180.0;
    } else if (b < 0.0) {
      h = h + 360.0;
    }
    return h;
  }