Exemplo n.º 1
0
  private void renderBlackout(Graphics g, int x, int y, int radius) {
    if (radius > 320) return;

    int[] xp = new int[20];
    int[] yp = new int[20];
    for (int i = 0; i < 16; i++) {
      xp[i] = x + (int) (Math.cos(i * Math.PI / 15) * radius);
      yp[i] = y + (int) (Math.sin(i * Math.PI / 15) * radius);
    }
    xp[16] = 320;
    yp[16] = y;
    xp[17] = 320;
    yp[17] = 240;
    xp[18] = 0;
    yp[18] = 240;
    xp[19] = 0;
    yp[19] = y;
    g.fillPolygon(xp, yp, xp.length);

    for (int i = 0; i < 16; i++) {
      xp[i] = x - (int) (Math.cos(i * Math.PI / 15) * radius);
      yp[i] = y - (int) (Math.sin(i * Math.PI / 15) * radius);
    }
    xp[16] = 320;
    yp[16] = y;
    xp[17] = 320;
    yp[17] = 0;
    xp[18] = 0;
    yp[18] = 0;
    xp[19] = 0;
    yp[19] = y;

    g.fillPolygon(xp, yp, xp.length);
  }
Exemplo n.º 2
0
  /* CALCULATE COORDINATES: Determine new x-y coords given a start x-y and
  a distance and direction */
  public static void calcCoords(int index, int x, int y, double dist, double dirn) {
    while (dirn < 0.0) dirn = 360.0 + dirn;
    while (dirn > 360.0) dirn = dirn - 360.0;
    // System.out.println("dirn = " + dirn);

    // North-East
    if (dirn <= 90.0) {
      xValues[index] = x + (int) (Math.sin(Math.toRadians(dirn)) * dist);
      yValues[index] = y - (int) (Math.cos(Math.toRadians(dirn)) * dist);
      return;
    }
    // South-East
    if (dirn <= 180.0) {
      xValues[index] = x + (int) (Math.cos(Math.toRadians(dirn - 90)) * dist);
      yValues[index] = y + (int) (Math.sin(Math.toRadians(dirn - 90)) * dist);
      return;
    }
    // South-West
    if (dirn <= 90.0) {
      xValues[index] = x - (int) (Math.sin(Math.toRadians(dirn - 180)) * dist);
      yValues[index] = y + (int) (Math.cos(Math.toRadians(dirn - 180)) * dist);
    }
    // Nort-West
    else {
      xValues[index] = x - (int) (Math.cos(Math.toRadians(dirn - 270)) * dist);
      yValues[index] = y - (int) (Math.sin(Math.toRadians(dirn - 270)) * dist);
    }
  }
Exemplo n.º 3
0
  /**
   * Uses the Haversine formula to calculate the distnace between to lat-long coordinates
   *
   * @param latitude1 The first point's latitude
   * @param longitude1 The first point's longitude
   * @param latitude2 The second point's latitude
   * @param longitude2 The second point's longitude
   * @return The distance between the two points in meters
   */
  public static double CalculateDistance(
      double latitude1, double longitude1, double latitude2, double longitude2) {
    /*
    Haversine formula:
    A = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
    C = 2.atan2(√a, √(1−a))
    D = R.c
    R = radius of earth, 6371 km.
    All angles are in radians
    */

    double deltaLatitude = Math.toRadians(Math.abs(latitude1 - latitude2));
    double deltaLongitude = Math.toRadians(Math.abs(longitude1 - longitude2));
    double latitude1Rad = Math.toRadians(latitude1);
    double latitude2Rad = Math.toRadians(latitude2);

    double a =
        Math.pow(Math.sin(deltaLatitude / 2), 2)
            + (Math.cos(latitude1Rad)
                * Math.cos(latitude2Rad)
                * Math.pow(Math.sin(deltaLongitude / 2), 2));

    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

    return 6371 * c * 1000; // Distance in meters
  }
Exemplo n.º 4
0
  double score(IGMap map, DoubleOrientedPoint p, double[] readings) {
    double s = 0;
    int angleIndex = initialBeamsSkip;
    DoubleOrientedPoint lp = new DoubleOrientedPoint(p.x, p.y, p.theta);
    lp.x += Math.cos(p.theta) * laserPose.x - Math.sin(p.theta) * laserPose.y;
    lp.y += Math.sin(p.theta) * laserPose.x + Math.cos(p.theta) * laserPose.y;
    lp.theta += laserPose.theta;
    int skip = 0;
    double freeDelta = map.getDelta() * freeCellRatio;
    for (int rIndex = initialBeamsSkip; rIndex < readings.length; rIndex++, angleIndex++) {
      skip++;
      skip = skip > likelihoodSkip ? 0 : skip;
      if (skip != 0 || readings[rIndex] > usableRange || readings[rIndex] == 0.0) continue;
      DoublePoint phit = new DoublePoint(lp.x, lp.y);
      phit.x += readings[rIndex] * Math.cos(Utils.theta(lp.theta + laserAngles[angleIndex]));
      phit.y += readings[rIndex] * Math.sin(Utils.theta(lp.theta + laserAngles[angleIndex]));
      IntPoint iphit = map.world2map(phit);
      DoublePoint pfree = new DoublePoint(lp.x, lp.y);
      pfree.x +=
          (readings[rIndex] - map.getDelta() * freeDelta)
              * Math.cos(Utils.theta(lp.theta + laserAngles[angleIndex]));
      pfree.y +=
          (readings[rIndex] - map.getDelta() * freeDelta)
              * Math.sin(Utils.theta(lp.theta + laserAngles[angleIndex]));
      pfree.x = pfree.x - phit.x;
      pfree.y = pfree.y - phit.y;

      IntPoint ipfree = map.world2map(pfree);
      boolean found = false;
      DoublePoint bestMu = new DoublePoint(0., 0.);
      for (int xx = -kernelSize; xx <= kernelSize; xx++) {
        for (int yy = -kernelSize; yy <= kernelSize; yy++) {
          IntPoint pr = new IntPoint(iphit.x + xx, iphit.y + yy);
          IntPoint pf = new IntPoint(pr.x + ipfree.x, pr.y + ipfree.y);
          // int ss = map.getStorage().cellState(pr);
          //                    if ((ss) > 0) {
          PointAccumulator cell = (PointAccumulator) map.cell(pr, true);
          PointAccumulator fcell = (PointAccumulator) map.cell(pf, true);
          if (cell != null && fcell != null) {
            if (cell.doubleValue() > fullnessThreshold && fcell.doubleValue() < fullnessThreshold) {
              DoublePoint mu = DoublePoint.minus(phit, cell.mean());
              if (!found) {
                bestMu = mu;
                found = true;
              } else {
                bestMu = DoublePoint.mulD(mu, mu) < DoublePoint.mulD(bestMu, bestMu) ? mu : bestMu;
              }
            }
          }
          //                    }
        }
      }
      if (found) {
        s += Math.exp(-1. / (gaussianSigma * DoublePoint.mulD(bestMu, bestMu)));
      }
    }
    return s;
  }
Exemplo n.º 5
0
 public static double distance(double lat1, double lon1, double lat2, double lon2) {
   double theta = lon1 - lon2;
   double dist =
       Math.sin(deg2rad(lat1)) * Math.sin(deg2rad(lat2))
           + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.cos(deg2rad(theta));
   dist = Math.acos(dist);
   dist = rad2deg(dist);
   dist = dist * 60 * 1.85315962;
   return (dist);
 }
Exemplo n.º 6
0
  /*======== public void generateSphere() ==========
      Inputs:   double cx
                double cy
  double r
  double step
      Returns:

      Generates all the points along the surface of a
      sphere with center (cx, cy) and radius r

      Adds these points to the matrix parameter

      jonalf
      ====================*/
  public void generateSphere(double cx, double cy, double r, double step) {
    double f, t;
    for (f = 0; f < 1; f += step) {
      for (t = 0; t < 1; t += step) {
        double x = r * Math.cos(Math.PI * 2 * t) + cx;
        double y = r * Math.sin(Math.PI * 2 * t) * Math.cos(Math.PI * f) + cy;
        double z = r * Math.sin(Math.PI * 2 * t) * Math.sin(Math.PI * f);
        addPoint(x, y, z);
      }
    }
  }
Exemplo n.º 7
0
  /*======== public void generateTorus() ==========
      Inputs:   double cx
                double cy
  double r1
  double r2
  double step
      Returns:

      Generates all the points along the surface of a
      tarus with center (cx, cy) and radii r1 and r2

      Adds these points to the matrix parameter

      jonalf
      ====================*/
  public void generateTorus(double cx, double cy, double r1, double r2, double step) {
    double f, t;
    for (f = 0; f < 1; f += step) {
      for (t = 0; t < 1; t += step) {
        double x = Math.cos(Math.PI * 2 * f) * (r2 * Math.cos(Math.PI * 2 * t) + r1) + cx;
        double y = r2 * Math.sin(Math.PI * 2 * t) + cy;
        double z = -1 * Math.sin(Math.PI * 2 * f) * (r2 * Math.cos(Math.PI * 2 * t) + r1);
        addPoint(x, y, z);
      }
    }
  }
Exemplo n.º 8
0
  public static double calAlpha(double theta, double dec) {
    if (Math.abs(dec) + theta > 89.9) return 180;

    return (double)
        Math.toDegrees(
            Math.abs(
                Math.atan(
                    Math.sin(Math.toRadians(theta))
                        / Math.sqrt(
                            Math.cos(Math.toRadians(dec - theta))
                                * Math.cos(Math.toRadians(dec + theta))))));
  }
  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();
    }
  }
Exemplo n.º 10
0
  /**
   * Rotate the oriented bounding box of the 3D image about the specified axis with the specified
   * angle.
   *
   * @param transform The transform and its matrix by which to rotate the image.
   */
  public void rotateFrameBy(Transform3D transform) {

    double rY, rX, rZ;
    double sinrX, sinrY, sinrZ, cosrX, cosrY, cosrZ;
    Matrix3d matrix = new Matrix3d();

    transform.get(matrix);

    rY = -Math.asin(matrix.m02);

    if (Math.cos(rY) != 0) {
      rX = -Math.atan2(matrix.m12, matrix.m22);
      rZ = Math.atan2(matrix.m01, matrix.m00);
    } else {
      rX = -Math.atan2(matrix.m10, matrix.m11);
      rZ = 0;
    }

    cosrX = Math.cos(rX);
    sinrX = Math.sin(rX);
    cosrY = Math.cos(rY);
    sinrY = Math.sin(rY);
    cosrZ = Math.cos(rZ);
    sinrZ = Math.sin(rZ);

    matrix.m00 = cosrZ * cosrY;
    matrix.m01 = -sinrZ * cosrY;
    matrix.m02 = sinrY;

    matrix.m10 = (cosrZ * sinrY * sinrX) + (sinrZ * cosrX);
    matrix.m11 = (-sinrZ * sinrY * sinrX) + (cosrZ * cosrX);
    matrix.m12 = -cosrY * sinrX;

    matrix.m20 = (-cosrZ * sinrY * cosrX) + (sinrZ * sinrX);
    matrix.m21 = (sinrZ * sinrY * cosrX) + (cosrZ * sinrX);
    matrix.m22 = cosrY * cosrX;

    m_kRotate.set(matrix);
    m_akAxis[0] = new Vector3f(1.0f, 0.0f, 0.0f);
    m_akAxis[1] = new Vector3f(0.0f, 1.0f, 0.0f);
    m_akAxis[2] = new Vector3f(0.0f, 0.0f, 1.0f);

    for (int i = 0; i < 3; i++) {
      m_kRotate.transform(m_akAxis[i]);
    }

    orthonormalize(m_akAxis);

    for (int i = 0; i < 3; i++) {
      setAxis(i, m_akAxis[i]);
    }
  }
Exemplo n.º 11
0
    void draw(Graphics2D g) {

      // toX/toY is tip of arrow and fx/fy is a point on the line -
      // fx/fy is used to determine direction & angle

      AffineTransform at = AffineTransform.getTranslateInstance(toX, toY);
      int b = 9;
      double theta = Math.toRadians(20);
      // The idea of using a GeneralPath is so we can
      // create the (three lines that make up the) arrow
      // (only) one time and then use AffineTransform to
      // place it anywhere we want.
      GeneralPath path = new GeneralPath();

      // distance between line and the arrow mark <** not **
      // Start a new line segment from the position of (0,0).
      path.moveTo(0, 0);
      // Create one of the two arrow head lines.
      int x = (int) (-b * Math.cos(theta));
      int y = (int) (b * Math.sin(theta));
      path.lineTo(x, y);

      // distance between line and the arrow mark <** not **
      // Make the other arrow head line.
      int x2 = (int) (-b * Math.cos(-theta));
      int y2 = (int) (b * Math.sin(-theta));
      // path.moveTo(0,0);
      path.lineTo(x2, y2);
      path.closePath();

      // theta is in radians
      double s, t;
      s = toY - fy; // calculate slopes.
      t = toX - fx;
      if (t != 0) {
        s = s / t;
        theta = Math.atan(s);
        if (t < 0) theta += Math.PI;
      } else if (s < 0) theta = -(Math.PI / 2);
      else theta = Math.PI / 2;

      at.rotate(theta);
      // at.rotate(theta,toX,toY);
      Shape shape = at.createTransformedShape(path);
      if (checkStatus == Status.UNCHECKED) g.setColor(Color.BLACK);
      else if (checkStatus == Status.COMPATIBLE) g.setColor(FOREST_GREEN);
      else g.setColor(ORANGE_RED);
      g.fill(shape);
      g.draw(shape);
    }
Exemplo n.º 12
0
 /**
  * @author Bogdan Sliptsov
  *     <p>Calculates the distance in km between two lat/long points using the haversine formula
  */
 public double distanceGPS(double lat1, double lng1, double lat2, double lng2) {
   int r = 6371; // average radius of the Earth in km
   double dLat = Math.toRadians(lat2 - lat1);
   double dLon = Math.toRadians(lng2 - lng1);
   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);
   double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
   double d = r * c;
   return d;
 }
Exemplo n.º 13
0
  void drawingCommands() {
    // Rotation about z:
    double theta = Math.PI / 3.0;
    double a11 = Math.cos(theta);
    double a12 = -Math.sin(theta);
    double a21 = Math.sin(theta);
    double a22 = Math.cos(theta);
    double[][] A = {
      {a11, a12, 0, 0},
      {a21, a22, 0, 0},
      {0, 0, 1, 0},
      {0, 0, 0, 1}
    };

    /*
    // INSERT YOUR CODE for rotation about x by 30 degrees
    double[][] B = {

    };

    // INSERT YOUR CODE for translation by (2,3,4)
    double[][] C = {

    };

    double[][] temp = MatrixTool.matrixMult (B,A);
    double[][] transform = MatrixTool.matrixMult (C,temp);
    */

    // Replace this transform with the above after implementing
    // matrices B and C
    double[][] transform = A;

    double x0 = 0, y0 = 0; // Center of original 2D ellipse.
    double a = 7; // Major axis
    double b = 4; // Minor axis
    double delT = 0.25; // t-increment for drawing

    d3.setDrawColor(Color.RED);
    for (double t = 0; t <= 2 * Math.PI + delT; t += delT) {
      double[] x = new double[4];
      x[0] = a * Math.cos(t);
      x[1] = b * Math.sin(t);
      x[2] = 0;
      x[3] = 1;
      double[] z = MatrixTool.matrixVectorMult(transform, x);
      d3.drawPoint(z[0], z[1], z[2]);
    }
  }
Exemplo n.º 14
0
  // For now the final output is unusable.  The associated quantization step
  // needs some tweaking.  If you get this part working, please let me know.
  public double[][] forwardDCTExtreme(float[][] input) {
    double[][] output = new double[N][N];
    double tmp0;
    double tmp1;
    double tmp2;
    double tmp3;
    double tmp4;
    double tmp5;
    double tmp6;
    double tmp7;
    double tmp10;
    double tmp11;
    double tmp12;
    double tmp13;
    double z1;
    double z2;
    double z3;
    double z4;
    double z5;
    double z11;
    double z13;
    int i;
    int j;
    int v;
    int u;
    int x;
    int y;

    for (v = 0; v < 8; v++) {
      for (u = 0; u < 8; u++) {
        for (x = 0; x < 8; x++) {
          for (y = 0; y < 8; y++) {
            output[v][u] +=
                (((double) input[x][y])
                    * Math.cos(((double) ((2 * x) + 1) * (double) u * Math.PI) / (double) 16)
                    * Math.cos(((double) ((2 * y) + 1) * (double) v * Math.PI) / (double) 16));
          }
        }

        output[v][u] *=
            ((double) (0.25)
                * ((u == 0) ? ((double) 1.0 / Math.sqrt(2)) : (double) 1.0)
                * ((v == 0) ? ((double) 1.0 / Math.sqrt(2)) : (double) 1.0));
      }
    }

    return output;
  }
Exemplo n.º 15
0
 /**
  * Fisher distribution
  *
  * @param f Fisher value
  * @param n1 N1 value
  * @param n2 N2 value
  * @return P-value associated
  */
 private static double FishF(double f, int n1, int n2) {
   double x = n2 / (n1 * f + n2);
   if ((n1 % 2) == 0) {
     return StatCom(1 - x, n2, n1 + n2 - 4, n2 - 2) * Math.pow(x, n2 / 2.0);
   }
   if ((n2 % 2) == 0) {
     return 1 - StatCom(x, n1, n1 + n2 - 4, n1 - 2) * Math.pow(1 - x, n1 / 2.0);
   }
   double th = Math.atan(Math.sqrt(n1 * f / (1.0 * n2)));
   double a = th / (Math.PI / 2.0);
   double sth = Math.sin(th);
   double cth = Math.cos(th);
   if (n2 > 1) {
     a = a + sth * cth * StatCom(cth * cth, 2, n2 - 3, -1) / (Math.PI / 2.0);
   }
   if (n1 == 1) {
     return 1 - a;
   }
   double c =
       4 * StatCom(sth * sth, n2 + 1, n1 + n2 - 4, n2 - 2) * sth * Math.pow(cth, n2) / Math.PI;
   if (n2 == 1) {
     return 1 - a + c / 2.0;
   }
   int k = 2;
   while (k <= (n2 - 1) / 2.0) {
     c = c * k / (k - .5);
     k = k + 1;
   }
   return 1 - a + c;
 }
Exemplo n.º 16
0
 public void mouseReleased(MouseEvent e) {
   left_mouse_pressed = false;
   double kvadrat = Math.sqrt(angleX * angleX + angleY * angleY);
   double tempx = angleX / kvadrat;
   double tempy = Math.sqrt(1 - tempx * tempx);
   if (angleY < 0) tempy = -tempy;
   Bullet b = new Bullet();
   boolean next = false;
   if (type_bullet1 == true && count_sphere > 0) {
     b = new Sphere();
     count_sphere--;
     next = true;
   }
   if (type_bullet2 == true && count_fireball > 0) {
     b = new FireBall();
     count_fireball--;
     next = true;
   }
   if (type_bullet3 == true && count_rocket > 0) {
     b = new Rocket();
     count_rocket--;
     next = true;
   }
   if (next == true) {
     b.bullet_x = player.getX() + 52 + 5 * Math.cos(angle); // + 50; //koef;
     b.bullet_y = player.getY() + 49 + 5 * Math.sin(angle); // player.getY() + 35; //25;
     b.current_direction_x = tempx;
     b.current_direction_y = tempy;
     bullet.addElement(b);
     allow_shoot = false;
   }
 }
Exemplo n.º 17
0
  /**
   * Rotate the polygon clockwise about a point by an arbritray angle.
   *
   * @param x X ordinate of point to rotate about
   * @param y Y ordinate of point to rotate about
   * @param angle Angle in radians
   */
  public void rotate(double x, double y, double angle) {
    double theta = -angle;

    for (Enumeration e = vertices(); e.hasMoreElements(); ) {
      Vector2D vertex = (Vector2D) e.nextElement();

      // translate to origin
      double tmpX = vertex.getX() - x;
      double tmpY = vertex.getY() - y;

      // rotate
      double sin = Math.sin(theta);
      double cos = Math.cos(theta);

      double newX = tmpX * cos - tmpY * sin;
      double newY = tmpX * sin + tmpY * cos;

      // translate back to old location
      newX += x;
      newY += y;

      // set teh point to be where we calculated it should be
      vertex.setXY(newX, newY);
    }

    flagModified();
  }
Exemplo n.º 18
0
 Point2D rightHinge(int index) {
   Turn turn = centerHinges[index];
   double angle = (turn.angle + turn.prevAngle) / 2 + Math.PI / 2;
   double x = turn.x + WIDTH / 2 * Math.sin(angle);
   double z = turn.z + WIDTH / 2 * Math.cos(angle);
   return new Point2D(x, z);
 }
Exemplo n.º 19
0
  /**
   * Draws an open star with a specified number of points.<br>
   * The center of this star is specified by centerX,centerY and its size is specified by radius
   * <br>
   * (As in the radius of the circle the star would fit inside). <br>
   * Precondition: points >= 2 <br>
   * Example: <br>
   * Expo.drawStar(g,300,200,100,8); <br>
   * Draws an open star with 8 points and a radius of 100 pixels whose center is located at the
   * coordinate (300,200).
   */
  public static void drawStar(Graphics g, int centerX, int centerY, int radius, int points) {
    int halfRadius = getHalfRadius(radius, points);
    int p = points;
    points *= 2;

    int xCoord[] = new int[points];
    int yCoord[] = new int[points];

    int currentRadius;

    for (int k = 0; k < points; k++) {
      if (k % 2 == 0) currentRadius = radius;
      else currentRadius = halfRadius;

      xCoord[k] = (int) Math.round(Math.cos(twoPI * k / points - halfPI) * currentRadius) + centerX;
      yCoord[k] = (int) Math.round(Math.sin(twoPI * k / points - halfPI) * currentRadius) + centerY;
    }

    int x = (p - 5) / 2 + 1;
    if (p >= 5 && p <= 51)
      switch (p % 4) {
        case 1:
          yCoord[x] = yCoord[x + 1] = yCoord[points - x - 1] = yCoord[points - x];
          break;
        case 2:
          yCoord[x] = yCoord[x + 1] = yCoord[points - x - 1] = yCoord[points - x];
          yCoord[x + 3] = yCoord[x + 4] = yCoord[points - x - 4] = yCoord[points - x - 3];
          break;
        case 3:
          yCoord[x + 2] = yCoord[x + 3] = yCoord[points - x - 3] = yCoord[points - x - 2];
      }
    g.drawPolygon(xCoord, yCoord, points);
  }
Exemplo n.º 20
0
  void act() {
    if (crashed) return;

    if (missionBuffer == 0) setMissions();

    playerZ += SPEED * Math.cos(turn);
    playerX += SPEED * Math.sin(turn);

    if (!region(1).contains(playerX, playerZ)) {
      for (int i = 0; i < NUM_TURNS - 1; i++) centerHinges[i] = centerHinges[i + 1];
      createTurn(NUM_TURNS - 1);

      if (!region(1).contains(playerX, playerZ)) crash();

      turnIndex++;
      if (missionBuffer > 0) missionBuffer--;
      if (barrierBuffer > 0) barrierBuffer--;
    }
    if (playerY + 100 >= centerHinges[3].barrierY
        && playerY + 100 <= centerHinges[3].barrierY + BARRIER_HEIGHT) {
      crash();
    }

    if (up && playerY > START_Y + 50) playerY--;
    if (down && playerY < START_Y + HEIGHT - 150) playerY++;
    if (left) turn -= .005;
    if (right) turn += .005;
  }
Exemplo n.º 21
0
  public BufferedImage filter(BufferedImage src, BufferedImage dst) {
    if (dst == null) dst = createCompatibleDestImage(src, null);

    int width = src.getWidth();
    int height = src.getHeight();
    int numScratches = (int) (density * width * height / 100);
    ArrayList<Line2D> lines = new ArrayList<Line2D>();
    {
      float l = length * width;
      Random random = new Random(seed);
      Graphics2D g = dst.createGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(new Color(color));
      g.setStroke(new BasicStroke(this.width));
      for (int i = 0; i < numScratches; i++) {
        float x = width * random.nextFloat();
        float y = height * random.nextFloat();
        float a = angle + ImageMath.TWO_PI * (angleVariation * (random.nextFloat() - 0.5f));
        float s = (float) Math.sin(a) * l;
        float c = (float) Math.cos(a) * l;
        float x1 = x - c;
        float y1 = y - s;
        float x2 = x + c;
        float y2 = y + s;
        g.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
        lines.add(new Line2D.Float(x1, y1, x2, y2));
      }
      g.dispose();
    }

    if (false) {
      //		int[] inPixels = getRGB( src, 0, 0, width, height, null );
      int[] inPixels = new int[width * height];
      int index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float sx = x, sy = y;
          for (int i = 0; i < numScratches; i++) {
            Line2D.Float l = (Line2D.Float) lines.get(i);
            float dot = (l.x2 - l.x1) * (sx - l.x1) + (l.y2 - l.y1) * (sy - l.y1);
            if (dot > 0) inPixels[index] |= (1 << i);
          }
          index++;
        }
      }

      Colormap colormap = new LinearColormap();
      index = 0;
      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          float f = (float) (inPixels[index] & 0x7fffffff) / 0x7fffffff;
          inPixels[index] = colormap.getColor(f);
          index++;
        }
      }
      setRGB(dst, 0, 0, width, height, inPixels);
    }
    return dst;
  }
Exemplo n.º 22
0
 public void update() {
   rad += increment;
   if (rad > (Math.PI * 2)) {
     rad = 0.0;
   }
   coords[0] = 0.8 * Math.cos(rad);
   coords[1] = 0.8 * Math.sin(rad);
 }
Exemplo n.º 23
0
  public static void main(String[] argv) {
    // Random seed for generation.
    UniformRandom.set_seed(System.currentTimeMillis());

    // Start with a random unit length vector: a random angle.
    double theta = UniformRandom.uniform(0, 2.0 * Math.PI);
    double[] x = new double[2];
    x[0] = Math.cos(theta);
    x[1] = Math.sin(theta);

    // Find perpendicular unit length vector by adding 90-deg
    double[] y = new double[2];
    y[0] = Math.cos(theta + Math.PI / 2);
    y[1] = Math.sin(theta + Math.PI / 2);

    // Test.
    double xDoty = MatrixTool.dotProduct(x, y);
    System.out.println("x dot y = " + xDoty);

    // Make the matrix with x and y as columns.
    double[][] A = new double[2][2];
    A[0][0] = x[0];
    A[1][0] = x[1];
    A[0][1] = y[0];
    A[1][1] = y[1];

    double delTheta = 0.1;
    double[] u = new double[2];
    Function F = new Function("alpha vs theta");
    for (theta = 0; theta <= 2 * Math.PI; theta += delTheta) {
      // Generate next vector along unit circle.
      u[0] = Math.cos(theta);
      u[1] = Math.sin(theta);
      // Apply A to u.
      double[] z = MatrixTool.matrixVectorMult(A, u);
      double alpha = Math.atan2(z[1], z[0]);
      // Get z's angle.
      alpha = fixAngle(alpha);
      // Add to data set.
      F.add(theta, alpha);
    }

    // Plot data set.
    F.show();
  }
Exemplo n.º 24
0
 /**
  * Prepare the light for rendering.
  *
  * @param width the output image width
  * @param height the output image height
  */
 public void prepare(int width, int height) {
   float lx = (float) (Math.cos(azimuth) * Math.cos(elevation));
   float ly = (float) (Math.sin(azimuth) * Math.cos(elevation));
   float lz = (float) Math.sin(elevation);
   direction = new Vector3f(lx, ly, lz);
   direction.normalize();
   if (type != DISTANT) {
     lx *= distance;
     ly *= distance;
     lz *= distance;
     lx += width * centreX;
     ly += height * centreY;
   }
   position = new Vector3f(lx, ly, lz);
   realColor.set(new Color(color));
   realColor.scale(intensity);
   cosConeAngle = (float) Math.cos(coneAngle);
 }
Exemplo n.º 25
0
 // Bharat's collision system
 public void bounce(Player b) {
   double trueAngle = Math.atan(b.getVel().getX() / b.getVel().getY());
   double incAngle = trueAngle + angle;
   double newAngle = incAngle + angle + Math.PI;
   Point p = new Point();
   p.x = (int) (b.VEL * Math.cos(newAngle));
   p.y = (int) (b.VEL * Math.sin(newAngle));
   b.setVel(p);
 }
Exemplo n.º 26
0
 /**
  * Specifies the angle of the texture.
  *
  * @param angle the angle of the texture.
  * @angle
  * @see #getAngle
  */
 public void setAngle(float angle) {
   this.angle = angle;
   float cos = (float) Math.cos(angle);
   float sin = (float) Math.sin(angle);
   m00 = cos;
   m01 = sin;
   m10 = -sin;
   m11 = cos;
 }
Exemplo n.º 27
0
 // Approx Great-circle distance.  Args in degrees, result in kilometers
 public static double gcdist(double lata, double longa, double latb, double longb) {
   double midlat, psi, dist;
   midlat = 0.5 * (lata + latb);
   psi =
       0.0174532925
           * Math.sqrt(
               Math.pow(lata - latb, 2)
                   + Math.pow((longa - longb) * Math.cos(0.0174532925 * midlat), 2));
   dist = 6372.640112 * psi;
   return dist;
 } // gcdist
Exemplo n.º 28
0
  @Override
  /** Draw the clock */
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    // Initialize clock parameters
    int clockRadius = (int) (Math.min(getWidth(), getHeight()) * 0.8 * 0.5);
    int xCenter = getWidth() / 2;
    int yCenter = getHeight() / 2;

    // Draw circle
    g.setColor(Color.black);
    g.drawOval(xCenter - clockRadius, yCenter - clockRadius, 2 * clockRadius, 2 * clockRadius);
    g.drawString("12", xCenter - 5, yCenter - clockRadius + 12);
    g.drawString("9", xCenter - clockRadius + 3, yCenter + 5);
    g.drawString("3", xCenter + clockRadius - 10, yCenter + 3);
    g.drawString("6", xCenter - 3, yCenter + clockRadius - 3);

    // Draw second hand
    int sLength = (int) (clockRadius * 0.8);
    int xSecond = (int) (xCenter + sLength * Math.sin(second * (2 * Math.PI / 60)));
    int ySecond = (int) (yCenter - sLength * Math.cos(second * (2 * Math.PI / 60)));
    g.setColor(Color.red);
    g.drawLine(xCenter, yCenter, xSecond, ySecond);

    // Draw minute hand
    int mLength = (int) (clockRadius * 0.65);
    int xMinute = (int) (xCenter + mLength * Math.sin(minute * (2 * Math.PI / 60)));
    int yMinute = (int) (yCenter - mLength * Math.cos(minute * (2 * Math.PI / 60)));
    g.setColor(Color.blue);
    g.drawLine(xCenter, yCenter, xMinute, yMinute);

    // Draw hour hand
    int hLength = (int) (clockRadius * 0.5);
    int xHour =
        (int) (xCenter + hLength * Math.sin((hour % 12 + minute / 60.0) * (2 * Math.PI / 12)));
    int yHour =
        (int) (yCenter - hLength * Math.cos((hour % 12 + minute / 60.0) * (2 * Math.PI / 12)));
    g.setColor(Color.green);
    g.drawLine(xCenter, yCenter, xHour, yHour);
  }
Exemplo n.º 29
0
  static double EucledianDistance(
      double pLat,
      double pLong, // 3D version
      double qLat,
      double qLong,
      double radius) {
    double phi1 = (90 - pLat) * Math.PI / 180;
    double theta1 = (360 - pLong) * Math.PI / 180;
    double x1 = radius * Math.sin(phi1) * Math.cos(theta1);
    double y1 = radius * Math.sin(phi1) * Math.sin(theta1);
    double z1 = radius * Math.cos(phi1);

    double phi2 = (90 - qLat) * Math.PI / 180;
    double theta2 = (360 - qLong) * Math.PI / 180;
    double x2 = radius * Math.sin(phi2) * Math.cos(theta2);
    double y2 = radius * Math.sin(phi2) * Math.sin(theta2);
    double z2 = radius * Math.cos(phi2);

    double dx = x1 - x2, dy = y1 - y2, dz = z1 - z2;
    return Math.sqrt(dx * dx + dy * dy + dz * dz);
  }
Exemplo n.º 30
0
 public void draw(GOut g) {
   long now = System.currentTimeMillis();
   for (int y = 0; y < gsz.y; y++) {
     for (int x = 0; x < gsz.x; x++) {
       Coord p = bgsz.mul(new Coord(x, y));
       g.image(bg, p);
       Pagina btn = layout[x][y];
       if (btn != null) {
         Tex btex = btn.img.tex();
         g.image(btex, p.add(1, 1));
         if (btn.meter > 0) {
           double m = btn.meter / 1000.0;
           if (btn.dtime > 0) m += (1 - m) * (double) (now - btn.gettime) / (double) btn.dtime;
           m = Utils.clip(m, 0, 1);
           g.chcolor(255, 255, 255, 128);
           g.fellipse(p.add(bgsz.div(2)), bgsz.div(2), 90, (int) (90 + (360 * m)));
           g.chcolor();
         }
         if (btn.newp != 0) {
           if (btn.fstart == 0) {
             btn.fstart = now;
           } else {
             double ph = ((now - btn.fstart) / 1000.0) - (((x + (y * gsz.x)) * 0.15) % 1.0);
             if (ph < 1.25) {
               g.chcolor(255, 255, 255, (int) (255 * ((Math.cos(ph * Math.PI * 2) * -0.5) + 0.5)));
               g.image(glowmask(btn), p.sub(4, 4));
               g.chcolor();
             } else {
               g.chcolor(255, 255, 255, 128);
               g.image(glowmask(btn), p.sub(4, 4));
               g.chcolor();
             }
           }
         }
         if (btn == pressed) {
           g.chcolor(new Color(0, 0, 0, 128));
           g.frect(p.add(1, 1), btex.sz());
           g.chcolor();
         }
       }
     }
   }
   super.draw(g);
   if (dragging != null) {
     final Tex dt = dragging.img.tex();
     ui.drawafter(
         new UI.AfterDraw() {
           public void draw(GOut g) {
             g.image(dt, ui.mc.add(dt.sz().div(2).inv()));
           }
         });
   }
 }