Example #1
0
  /**
   * Perform a great circle (spherical linear) interpolation between this quaternion and the
   * quaternion parameter.
   *
   * @param q The other quaternion.
   * @param alpha The interpolation parameter from the interval [0, 1].
   * @return The interpolated quaternion.
   */
  public final Quaternion interpolate(Quaternion q, float alpha) {
    // From "Advanced Animation and Rendering Techniques"
    // by Watt and Watt pg. 364, function as implemented appeared to be
    // incorrect. Fails to choose the same quaternion for the float
    // covering. Resulting in change of direction for rotations.
    // Fixed function to negate the first quaternion in the case that the
    // dot product of q and this is negative. Second case was not needed.
    float dot, s1, s2, om, sinom;

    dot = x * q.x + y * q.y + z * q.z + w * q.w;

    if (dot < 0) {
      q = q.negate();
      dot = -dot;
    }

    if ((1.0 - dot) > EPS) {
      om = (float) Math.acos(dot);
      sinom = (float) Math.sin(om);
      s1 = (float) Math.sin((1.0 - alpha) * om) / sinom;
      s2 = (float) Math.sin(alpha * om) / sinom;
    } else {
      s1 = 1.0f - alpha;
      s2 = alpha;
    }

    return new Quaternion(
        s1 * w + s2 * q.w, s1 * x + s2 * q.x, s1 * y + s2 * q.y, s1 * z + s2 * q.z);
  }
Example #2
0
 public static void getGlobalXYZfromGPSdata(double phi, double theta, double h, double[] XYZ) {
   double N =
       a / Math.sqrt(1.0 - e2 * Math.sin(phi * piGps / 180.0) * Math.sin(phi * piGps / 180.0));
   XYZ[0] = (N + h) * Math.cos(phi * piGps / 180.0) * Math.cos(theta * piGps / 180.0); // 	X
   XYZ[1] = (N + h) * Math.cos(phi * piGps / 180.0) * Math.sin(theta * piGps / 180.0); // 	Y
   XYZ[2] = (N * (1.0 - e2) + h) * Math.sin(phi * piGps / 180.0); // 	Z
   return;
 }
  @Test
  public void domain2PI() {
    double angles[] = new double[] {-0.1, -Math.PI, -0.4, 0.1, 0.4, 2.5, Math.PI};

    for (double angle : angles) {
      assertEquals(Math.cos(angle), Math.cos(UtilAngle.domain2PI(angle)), 1e-8);
      assertEquals(Math.sin(angle), Math.sin(UtilAngle.domain2PI(angle)), 1e-8);
    }
  }
  private void interpolateLine(int startX, int startY, int destX, int destY) {
    while (startX < 0 || startY < 0 || startX > m_width - 1 || startY > m_height - 1) {
      double direction = Math.atan2(destY - startY, destX - startX);
      startX += ceilInt(Math.cos(direction));
      startY += ceilInt(Math.sin(direction));
    }
    int startHeight = m_contour[startX][startY];
    int endHeight = m_contour[destX][destY];
    if (startHeight == endHeight) return;
    double distance = Math.sqrt(Math.pow(startX - destX, 2) + Math.pow(startY - destY, 2));
    double realX = startX;
    double realY = startY;
    double value = 1;
    while (value > 0) {
      if (Math.abs(destX - realX) < 1.2 && Math.abs(destY - realY) < 1.2) break;

      double direction = Math.atan2(destY - realY, destX - realX);
      value = Math.sqrt(Math.pow(realX - destX, 2) + Math.pow(realY - destY, 2)) / distance;
      double height;

      if (value < 0.5) height = (startHeight - endHeight) / 2 * Math.pow(value * 2, 3) + endHeight;
      else height = (startHeight - endHeight) / 2 * (Math.pow(value * 2 - 2, 3) + 2) + endHeight;

      double dx = Math.cos(direction);
      double dy = Math.sin(direction);
      if (dx == -1 || dx == 1) dy = 0;
      if (dy == -1 || dy == 1) dx = 0;

      realX += ceilInt(dx);
      realY += ceilInt(dy);
      int centerX = ceilInt(realX);
      int centerY = ceilInt(realY);

      double dTopX = Math.cos(direction + Math.PI / 2);
      double dTopY = Math.sin(direction + Math.PI / 2);
      int topX = ceilInt(realX + dTopX);
      int topY = ceilInt(realY + dTopY);

      double dBottomX = Math.cos(direction - Math.PI / 2);
      double dBottomY = Math.sin(direction - Math.PI / 2);
      int bottomX = ceilInt(realX + dBottomX);
      int bottomY = ceilInt(realY + dBottomY);

      if (m_antiAlias) {
        m_contour[centerX][centerY] =
            (int) (Math.sqrt(Math.pow(centerX - realX, 2) + Math.pow(centerY - realY, 2)) * height);
        m_contour[topX][topY] =
            (int) (Math.sqrt(Math.pow(topX - realX, 2) + Math.pow(topY - realY, 2)) * height);
        m_contour[bottomX][bottomY] =
            (int) (Math.sqrt(Math.pow(bottomX - realX, 2) + Math.pow(bottomY - realY, 2)) * height);
      } else {
        m_contour[centerX][centerY] = (int) height;
      }
    }
  }
Example #5
0
 private Position rot(Position pos) {
   double[][] turn = {
     {Math.cos(pos.getTheta()), -Math.sin(pos.getTheta())},
     {Math.sin(pos.getTheta()), Math.cos(pos.getTheta())}
   };
   double[][] vecPos = {{pos.getX(), pos.getY()}};
   double[][] relative = multiplicar(vecPos, turn);
   int rRows = relative.length;
   int rColumns = relative[0].length;
   return new Position(relative[0][0], relative[0][1], Math.atan2(relative[0][1], relative[0][0]));
 }
  public void move() {
    if (last_move_time == null || last_move_time.doubleValue() < world.time) {
      last_move_time = new Double(world.time);
      double max_dist, dist_right, dist_left, theta, x, y, dist_diff;
      double delta_theta, turn_radius, new_theta, new_x, new_y;
      Location location;
      Orientation orientation;

      orientation = orientation();
      location = location();

      max_dist = max_speed / world.ticks_per_second;
      dist_right = right_motor.output() * max_dist;
      dist_left = left_motor.output() * max_dist;
      theta = orientation.theta;
      x = location.x;
      y = location.y;
      old_location.x = x;
      old_location.y = y;
      dist_diff = dist_right - dist_left;

      //			System.out.println("dist_diff: " + dist_diff);

      delta_theta = dist_diff / wheel_base;
      if (Math.abs(dist_diff) < .0001) {
        turn_radius = 0.0;
      } else {
        turn_radius = (dist_right / delta_theta) - (wheel_base / 2);
      }

      //			System.out.println("turn_radius: " + turn_radius);

      new_theta = theta + delta_theta;
      if (turn_radius == 0.0) {

        //				System.out.println("turn_radius == 0");

        new_x = x + Math.cos(theta) * dist_left;
        new_y = y + Math.sin(theta) * dist_left;
      } else {

        //				System.out.println("new_theta= " + new_theta + " theta= " + theta);

        new_x = x + ((Math.sin(new_theta) - Math.sin(theta)) * turn_radius);
        new_y = y - ((Math.cos(new_theta) - Math.cos(theta)) * turn_radius);
      }
      orientation.theta = new_theta;
      location.x = new_x;
      location.y = new_y;

      maybe_fire_guns();
    }
  }
Example #7
0
 @DSGenerator(
     tool_name = "Doppelganger",
     tool_version = "2.0",
     generated_on = "2014-03-24 16:07:12.842 -0400",
     hash_original_method = "C663BE769BDA9250A705D77625E77C9D",
     hash_generated_method = "425A45736091487E5B9A0A89EB7E4A5D")
 public Point rotated(float radians) {
   // TODO(renn): Optimize: Keep cache of cos/sin values
   return new Point(
       (float) (Math.cos(radians) * x - Math.sin(radians) * y),
       (float) (Math.sin(radians) * x + Math.cos(radians) * y));
 }
  private void drawSunArrow(Graphics g, float angle, Color col, float scale) {
    float angleRad = (angle) * (float) java.lang.Math.PI / 180;
    int centerX = location.width / 2, centerY = location.height / 2;
    float arrowLength = roseRadius * scale;
    float halfArrowWidth = arrowLength * 0.08f;
    float circlePos = arrowLength * 0.7f;
    int circleRadius = (int) (arrowLength * 0.1f);

    int circleX = centerX + new Float(circlePos * java.lang.Math.sin(angleRad)).intValue();
    int circleY = centerY - new Float(circlePos * java.lang.Math.cos(angleRad)).intValue();

    int[] pointsX = new int[4];
    int[] pointsY = new int[4];

    pointsX[0] = centerX + new Float(arrowLength * java.lang.Math.sin(angleRad)).intValue();
    pointsY[0] = centerY - new Float(arrowLength * java.lang.Math.cos(angleRad)).intValue();
    pointsX[1] =
        centerX
            + new Float(halfArrowWidth * java.lang.Math.sin(angleRad + java.lang.Math.PI / 2.0))
                .intValue();
    pointsY[1] =
        centerY
            - new Float(halfArrowWidth * java.lang.Math.cos(angleRad + java.lang.Math.PI / 2.0))
                .intValue();
    pointsX[2] =
        centerX
            + new Float(halfArrowWidth * java.lang.Math.sin(angleRad + java.lang.Math.PI))
                .intValue();
    pointsY[2] =
        centerY
            - new Float(halfArrowWidth * java.lang.Math.cos(angleRad + java.lang.Math.PI))
                .intValue();
    pointsX[3] =
        centerX
            + new Float(halfArrowWidth * java.lang.Math.sin(angleRad - java.lang.Math.PI / 2.0))
                .intValue();
    pointsY[3] =
        centerY
            - new Float(halfArrowWidth * java.lang.Math.cos(angleRad - java.lang.Math.PI / 2.0))
                .intValue();

    // g.setPen(new Pen(col,Pen.SOLID,3));
    // g.drawLine(centerX,centerY,pointX,pointY);

    g.setPen(new Pen(Color.Black, Pen.SOLID, 1));
    g.setBrush(new Brush(col, Brush.SOLID));
    g.fillPolygon(pointsX, pointsY, 4);
    g.fillEllipse(
        circleX - circleRadius, circleY - circleRadius, 2 * circleRadius, 2 * circleRadius);
  }
Example #9
0
  @Override
  public void evaluate(Solution solution) {
    double[] theta = new double[numberOfObjectives - 1];

    double[] f = new double[numberOfObjectives];
    double[] x = EncodingUtils.getReal(solution);

    int k = numberOfVariables - numberOfObjectives + 1;

    double g = 0.0;
    for (int i = numberOfVariables - k; i < numberOfVariables; i++) {
      g += java.lang.Math.pow(x[i], 0.1);
    }

    double t = java.lang.Math.PI / (4.0 * (1.0 + g));
    theta[0] = x[0] * java.lang.Math.PI / 2;
    for (int i = 1; i < (numberOfObjectives - 1); i++) {
      theta[i] = t * (1.0 + 2.0 * g * x[i]);
    }

    for (int i = 0; i < numberOfObjectives; i++) {
      f[i] = 1.0 + g;

      for (int j = 0; j < numberOfObjectives - (i + 1); j++) {
        f[i] *= java.lang.Math.cos(theta[j]);
      }
      if (i != 0) {
        int aux = numberOfObjectives - (i + 1);
        f[i] *= java.lang.Math.sin(theta[aux]);
      }

      solution.setObjective(i, f[i]);
    }
  }
Example #10
0
  @Override
  public void update(GameContainer gc, StateBasedGame sb, int delta) {

    float rotation = owner.getRotation();
    float scale = owner.getScale();
    Vector2f position = owner.getPosition();

    Input input = gc.getInput();

    if (input.isKeyDown(Input.KEY_LEFT)) {
      rotation += -0.2f * delta;
    }

    if (input.isKeyDown(Input.KEY_RIGHT)) {
      rotation += 0.2f * delta;
    }

    if (input.isKeyDown(Input.KEY_UP)) {
      float hip = 0.45f * delta;

      position.x += hip * java.lang.Math.sin(java.lang.Math.toRadians(rotation));
      position.y -= hip * java.lang.Math.cos(java.lang.Math.toRadians(rotation));
    }

    owner.setPosition(position);
    owner.setRotation(rotation);
    owner.setScale(scale);
  }
  /** Расчет результата */
  public void calculation() {

    if (mathOperation.getTypeMathOperation() == TypeMathOperation.ADD) {
      lastResult = firstNumber + secondNumber;
    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.SUB) {
      lastResult = firstNumber - secondNumber;
    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.MUL) {
      lastResult = firstNumber * secondNumber;
    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.DIV) {

      // try {
      lastResult = firstNumber / secondNumber;
      // } catch (ArithmeticException rte){

      //    lastResult = 0;
      //    textMessage = "div by ZERO";
      //    changed();
      //    return;
      // }

    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.MRC) {
      mrc = lastResult;
    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.COS) {
      lastResult = (float) Math.cos(firstNumber);
    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.SIN) {
      lastResult = (float) Math.sin(firstNumber);
    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.TG) {
      lastResult = (float) Math.tan(firstNumber);
    } else if (mathOperation.getTypeMathOperation() == TypeMathOperation.CT) {
      lastResult = (float) 1 / ((float) Math.tan(firstNumber));
    }

    textMessage = "Result: " + String.valueOf(lastResult);
    changed();
  }
Example #12
0
  /*
   * requires a magnitude between -1 and 1 inclusive:
   * assumes that the angle is in degrees
   * calculates and sets the motor speeds for a given polar vector
   * allows for rotation while driving [-1,1]
   */
  private void driveMecanum() {

    /*
     * Does the computation of each motor speed value ever exceed the
     * range of -1.0, 1.0?  Just curious.
     *
     * - Mr. Ward
     */

    // RRLogger.logDebug(this.getClass(),"driveMecanum()", "driveMecanum()" );

    frontLeftMotor.set(-(l_magnitude + rotation) * Math.cos(Math.toRadians((l_angle + 45))));
    frontRightMotor.set((l_magnitude - rotation) * Math.sin(Math.toRadians(l_angle + 45)));
    backLeftMotor.set(-(l_magnitude + rotation) * Math.sin(Math.toRadians(l_angle + 45)));
    backRightMotor.set((l_magnitude - rotation) * Math.cos(Math.toRadians(l_angle + 45)));
  }
Example #13
0
 public Complex powi(float p) {
   float magnew = (float) Math.pow((double) abs(), (double) p);
   float phasenew = arg() * p;
   re = magnew * (float) Math.cos(phasenew);
   im = magnew * (float) Math.sin(phasenew);
   return this;
 }
Example #14
0
  /**
   * Evaluates a solution
   *
   * @param solution The solution to evaluate
   * @throws JMException
   */
  public void evaluate(Solution solution) throws JMException {
    DecisionVariables gen = solution.getDecisionVariables();

    double[] x = new double[numberOfVariables_];
    double[] f = new double[numberOfObjectives_];
    double[] theta = new double[numberOfObjectives_ - 1];
    int k = numberOfVariables_ - numberOfObjectives_ + 1;

    for (int i = 0; i < numberOfVariables_; i++) x[i] = gen.variables_[i].getValue();

    double g = 0.0;
    for (int i = numberOfVariables_ - k; i < numberOfVariables_; i++)
      g += java.lang.Math.pow(x[i], 0.1);

    double t = java.lang.Math.PI / (4.0 * (1.0 + g));
    theta[0] = x[0] * java.lang.Math.PI / 2;
    for (int i = 1; i < (numberOfObjectives_ - 1); i++) theta[i] = t * (1.0 + 2.0 * g * x[i]);

    for (int i = 0; i < numberOfObjectives_; i++) f[i] = 1.0 + g;

    for (int i = 0; i < numberOfObjectives_; i++) {
      for (int j = 0; j < numberOfObjectives_ - (i + 1); j++) f[i] *= java.lang.Math.cos(theta[j]);
      if (i != 0) {
        int aux = numberOfObjectives_ - (i + 1);
        f[i] *= java.lang.Math.sin(theta[aux]);
      } // if
    } // for

    for (int i = 0; i < numberOfObjectives_; i++) solution.setObjective(i, f[i]);
  } // evaluate
Example #15
0
  public void paintComponent(Graphics g) {
    double x = 200;
    double y = 200;
    Graphics2D g2 = (Graphics2D) g;
    Line2D.Double line1 =
        new Line2D.Double(
            x / 2,
            0,
            (x / 2) - (x / 2) * Math.cos(Math.PI / 6),
            (y / 2) + (y / 2) * Math.sin(Math.PI / 6));
    Line2D.Double line2 =
        new Line2D.Double(
            x / 2,
            0,
            (x / 2) + (x / 2) * Math.cos(Math.PI / 6),
            (y / 2) + (y / 2) * Math.sin(Math.PI / 6));
    Line2D.Double line3 =
        new Line2D.Double(
            (x / 2) - (x / 2) * Math.cos(Math.PI / 6),
            (y / 2) + (y / 2) * Math.sin(Math.PI / 6),
            (x / 2) + (x / 2) * Math.cos(Math.PI / 6),
            (y / 2) + (y / 2) * Math.sin(Math.PI / 6));
    Line2D.Double line4 =
        new Line2D.Double(
            x / 2,
            y,
            x / 2 - (x / 2) * Math.cos(Math.PI / 6),
            y / 2 - (y / 2) * Math.sin(Math.PI / 6));
    Line2D.Double line5 =
        new Line2D.Double(
            x / 2,
            y,
            x / 2 + (x / 2) * Math.cos(Math.PI / 6),
            y / 2 - (y / 2) * Math.sin(Math.PI / 6));
    Line2D.Double line6 =
        new Line2D.Double(
            x / 2 - (x / 2) * Math.cos(Math.PI / 6),
            y / 2 - (y / 2) * Math.sin(Math.PI / 6),
            x / 2 + (x / 2) * Math.cos(Math.PI / 6),
            y / 2 - (y / 2) * Math.sin(Math.PI / 6));
    // Line2D.Double line7 = new Line2D.Double();
    // Line2D.Double line8 = new Line2D.Double(65,100,40,170);
    // Line2D.Double line9 = new Line2D.Double(40,170,100,125);
    // Line2D.Double line10 = new Line2D.Double(160,170,100,125);

    g2.draw(line1);
    g2.draw(line2);
    g2.draw(line3);
    g2.draw(line4);
    g2.draw(line5);
    g2.draw(line6);
    // g2.draw(line7);
    // g2.draw(line8);
    // g2.draw(line9);
    // g2.draw(line10);
  }
Example #16
0
  /// @pre temps > 0
  /// @post Retorna una taula(t). t[0] i t[1] són les coordenades de n després de que hagui passat
  // temps iteracions
  double[] preveurePosicio(Nau n, double temps) {
    double dx = temps * n.velocitat_ * Math.cos(Math.toRadians(n.angleVelocitat_));
    double dy = temps * n.velocitat_ * -Math.sin(Math.toRadians(n.angleVelocitat_));

    double[] t = n.obtenirCentreTriangle();
    double centrex = t[0];
    double centrey = t[1];

    double[] previsio = {centrex + dx, centrey + dy};
    return previsio;
  }
Example #17
0
  public Position placeObstacle(Position robotPos, Bearing landmark) {
    Position rotlandMark = new Position(0, 0, 0); // position data for rotating landmark
    Position result =
        new Position(0, 0, 0); // position data holding dist and angle to landmark from particle

    rotlandMark.setX(landmark.getR() * Math.cos(landmark.getTheta()));
    rotlandMark.setY(landmark.getR() * Math.sin(landmark.getTheta()));
    rotlandMark.setTheta(-landmark.getTheta());
    result = rot(rotlandMark);

    return new Position(result.getX() + robotPos.getX(), result.getY() + robotPos.getY(), 0);
  }
  private void drawThickArrow(Graphics g, float angle, Color col, float scale) {
    float angleRad = (angle) * (float) java.lang.Math.PI / 180;
    int centerX = location.width / 2, centerY = location.height / 2;
    float arrowLength = roseRadius * scale;
    float halfArrowWidth = arrowLength * 0.1f;

    int[] pointsX = new int[4];
    int[] pointsY = new int[4];

    pointsX[0] = centerX + new Float(arrowLength * java.lang.Math.sin(angleRad)).intValue();
    pointsY[0] = centerY - new Float(arrowLength * java.lang.Math.cos(angleRad)).intValue();
    pointsX[1] =
        centerX
            + new Float(halfArrowWidth * java.lang.Math.sin(angleRad + java.lang.Math.PI / 2.0))
                .intValue();
    pointsY[1] =
        centerY
            - new Float(halfArrowWidth * java.lang.Math.cos(angleRad + java.lang.Math.PI / 2.0))
                .intValue();
    pointsX[2] =
        centerX
            + new Float(halfArrowWidth * java.lang.Math.sin(angleRad + java.lang.Math.PI))
                .intValue();
    pointsY[2] =
        centerY
            - new Float(halfArrowWidth * java.lang.Math.cos(angleRad + java.lang.Math.PI))
                .intValue();
    pointsX[3] =
        centerX
            + new Float(halfArrowWidth * java.lang.Math.sin(angleRad - java.lang.Math.PI / 2.0))
                .intValue();
    pointsY[3] =
        centerY
            - new Float(halfArrowWidth * java.lang.Math.cos(angleRad - java.lang.Math.PI / 2.0))
                .intValue();

    g.setPen(new Pen(Color.Black, Pen.SOLID, 1));
    g.setBrush(new Brush(col, Brush.SOLID));
    g.fillPolygon(pointsX, pointsY, 4);
  }
  protected void rotatePoints() {

    if (counter < 17) {
      for (int i = 0; i < xValues.length; i++)
        tempX[i] =
            (int) (xValues[i] * Math.cos(3.14159265 / 12) + yValues[i] * Math.sin(3.14159265 / 12));
      for (int i = 0; i < yValues.length; i++)
        tempY[i] =
            (int)
                (xValues[i] * (-Math.sin(3.14159265 / 12))
                    + yValues[i] * Math.cos(3.14159265 / 12));
      counter++;
    }

    if (counter == 17) {
      tempX = xValues;
      tempY = xValues;
      counter = 0;
    }

    star2 = new Polygon(tempX, tempY, 8);
  }
  private void drawThinArrow(Graphics g, float angle, Color col, Color colPoint, float scale) {
    float angleRad = (angle) * (float) java.lang.Math.PI / 180;
    int centerX = location.width / 2, centerY = location.height / 2;
    float arrowLength = roseRadius * scale;
    float halfOpeningAngle = (float) (java.lang.Math.PI * 0.03);
    float sideLineLength = arrowLength * 0.75f;

    int[] pointsX = new int[4];
    int[] pointsY = new int[4];

    pointsX[0] =
        centerX
            + new Float(sideLineLength * java.lang.Math.sin(angleRad - halfOpeningAngle))
                .intValue();
    pointsY[0] =
        centerY
            - new Float(sideLineLength * java.lang.Math.cos(angleRad - halfOpeningAngle))
                .intValue();
    pointsX[1] = centerX + new Float(arrowLength * java.lang.Math.sin(angleRad)).intValue();
    pointsY[1] = centerY - new Float(arrowLength * java.lang.Math.cos(angleRad)).intValue();
    pointsX[2] =
        centerX
            + new Float(sideLineLength * java.lang.Math.sin(angleRad + halfOpeningAngle))
                .intValue();
    pointsY[2] =
        centerY
            - new Float(sideLineLength * java.lang.Math.cos(angleRad + halfOpeningAngle))
                .intValue();
    pointsX[3] = centerX;
    pointsY[3] = centerY;

    g.setPen(new Pen(Color.Black, Pen.SOLID, 1));
    g.setBrush(new Brush(col, Brush.SOLID));
    g.fillPolygon(pointsX, pointsY, 4);
    if (colPoint != null) {
      g.setBrush(new Brush(colPoint, Brush.SOLID));
      g.fillPolygon(pointsX, pointsY, 3);
    }
  }
Example #21
0
 /*
  * initialize the fire particles
  */
 public void init() {
   // initialize the inner particles
   for (int i = 0; i < parti_num; ++i) {
     parti_obj[INNER][i].x = width / 3 + (float) (width / 3 * Math.random());
     parti_obj[INNER][i].y =
         Math.random()
             * height
             / 2
             * Math.sin(((parti_obj[INNER][i].x - width / 3) * Math.PI * 3 / width));
     parti_obj[INNER][i].color = 0xffff9d00;
     parti_obj[INNER][i].life = (int) Math.random() * 100;
     parti_obj[INNER][i].speedX = 5 + Math.random() * 5;
     parti_obj[INNER][i].speedY = 5 + Math.random() * 5;
     parti_obj[INNER][i].accX = 2 + Math.random();
     parti_obj[INNER][i].accY = 2 + Math.random();
   }
   // initialize the middle particles
   for (int i = 0; i < parti_num; ++i) {
     parti_obj[MID][i].x = (float) (width * Math.random());
     if (parti_obj[MID][i].x >= width * 2 / 3 || parti_obj[MID][i].x <= width / 3) {
       parti_obj[MID][i].y =
           Math.random() * height * 3 / 4 * Math.sin((parti_obj[MID][i].x * Math.PI / width));
     } else {
       parti_obj[MID][i].y =
           height / 2 * Math.sin(((parti_obj[INNER][i].x - width / 3) / Math.PI * 3 / width))
               + Math.random()
                   * (height * 3 / 4 * Math.sin((parti_obj[MID][i].x * Math.PI / width))
                       - height
                           / 2
                           * Math.sin(
                               ((parti_obj[INNER][i].x - width / 3) / Math.PI * 3 / width)));
     }
     parti_obj[MID][i].color = 0xffffa734;
     parti_obj[MID][i].life = (int) Math.random() * 100;
     parti_obj[MID][i].speedX = 5 + Math.random() * 5;
     parti_obj[MID][i].speedY = 5 + Math.random() * 5;
     parti_obj[MID][i].accX = 2 + Math.random();
     parti_obj[MID][i].accY = 2 + Math.random();
   }
   // initialize the outer particles
   for (int i = 0; i < parti_num; ++i) {
     parti_obj[OUTER][i].x = (float) (width * Math.random());
     parti_obj[OUTER][i].y =
         height * 3 / 4 * Math.sin((parti_obj[MID][i].x * Math.PI / width))
             + Math.random() * (height / 4 * Math.sin((parti_obj[MID][i].x * Math.PI / width)));
     parti_obj[OUTER][i].color = 0xfff55700;
     parti_obj[OUTER][i].life = (int) Math.random() * 100;
     parti_obj[OUTER][i].speedX = Math.random() * 5;
     parti_obj[OUTER][i].speedY = Math.random() * 5;
     parti_obj[OUTER][i].accX = Math.random();
     parti_obj[OUTER][i].accY = Math.random();
   }
 }
 public Coord3f rot(Coord3f p, float a) {
   float c = (float) Math.cos(a), s = (float) Math.sin(a), C = 1.0f - c;
   float ax = p.x, ay = p.y, az = p.z;
   return (new Coord3f(
       (x * ((ax * ax * C) + c))
           + (y * ((ay * ax * C) - (az * s)))
           + (z * ((az * ax * C) + (ay * s))),
       (x * ((ax * ay * C) + (az * s)))
           + (y * ((ay * ay * C) + c))
           + (z * ((az * ay * C) - (ax * s))),
       (x * ((ax * az * C) - (ay * s)))
           + (y * ((ay * az * C) + (ax * s)))
           + (z * ((az * az * C) + c))));
 }
  /**
   * When scanning a robot we need to add it to the collection of scanned objects so it can be used
   * later for updates to the bots movement.
   */
  public void onScannedRobot(ScannedRobotEvent e) {
    double targetBearing = getHeading() + e.getBearing();
    double tmpX = getX() + e.getDistance() * Math.sin(Math.toRadians(targetBearing));
    double tmpY = getY() + e.getDistance() * Math.cos(Math.toRadians(targetBearing));
    String name = e.getName();

    if (name.equals(GOAL_NAME)) {
      foundGoal = true;
    }

    obstacles.put(name, new Enemy(tmpX, tmpY, e.getBearing()));

    setTurnRadarRight(getRadarTurnRemaining());
  }
  @Override
  public void onScannedRobot(ScannedRobotEvent event) {
    /**
     * ScannedRobotEvent не содержит в себе явно положения противника, однако, его легко вычислить,
     * зная направление своего корпуса, беаринг (по сути угол относительный чего-то, в данном случае
     * относительно корпуса) и расстояние до противника
     */

    // абсолютный угол до противника
    final double alphaToEnemy = getHeadingRadians() + event.getBearingRadians();

    // а далее элементарная геометрия
    enemyX = getX() + Math.sin(alphaToEnemy) * event.getDistance();
    enemyY = getY() + Math.cos(alphaToEnemy) * event.getDistance();
  }
Example #25
0
    public void setHoverPosition(GL10 gl, int nFlags, Planet m_Planet) {

      gl.glMatrixMode(GL10.GL_MODELVIEW);
      gl.glLoadIdentity();
      Quaternion orientation = Miniglu.gluGetOrientation();

      Vector3 vpLoc = new Vector3(0.0f, 0.0f, 0.0f);
      vpLoc.x = m_Eyeposition[0];
      vpLoc.y = m_Eyeposition[1];
      vpLoc.z = m_Eyeposition[2];

      Vector3 objectLoc = new Vector3(0.0f, 0.0f, 0.0f);
      objectLoc.x = m_Planet.m_Pos[0];
      objectLoc.y = m_Planet.m_Pos[1];
      objectLoc.z = m_Planet.m_Pos[2];

      Vector3 offset = new Vector3(0.0f, 0.0f, 0.0f);
      offset.x = (objectLoc.x - vpLoc.x);
      offset.y = (objectLoc.y - vpLoc.y);
      offset.z = (objectLoc.z - vpLoc.z);

      Vector3 offsetv = new Vector3(0.0f, 0.0f, 0.0f);
      offsetv.z = Vector3Distance(objectLoc, vpLoc);

      gl.glMatrixMode(GL10.GL_MODELVIEW);

      // Rotate around the Y-axis.

      float s = (float) Math.sin(0.0005);
      float c = (float) Math.cos(0.0005);

      Quaternion tempQ2 = new Quaternion(0, s, 0, c);
      tempQ2 = tempQ2.mulThis(orientation);
      orientation = tempQ2;

      float matrix3[][] = new float[3][3];
      matrix3 = orientation.toMatrix();
      matrix3 = orientation.tranposeMatrix(matrix3);
      offsetv = orientation.Matrix3MultiplyVector3(matrix3, offsetv);

      m_Eyeposition[0] = (float) (objectLoc.x + offsetv.x);
      m_Eyeposition[1] = (float) (objectLoc.y + offsetv.y);
      m_Eyeposition[2] = (float) (objectLoc.z + offsetv.z);

      lookAtTarget(gl, m_Planet);
    }
Example #26
0
 public void update() {
   for (int j = 0; j < parti_num; ++j) {
     Parti_obj obj = parti_obj[INNER][j];
     obj.x += obj.speedX;
     obj.y += obj.speedY;
     obj.speedX += obj.accX;
     obj.speedY += obj.accY;
     if (obj.x < width / 3
         || obj.x > width * 2 / 3
         || obj.y - height / 4 > height / 2 * Math.sin(((obj.x - width / 3) / Math.PI * 3 / width))
         || obj.y < 0) {
       reset(obj, INNER);
     }
   }
   for (int j = 0; j < parti_num; ++j) {
     Parti_obj obj = parti_obj[MID][j];
     obj.x += obj.speedX;
     obj.y += obj.speedY;
     obj.speedX += obj.accX;
     obj.speedY += obj.accY;
     if (obj.x >= width * 2 / 3 || obj.x <= width / 3) {
       if (obj.x < 0
           || obj.x > width
           || obj.y - height / 4 > height * 3 / 4 * Math.sin((obj.x * Math.PI / width))
           || obj.y < 0) {
         reset(obj, MID);
       }
     } else {
       if (obj.y - height / 4 > height * 3 / 4 * Math.sin((obj.x * Math.PI / width))
           || obj.y + height / 4
               < height / 2 * Math.sin(((obj.x - width / 3) / Math.PI * 3 / width))
           || obj.y < 0) {
         reset(obj, MID);
       }
     }
   }
   for (int j = 0; j < parti_num; ++j) {
     Parti_obj obj = parti_obj[OUTER][j];
     obj.x += obj.speedX;
     obj.y += obj.speedY;
     obj.speedX += obj.accX;
     obj.speedY += obj.accY;
     if (obj.x < 0
         || obj.x > width
         || obj.y - height / 4 > height * Math.sin((obj.x * Math.PI / width))
         || obj.y + height / 4 < height * 3 / 4 * Math.sin((obj.x * Math.PI / width))
         || obj.y < 0) {
       reset(obj, OUTER);
     }
   }
 }
Example #27
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);
  }
Example #28
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);
  }
  private double getBodyTurn() {
    // а вот вычисление угла поворота посложее
    final double alphaToMe = angleTo(enemyX, enemyY, getX(), getY());

    // определяем угловое направление относительно противника (по часовой стрелке, либо против) ...
    final double lateralDirection =
        signum(
            (getVelocity() != 0 ? getVelocity() : 1)
                * Math.sin(Utils.normalRelativeAngle(getHeadingRadians() - alphaToMe)));
    // получаем желаемое направление движения
    final double desiredHeading =
        Utils.normalAbsoluteAngle(alphaToMe + Math.PI / 2 * lateralDirection);
    // нормализуем направление по скорости
    final double normalHeading =
        getVelocity() >= 0
            ? getHeadingRadians()
            : Utils.normalAbsoluteAngle(getHeadingRadians() + Math.PI);
    // и возвращаем угол поворта
    return Utils.normalRelativeAngle(desiredHeading - normalHeading);
  }
Example #30
0
  private void carveCanyon(int x, int y, double direction, int depth) {
    int nextX = x;
    int nextY = y;
    while (nextX > 0 && nextY > 0 && nextY < m_height - 1 && nextX < m_width - 1 && depth > 0) {
      sculptHill(nextX, nextY, -depth, 10, true);
      /*for(int i = Math.max(0,nextX-6);i<Math.min(m_width-1, nextX+6);i++) {
      	for(int j = Math.max(0,nextY-6);j<Math.min(m_height-1,nextY+6);j++) {
      		m_contour[i][j] = -depth;
      	}
      }*/
      double choice = m_random.nextGaussian();
      choice = 0;
      if (choice > 0.7) direction += m_random.nextDouble() * Math.PI * 2;
      if (choice < -0.7) direction -= m_random.nextDouble() * Math.PI * 2;

      double dx = Math.cos(direction);
      double dy = Math.sin(direction);
      nextX += Math.ceil(Math.abs(dx)) * ((dx < 0) ? -1 : 1);
      nextY += Math.ceil(Math.abs(dy)) * ((dy < 0) ? -1 : 1);
    }
  }