Example #1
0
 static { // data[] is a bitmap image of the ball of radius R
   data = new byte[R * 2 * R * 2];
   for (int Y = -R; Y < R; Y++) {
     int x0 = (int) (Math.sqrt(R * R - Y * Y) + 0.5);
     for (int X = -x0; X < x0; X++) {
       // sqrt(x^2 + y^2) gives distance from the spot light
       int x = X + hx, y = Y + hy;
       int r = (int) (Math.sqrt(x * x + y * y) + 0.5);
       // set the maximal intensity to the maximal distance
       // (in pixels) from the spot light
       if (r > maxr) maxr = r;
       data[(Y + R) * (R * 2) + (X + R)] = (r <= 0) ? 1 : (byte) r;
     }
   }
 }
Example #2
0
  /* -------------------------------------------------------------*/
  private void objectCollision(ArrayList movingObjects) {
    for (int i = 0; i < movingObjects.size(); i++) {
      // make sure not testing if collided with yourself :P
      if (((SpaceObject) movingObjects.get(i)).getObjCount() != objectNum) {
        SpaceObject object = (SpaceObject) movingObjects.get(i);

        // find distance vector between two objects
        int x = pos_x - object.getXPos();
        int y = pos_y - object.getYPos();

        double distance = Math.sqrt(x * x + y * y);

        // has it collided with the object?
        if (distance < (radius + object.getRadius())) {
          // has it collided with a BULLET (or MISSILE)?
          if (object.isBullet()) {
            // do nothing
          }
          // is it another SPACESHIP? (INSTANT DEATH)
          else if (object.isSpaceShip()) {
            // do nothing
          }
          // collided with anything else (e.g PLANET): (INSTANT DEATH)
          else {
            collision.play();
            kill(movingObjects); // object has died
          }
        }
      }
    } // end for loop
  }
Example #3
0
  /* -------------------------------------------------------------*/
  private void gravityEffect(ArrayList movingObjects) {
    // find effect of gravity on this objects from all other objects
    for (int i = 0; i < movingObjects.size(); i++) {
      // reset variables
      double add_vx = 0.0;
      double add_vy = 0.0;

      SpaceObject object = (SpaceObject) movingObjects.get(i);

      if (object.getObjCount() != objectNum
          && // ignore yourself (distance = 0!)
          !object.isBullet()
          && // ignore bullets
          !object.isSpaceShip()) // ignore spaceships
      {

        // find distance vector between planet and ball
        int x = pos_x - object.getXPos();
        int y = pos_y - object.getYPos();

        double distance = Math.sqrt(x * x + y * y);

        // find effect of planet on velocity
        double add_vec = (SpaceObject.G * k * object.getMass() * ballMass) / (distance * distance);

        add_vx = -(x / distance) * add_vec;
        add_vy = -(y / distance) * add_vec;

        // add objects speeds onto spaceship speed (clip speed if too large)
        x_speed += add_vx;
        y_speed += add_vy;
      }
    }
  }
Example #4
0
 public double bond_degree_of_association() {
   double dof;
   // used to calculate strength of bonds of this type
   if ((!clamp_bdoa) && (activation == 100.0)) dof = shrunk_link_length;
   else dof = intrinsic_link_length;
   dof = 100.0 - dof;
   dof = Math.sqrt(dof) * 11.0; // / usually *11.0- but lets see what happens
   if (dof > 100.0) dof = 100.0;
   return dof;
 }
 double calc_dist(Vec p2) {
   Vec p1 = this;
   return Math.sqrt((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y));
 }
Example #6
0
 public double getStd() {
   return Math.sqrt(getVar());
 }
Example #7
0
  /**
   * Calculate the range of the data and the magnitude of the vectors. This modifies
   * dxmin,dxmax,dymin,dymax and xmin,xmax,ymin,ymax
   */
  protected void range(int stride) {
    int i;
    double mag = 0.0;

    if (length > stride) {
      dxmax = data[0];
      dymax = data[1];
      dxmin = dxmax;
      dymin = dymax;

      mag = data[2] * data[2] + data[3] * data[3];
      vmean = Math.sqrt(mag);
      vmin = mag;
      vmax = mag;

    } else {
      dxmin = 0.0;
      dxmax = 0.0;
      dymin = 0.0;
      dymax = 0.0;

      vmean = 0.0;
      vmin = 0.0;
      vmax = 0.0;
    }

    for (i = stride; i < length; i += stride) {

      if (dxmax < data[i]) {
        dxmax = data[i];
      } else if (dxmin > data[i]) {
        dxmin = data[i];
      }

      if (dymax < data[i + 1]) {
        dymax = data[i + 1];
      } else if (dymin > data[i + 1]) {
        dymin = data[i + 1];
      }

      mag = data[i + 2] * data[i + 2] + data[i + 3] * data[i + 3];

      vmean += Math.sqrt(mag);
      if (vmin > mag) vmin = mag;
      if (vmax < mag) vmax = mag;
    }

    if (length > stride) {
      vmin = Math.sqrt(vmin);
      vmax = Math.sqrt(vmax);
      vmean = vmean / dataPoints();
    }

    if (xaxis == null) {
      xmin = dxmin;
      xmax = dxmax;
    }
    if (yaxis == null) {
      ymin = dymin;
      ymax = dymax;
    }
  }