/**
  * В Robocode немного извращённые углы - 0 смотрит на север и далее по часовой стрелке: 90 -
  * восток, 180 - юг, 270 - запад, 360 - север.
  *
  * <p>Из-за этого приходится писать собственный метод вычисления угла между двумя точками. Вообще
  * говоря, математика никогда не была моим коньком, поэтому, возможно, существует лучшее решение
  */
 private static double angleTo(double baseX, double baseY, double x, double y) {
   double theta = Math.asin((y - baseY) / Point2D.distance(x, y, baseX, baseY)) - Math.PI / 2;
   if (x >= baseX && theta < 0) {
     theta = -theta;
   }
   return (theta %= Math.PI * 2) >= 0 ? theta : (theta + Math.PI * 2);
 }
Exemplo n.º 2
0
  // ---------------------------------------------------------------------------
  private String Calculate1(String oper, String str1) throws Exception {
    double n1 = Values.StringToDouble(str1);
    double val = 0;

    if (oper.equalsIgnoreCase("SEN")) val = java.lang.Math.sin(n1);
    else if (oper.equalsIgnoreCase("COS")) val = java.lang.Math.cos(n1);
    else if (oper.equalsIgnoreCase("TAN")) val = java.lang.Math.tan(n1);
    else if (oper.equalsIgnoreCase("CTG")) val = 1.0 / java.lang.Math.tan(n1);
    else if (oper.equalsIgnoreCase("ASEN")) val = java.lang.Math.asin(n1);
    else if (oper.equalsIgnoreCase("ACOS")) val = java.lang.Math.acos(n1);
    else if (oper.equalsIgnoreCase("ATAN")) val = java.lang.Math.atan(n1);
    else if (oper.equalsIgnoreCase("ACTG")) val = 1.0 / java.lang.Math.atan(n1);
    else if (oper.equalsIgnoreCase("SENH")) val = java.lang.Math.sinh(n1);
    else if (oper.equalsIgnoreCase("COSH")) val = java.lang.Math.cosh(n1);
    else if (oper.equalsIgnoreCase("TANH")) val = java.lang.Math.tanh(n1);
    else if (oper.equalsIgnoreCase("CTGH")) val = 1.0 / java.lang.Math.tanh(n1);
    else if (oper.equalsIgnoreCase("EXP")) val = java.lang.Math.exp(n1);
    // valor absoluto de inteiros s�o inteiros
    else if (oper.equalsIgnoreCase("ABS")) {
      val = java.lang.Math.abs(n1);
      if (Values.IsInteger(str1)) return Values.IntegerToString(val);
    } else if (oper.equalsIgnoreCase("RAIZ")) val = java.lang.Math.sqrt(n1);
    else if (oper.equalsIgnoreCase("LOG")) val = java.lang.Math.log10(n1);
    else if (oper.equalsIgnoreCase("LN")) val = java.lang.Math.log(n1);
    // parte inteira do numeros
    else if (oper.equalsIgnoreCase("INT")) {
      return Values.IntegerToString(n1);
    }
    // parte real
    else if (oper.equalsIgnoreCase("FRAC")) {
      String num = Values.DoubleToString(n1);
      return num.substring(num.indexOf('.') + 1);
    }

    // parte real
    else if (oper.equalsIgnoreCase("ARRED")) {
      double vm = java.lang.Math.ceil(n1);
      if (n1 - vm >= 0.5) return Values.IntegerToString((int) n1 + 1);
      return Values.IntegerToString((int) n1);
    } else throw new Exception("ERRO fun��o Desconhecida 1 [" + oper + "]");
    return Values.DoubleToString(val);
  }
Exemplo n.º 3
0
  void apply_trackball(double[] m0, double[] m1) {
    final double tbsize = 0.8;
    final double r2 = tbsize * tbsize / 2.0;

    double d1 = m0[0] * m0[0] + m0[1] * m0[1];
    double d2 = m1[0] * m1[0] + m1[1] * m1[1];

    double sp1[] = {
      m0[0], m0[1], d1 < tbsize ? Math.sqrt(2.0 * tbsize - d1) : tbsize / Math.sqrt(d1)
    };
    double sp2[] = {
      m1[0], m1[1], d2 < tbsize ? Math.sqrt(2.0 * tbsize - d2) : tbsize / Math.sqrt(d2)
    };

    double axis[] = {
      sp2[1] * sp1[2] - sp2[2] * sp1[1],
      sp2[2] * sp1[0] - sp2[0] * sp1[2],
      sp2[0] * sp1[1] - sp2[1] * sp1[0]
    };

    double saxis[] = {axis[0], axis[1], axis[2]};

    normalize(axis);
    rotate_vq(axis, pCurr.r);

    sp2[0] -= sp1[0];
    sp2[1] -= sp1[1];
    sp2[2] -= sp1[2];

    double angle = Math.sqrt(sp2[0] * sp2[0] + sp2[1] * sp2[1] + sp2[2] * sp2[2]) / tbsize;

    if (angle > 1.0) angle = 1.0;
    if (angle < -1.0) angle = -1.0;

    angle = Math.asin(angle);

    final double ch = Math.cos(0.5 * angle);
    final double sh = Math.sin(0.5 * angle);

    double qr[] = {axis[0] * sh, axis[1] * sh, axis[2] * sh, ch};
    rotate_qq(pCurr.r, qr);
  }
  /**
   * Calculates the length of a given day. Uses the Calendar object to pass in the target date. The
   * hour, if not specified in the Calendar object, will default to 12.00 NOON. We need to convert
   * the dates between Julian & Gregorian and hour of the day impacts the generated Julian Day. Ref:
   * http://users.electromagnetic.net/bu/astro/sunrise-set.php
   *
   * @param cal - Gregorian calendar day for which the day length is to be calculated.
   * @param location - a lat/long position for which the DayLength is to be calculated.
   * @return - A DayLength object with with the Sunrise and Sunset for the given day.
   */
  public DayLength getLengthOfDay(Calendar cal, IGeoLocation location) {
    double latitudeNorth = location.getLatitude().getDegrees();
    double longitudeWest = location.getLatitude().getDegrees();

    latitudeNorth =
        location.getLatitude().getOrientation() == GeoOrientation.NORTH
            ? latitudeNorth
            : latitudeNorth * -1; // for degrees to the south, inverse sign.
    longitudeWest =
        location.getLongitude().getOrientation() == GeoOrientation.WEST
            ? longitudeWest
            : longitudeWest * -1; // for degrees to the east, inverse sign.

    Calendar gregorianDate = makeDefensiveCopy(cal);
    double julianDay = Calculations.toJulianValue(gregorianDate);
    long julianCycle = round((julianDay - JAN012000 - CYCLE_CONST) - (longitudeWest / 360));
    double approxSolarNoon = JAN012000 + CYCLE_CONST + longitudeWest / 360 + julianCycle;
    double meanSolarAnomaly = (357.5291 + 0.98560028 * (approxSolarNoon - JAN012000)) % 360;
    double equationOfCenter =
        (1.9148 * sin(meanSolarAnomaly))
            + (0.0200 * sin(2 * meanSolarAnomaly))
            + (0.0003 * sin(3 * meanSolarAnomaly));
    double longitudeOfSun = (meanSolarAnomaly + 102.9372 + equationOfCenter + 180) % 360;
    double julianSolarNoon =
        approxSolarNoon + (0.0053 * sin(meanSolarAnomaly)) - (0.0069 * sin(2 * longitudeOfSun));
    double sunDeclination = Math.asin(sin(longitudeOfSun) * sin(23.45));
    double hourAngle =
        Math.acos(
            (sin(-0.83) - sin(latitudeNorth) * sin(sunDeclination))
                / (cos(latitudeNorth) * cos(sunDeclination)));
    approxSolarNoon = JAN012000 + CYCLE_CONST + ((hourAngle + longitudeWest) / 360) + julianCycle;
    double julianSunSet =
        approxSolarNoon + (0.0053 * sin(meanSolarAnomaly)) - (0.0069 * sin(2 * longitudeOfSun));
    double julianRise = julianSolarNoon - (julianSunSet - julianSolarNoon);

    assert julianSunSet > julianRise
        : "The sunset value for " + julianDay + " is higher than the sunrise value";

    return new DayLength(julianRise, julianSunSet);
  }
Exemplo n.º 5
0
 /* Returns the arc sine of an angle, in the range of -pi/2 through pi/2.
  */
 public static SchemaTypeNumber asin(SchemaTypeNumber value) {
   switch (value.numericType()) {
     case SchemaTypeNumber.NUMERIC_VALUE_INT:
       return new SchemaInt((int) java.lang.Math.asin(value.doubleValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_LONG:
       return new SchemaLong((long) java.lang.Math.asin(value.doubleValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_BIGINTEGER:
       return new SchemaInteger(
           (long) java.lang.Math.asin(value.doubleValue())); // note: possible loss of precision
     case SchemaTypeNumber.NUMERIC_VALUE_FLOAT:
       return new SchemaFloat((float) java.lang.Math.asin(value.doubleValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_DOUBLE:
       return new SchemaDouble(java.lang.Math.asin(value.doubleValue()));
   }
   return new SchemaDecimal(java.lang.Math.asin(value.doubleValue()));
 }
Exemplo n.º 6
0
 public double pobierzKąt() {
   return java.lang.Math.asin(vy / sqrt(vy * vy + vx * vx));
 }
Exemplo n.º 7
0
    public void setFinalOrientations() {
      // blah blah blah.
      rightUpperFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
      rightLowerFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
      rightLowerFinalOrient.rotateX(0.5 * java.lang.Math.PI);
      rightFootFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
      rightFootFinalOrient.rotateX(0.5 * java.lang.Math.PI);

      if (KneelAnimation.this.oneKnee.booleanValue()) {
        double lengthSupportLeg = 0.0;

        if ((rightLower == null)) {
          leftUpperFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
          leftUpperFinalOrient.rotateX(0.25 * java.lang.Math.PI);
          leftFootFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
          leftFootFinalOrient.rotateX(-0.25 * java.lang.Math.PI);

          rightUpperFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
          rightUpperFinalOrient.rotateX(-0.25 * java.lang.Math.PI);
          rightFootFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
          rightFootFinalOrient.rotateX(0.25 * java.lang.Math.PI);
        }

        if ((rightUpper != null) && (rightLower != null)) {
          Vector3 posLower = rightLower.getPosition(rightUpper);
          edu.cmu.cs.stage3.math.Box boxLower = rightLower.getBoundingBox(rightLower);

          lengthSupportLeg =
              java.lang.Math.abs(posLower.y) + java.lang.Math.abs(boxLower.getMinimum().z);

          double lengthLowerLeg = 0.0;
          if (leftFoot != null)
            lengthLowerLeg =
                java.lang.Math.abs(leftFoot.getPosition(leftLower).y)
                    + java.lang.Math.abs(leftFoot.getBoundingBox(leftFoot).getMinimum().z);
          else
            lengthLowerLeg = java.lang.Math.abs(leftLower.getBoundingBox(leftLower).getMinimum().y);

          double diff = lengthSupportLeg - lengthLowerLeg;
          double angle =
              java.lang.Math.asin(java.lang.Math.abs(diff) / java.lang.Math.abs(posLower.y));

          if (lengthSupportLeg * 2.0 < lengthLowerLeg) {
            leftUpperFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
            leftLowerFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
            leftLowerFinalOrient.rotateX(0.25 * java.lang.Math.PI);
            leftFootFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
            leftFootFinalOrient.rotateX(-0.25 * java.lang.Math.PI);

            rightUpperFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
            rightLowerFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
            rightLowerFinalOrient.rotateX(-0.25 * java.lang.Math.PI);
            rightFootFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
            rightFootFinalOrient.rotateX(0.25 * java.lang.Math.PI);
          } else if (diff < 0) {
            leftUpperFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
            leftUpperFinalOrient.rotateX(-0.5 * java.lang.Math.PI - angle);
            leftLowerFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
            leftLowerFinalOrient.rotateX(0.5 * java.lang.Math.PI + angle);
            leftFootFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();

          } else {
            leftUpperFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
            leftUpperFinalOrient.rotateX(-0.5 * java.lang.Math.PI + angle);
            leftLowerFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
            leftLowerFinalOrient.rotateX(0.5 * java.lang.Math.PI - angle);
            leftFootFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
          }
        }
      } else {
        if ((rightLower == null)) {
          leftUpperFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
          leftUpperFinalOrient.rotateX(0.5 * java.lang.Math.PI);
          leftFootFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
          leftFootFinalOrient.rotateX(0.5 * java.lang.Math.PI);

          rightUpperFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
          rightUpperFinalOrient.rotateX(0.5 * java.lang.Math.PI);
          rightFootFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
          rightFootFinalOrient.rotateX(0.5 * java.lang.Math.PI);

        } else {
          leftUpperFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
          leftLowerFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
          leftLowerFinalOrient.rotateX(0.5 * java.lang.Math.PI);
          leftFootFinalOrient = new edu.cmu.cs.stage3.math.Matrix33();
          leftFootFinalOrient.rotateX(0.5 * java.lang.Math.PI);
        }
      }
    }
Exemplo n.º 8
0
 /** Returns the arc sine of the value at index location 0. */
 public double of(double[] d, int numParam) {
   return java.lang.Math.asin(d[0]);
 }