Example #1
0
  private void spawnRandomers() {
    for (int i = 0; i < randomN; i++) {
      float x = (float) Math.random() * width;
      float y = (float) Math.random() * height;
      float r =
          (float)
              Math.sqrt(
                  Math.pow(((Player) players.get(0)).getX() - x, 2)
                      + Math.pow(((Player) players.get(0)).getY() - x, 2));

      while (r < distanceLimit) {
        x = (float) Math.random() * width;
        y = (float) Math.random() * height;
        r =
            (float)
                Math.sqrt(
                    Math.pow(((Player) players.get(0)).getX() - x, 2)
                        + Math.pow(((Player) players.get(0)).getY() - y, 2));
      }

      enemies.add(new EnemyTypes.Random(x, y, 0.5f, borders));
    }

    spawnRandomersB = false;
  }
Example #2
0
  public void EMpar(Database db, double prior) {
    int j, np;
    double x, y, tmp, tmpx, tmpy, tmpsx, tmpsy, tmpsxy;

    np = db.nPoints();
    tmpsx = tmpsy = tmpsxy = kmx = kmy = 0;
    for (j = 0; j < np; j++) {
      x = db.xVal(j);
      y = db.yVal(j);
      kmx += probs[j] * x;
      kmy += probs[j] * y;
      tmpsx += probs[j] * x * x;
      tmpsy += probs[j] * y * y;
      tmpsxy += probs[j] * x * y;
    }
    tmp = np * weight;
    kmx /= tmp;
    kmy /= tmp;
    ksx = Math.sqrt(tmpsx / tmp - kmx * kmx);
    ksy = Math.sqrt(tmpsy / tmp - kmy * kmy);
    ksxy = tmpsxy / tmp - kmx * kmy;
    if (ksx < mins) ksx = mins;
    if (ksy < mins) ksy = mins;
    weight = 0.9 * weight + 0.1 * prior;
  }
  private PPath redrawArrows(double... curve) {
    double[] sub = subdivide(curve, ARROW_LENGTH);

    double x1 = sub[0];
    double y1 = sub[1];
    double x4 = sub[6];
    double y4 = sub[7];

    Point2D e = makeDistanceFromOrigin(x1 - x4, y1 - y4, ARROW_LENGTH);
    x1 = x4 + e.getX();
    y1 = y4 + e.getY();

    // arrow tails
    double m = (y4 - y1) / (x4 - x1);
    double at_x1 = x1 + m * ARROW_WIDTH / Math.sqrt(m * m + 1);
    double at_y1 = y1 - ARROW_WIDTH / Math.sqrt(m * m + 1);
    double at_x2 = x1 - m * ARROW_WIDTH / Math.sqrt(m * m + 1);
    double at_y2 = y1 + ARROW_WIDTH / Math.sqrt(m * m + 1);
    a1.reset();
    a1.moveTo((float) at_x1, (float) at_y1);
    a1.lineTo((float) at_x2, (float) at_y2);
    a1.lineTo((float) x4, (float) y4);
    a1.lineTo((float) at_x1, (float) at_y1);

    return a1;
  }
Example #4
0
  private void renderPin(GL gl, Coordinates position, float[] color, float size) {
    float height = heightmap.getHeight(projection.getGeoCoordinates(position));
    gl.glPushMatrix();
    double[] model = new double[16];
    gl.glGetDoublev(GL_MODELVIEW_MATRIX, model, 0);
    double zoomH =
        0.1 / Math.sqrt((model[0] * model[0]) + (model[1] * model[1]) + (model[2] * model[2]));
    double zoomZ =
        0.1 / Math.sqrt((model[8] * model[8]) + (model[9] * model[9]) + (model[10] * model[10]));
    gl.glTranslatef(position.getLongitude(), position.getLatitude(), height);
    gl.glScaled(zoomH * size, zoomH * size, zoomZ * size);
    gl.glDisable(GL_TEXTURE_2D);

    gl.glRotatef(20, 0.3f, 1, 0);

    GLU glu = new GLU();
    GLUquadric quadric = glu.gluNewQuadric();
    // glu.gluQuadricNormals(quadric, GLU.GLU_FLAT);
    gl.glColor3f(0.5f, 0.5f, 0.5f);
    gl.glEnable(GL_LIGHTING);
    glu.gluCylinder(quadric, 0.03, 0.03, 0.6f, 5, 1);
    gl.glTranslatef(0, 0, 0.6f);

    gl.glColor3f(color[0], color[1], color[2]);
    gl.glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
    glu.gluSphere(quadric, 0.12, 8, 8);
    // glu.gluCylinder(quadric, 0.2, 0.1, 0.5, 8, 1);
    gl.glDisable(GL_LIGHTING);
    glu.gluDeleteQuadric(quadric);
    gl.glPopMatrix();
  }
Example #5
0
  public void mouseDragged(MouseEvent evt) {
    Graphics g = canvas.getGraphics();
    g.setColor(color);

    if (type == 0) {
      g.setXORMode(canvas.getBackground());
      g.drawRect(start.x, start.y, end.x - start.x, end.y - start.y);
      end = evt.getPoint();
      g.drawRect(start.x, start.y, end.x - start.x, end.y - start.y);
    } else if (type == 1) {
      int radius;

      g.setXORMode(canvas.getBackground());

      radius = (int) Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));

      g.drawOval(start.x - radius, start.y - radius, 2 * radius, 2 * radius);
      end = evt.getPoint();

      radius = (int) Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));

      g.drawOval(start.x - radius, start.y - radius, 2 * radius, 2 * radius);
    } else if (type == 2) {
      g.setXORMode(canvas.getBackground());
      g.drawOval(start.x, start.y, end.x - start.x, end.y - start.y);
      end = evt.getPoint();
      g.drawOval(start.x, start.y, end.x - start.x, end.y - start.y);
    }
  }
Example #6
0
 private void getintbright() {
   weights = new float[ncurves][xpts][ypts];
   for (int i = 0; i < ncurves; i++) {
     nmeas[i] = 0;
     for (int j = 0; j < xpts; j++) {
       for (int k = 0; k < ypts; k++) {
         nmeas[i] += (int) pch[i][j][k];
       }
     }
     double tempavg = 0.0;
     double tempavg2 = 0.0;
     double temp2avg = 0.0;
     double temp2avg2 = 0.0;
     double tempccavg = 0.0;
     for (int j = 0; j < xpts; j++) {
       for (int k = 0; k < ypts; k++) {
         double normed = (double) pch[i][j][k] / (double) nmeas[i];
         if (pch[i][j][k] > 0.0f) {
           weights[i][j][k] = (float) ((double) nmeas[i] / (normed * (1.0f - normed)));
         } else {
           weights[i][j][k] = 1.0f;
         }
         tempavg += normed * (double) j;
         tempavg2 += normed * (double) j * (double) j;
         temp2avg += normed * (double) k;
         temp2avg2 += normed * (double) k * (double) k;
         tempccavg += normed * (double) k * (double) j;
       }
     }
     tempccavg -= tempavg * temp2avg;
     brightcc[i] = tempccavg / Math.sqrt(tempavg * temp2avg);
     tempavg2 -= tempavg * tempavg;
     tempavg2 /= tempavg;
     bright1[i] = (tempavg2 - 1.0);
     temp2avg2 -= temp2avg * temp2avg;
     temp2avg2 /= temp2avg;
     bright2[i] = (temp2avg2 - 1.0);
     intensity1[i] = tempavg;
     intensity2[i] = temp2avg;
     if (psfflag == 0) {
       bright1[i] /= 0.3536;
       bright2[i] /= 0.3536;
       brightcc[i] /= 0.3536;
     } else {
       if (psfflag == 1) {
         bright1[i] /= 0.078;
         bright2[i] /= 0.078;
         brightcc[i] /= 0.078;
       } else {
         bright1[i] /= 0.5;
         bright2[i] /= 0.5;
         brightcc[i] /= 0.5;
       }
     }
     number1[i] = intensity1[i] / bright1[i];
     number2[i] = intensity2[i] / bright2[i];
     brightmincc[i] = (bright1[i] * beta) * Math.sqrt(intensity1[i] / intensity2[i]);
   }
 }
Example #7
0
 /**
  * Constructs OscillatorsMode with the given mode and number of particles.
  *
  * <p>The particle separation is one in this model.
  *
  * @param mode int
  * @param N int
  */
 OscillatorsMode(int mode, int N) {
   amplitude = Math.sqrt(2.0 / (N + 1));
   omega = 2 * Math.sqrt(OMEGA_SQUARED) * Math.abs(Math.sin(mode * Math.PI / N / 2));
   wavenumber = Math.PI * mode / (N + 1);
   functionDrawer = new FunctionDrawer(this);
   functionDrawer.initialize(0, N + 1, 300, false); // draws the initial displacement
   functionDrawer.color = Color.LIGHT_GRAY;
 }
Example #8
0
  static Rgb hisToRgb(double h, double i, double s) {
    double m1, m2, i1;

    m1 = s * Math.sin(h * Math.PI / 180);
    m2 = s * Math.cos(h * Math.PI / 180);
    i1 = i / Math.sqrt(3);

    Rgb rgb = new Rgb();

    rgb.r = m1 * 2 / Math.sqrt(6) + i1 / Math.sqrt(3);
    rgb.g = -m1 / Math.sqrt(6) + m2 / Math.sqrt(2) + i1 / Math.sqrt(3);
    rgb.b = -m1 / Math.sqrt(6) - m2 / Math.sqrt(2) + i1 / Math.sqrt(3);

    rgb.r = rgb.r / 2 + 0.5;
    rgb.g = rgb.g / 2 + 0.5;
    rgb.b = rgb.b / 2 + 0.5;
    if (rgb.r > 1) rgb.r = 1;
    if (rgb.r < 0) rgb.r = 0;
    if (rgb.g > 1) rgb.g = 1;
    if (rgb.g < 0) rgb.g = 0;
    if (rgb.b > 1) rgb.b = 1;
    if (rgb.b < 0) rgb.b = 0;

    return rgb;
  }
 public YIntervalSeries getYIntervalSeries(String rowname, long factor) {
   YIntervalSeries mydataset = new YIntervalSeries(rowname);
   double sdcount = 0;
   double total = 0;
   Vector<Double> totalvalues = new Vector<Double>();
   double avgtotal = 0;
   double minus = 0;
   double plus = 0;
   double zero = 0;
   for (Integer key : ysum.keySet()) {
     Double value = ysum.get(key) / (double) count.get(key);
     Double point = (double) xsum.get(key) / (double) count.get(key);
     Vector<Double> listofvalues = values.get(key);
     double sumofdiff = 0.0;
     for (Double onevalue : listofvalues) {
       sumofdiff += Math.pow(onevalue - value, 2);
       sdcount++;
       total += Math.pow(onevalue, 2);
       avgtotal += onevalue;
       totalvalues.add(onevalue);
       if (onevalue == 1) {
         plus++;
       }
       ;
       if (onevalue == -1) {
         minus++;
       }
       ;
       if (onevalue == 0) {
         zero++;
       }
       ;
     }
     double sd = Math.sqrt(sumofdiff / count.get(key));
     // mydataset.add(point/factor, value,value+sd,value-sd);
     // mydataset.add(point/factor, value,value,value);
     mydataset.add(
         point / factor,
         value,
         value + 1.96 * (sd / Math.sqrt(count.get(key))),
         value - 1.96 * (sd / Math.sqrt(count.get(key))));
   }
   double sdtotal = 0;
   double avgsd = total / sdcount;
   double test = 0;
   for (Double onevalue : totalvalues) {
     sdtotal += Math.pow(Math.pow(onevalue, 2) - (total / sdcount), 2);
     test += onevalue;
   }
   // System.out.println(rowname+" mean square: "+avgsd+"
   // +/-95%:"+1.96*Math.sqrt(sdtotal/sdcount)/Math.sqrt(sdcount));
   // System.out.println("total -1:"+minus+" total +1:"+plus+" zero: "+zero
   // +" total:"+sdcount);
   return mydataset;
 }
Example #10
0
 public static double getDistanceBetweenLatLons(
     double lat1, double lon1, double lat2, double lon2) {
   double dLat = lat2 - lat1;
   double dLon = lon2 - lon1;
   double a =
       Math.sin(Math.toRadians(dLat) / 2D) * Math.sin(Math.toRadians(dLat) / 2D)
           + Math.cos(Math.toRadians(lat1))
               * Math.cos(Math.toRadians(lat2))
               * Math.sin(Math.toRadians(dLon) / 2D)
               * Math.sin(Math.toRadians(dLon) / 2D);
   return 12742D * Math.atan2(Math.sqrt(a), Math.sqrt(1.0D - a));
 }
Example #11
0
  public void paint(Graphics g, Database db) {
    int j;
    double theta, u1x, u1y, u2x, u2y, r1, r2, tmp, varx, vary;

    if (Math.abs(ksxy) <= 1e-4) {
      if (ksx > ksy) {
        u1x = u2y = 1;
        u1y = u2x = 0;
        r1 = ksx;
        r2 = ksy;
      } else {
        u1x = u2y = 0;
        u1y = u2x = 1;
        r1 = ksy;
        r2 = ksx;
      }
    } else {
      varx = ksx * ksx;
      vary = ksy * ksy;
      // eigen value
      tmp = varx - vary;
      tmp = Math.sqrt(tmp * tmp + 4 * ksxy * ksxy);
      r1 = Math.sqrt((varx + vary + tmp) / 2);
      r2 = Math.sqrt((varx + vary - tmp) / 2);

      // eigen vectors
      u1x = r1 * r1 - vary;
      tmp = Math.sqrt(u1x * u1x + ksxy * ksxy);
      u1x /= tmp;
      u1y = ksxy / tmp;

      u2x = r2 * r2 - vary;
      tmp = Math.sqrt(u2x * u2x + ksxy * ksxy);
      u2x /= tmp;
      u2y = ksxy / tmp;
    }
    g.setColor(Color.red);
    g.drawString(weight + "", (int) kmx, (int) kmy);
    g.setColor(Color.blue);
    if (plotcircle) {
      for (j = 1; j < 4; j++) {
        drawCurvedOval(g, u1x, u1y, u2x, u2y, r1 * j, r2 * j);
      }
    } else {
      g.drawLine(
          (int) (kmx + 3 * r1 * u1x),
          (int) (kmy + 3 * r1 * u1y),
          (int) (kmx - 3 * r1 * u1x),
          (int) (kmy - 3 * r1 * u1y));
    }
  }
Example #12
0
 /* Creates a spline fitted polygon with one pixel segment lengths
 that can be retrieved using the getFloatPolygon() method. */
 public void fitSplineForStraightening() {
   fitSpline((int) getUncalibratedLength() * 2);
   if (splinePoints == 0) return;
   float[] xpoints = new float[splinePoints * 2];
   float[] ypoints = new float[splinePoints * 2];
   xpoints[0] = xSpline[0];
   ypoints[0] = ySpline[0];
   int n = 1, n2;
   double inc = 0.01;
   double distance = 0.0, distance2 = 0.0, dx = 0.0, dy = 0.0, xinc, yinc;
   double x, y, lastx, lasty, x1, y1, x2 = xSpline[0], y2 = ySpline[0];
   for (int i = 1; i < splinePoints; i++) {
     x1 = x2;
     y1 = y2;
     x = x1;
     y = y1;
     x2 = xSpline[i];
     y2 = ySpline[i];
     dx = x2 - x1;
     dy = y2 - y1;
     distance = Math.sqrt(dx * dx + dy * dy);
     xinc = dx * inc / distance;
     yinc = dy * inc / distance;
     lastx = xpoints[n - 1];
     lasty = ypoints[n - 1];
     // n2 = (int)(dx/xinc);
     n2 = (int) (distance / inc);
     if (splinePoints == 2) n2++;
     do {
       dx = x - lastx;
       dy = y - lasty;
       distance2 = Math.sqrt(dx * dx + dy * dy);
       // IJ.log(i+"   "+IJ.d2s(xinc,5)+"   "+IJ.d2s(yinc,5)+"   "+IJ.d2s(distance,2)+"
       // "+IJ.d2s(distance2,2)+"   "+IJ.d2s(x,2)+"   "+IJ.d2s(y,2)+"   "+IJ.d2s(lastx,2)+"
       // "+IJ.d2s(lasty,2)+"   "+n+"   "+n2);
       if (distance2 >= 1.0 - inc / 2.0 && n < xpoints.length - 1) {
         xpoints[n] = (float) x;
         ypoints[n] = (float) y;
         // IJ.log("--- "+IJ.d2s(x,2)+"   "+IJ.d2s(y,2)+"  "+n);
         n++;
         lastx = x;
         lasty = y;
       }
       x += xinc;
       y += yinc;
     } while (--n2 > 0);
   }
   xSpline = xpoints;
   ySpline = ypoints;
   splinePoints = n;
 }
Example #13
0
  /**
   * Sets one or more icons for the Display.
   *
   * <ul>
   *   <li>On Windows you should supply at least one 16x16 icon and one 32x32.
   *   <li>Linux (and similar platforms) expect one 32x32 icon.
   *   <li>Mac OS X should be supplied one 128x128 icon
   * </ul>
   *
   * The implementation will use the supplied ByteBuffers with image data in RGBA and perform any
   * conversions nescesarry for the specific platform.
   *
   * @param icons Array of icons in RGBA mode
   * @return number of icons used.
   */
  public int setIcon(ByteBuffer[] icons) {
    boolean done_small = false;
    boolean done_large = false;
    int used = 0;

    int small_icon_size = 16;
    int large_icon_size = 32;
    for (ByteBuffer icon : icons) {
      int size = icon.limit() / 4;

      if ((((int) Math.sqrt(size)) == small_icon_size) && (!done_small)) {
        long small_new_icon = createIcon(small_icon_size, small_icon_size, icon.asIntBuffer());
        sendMessage(hwnd, WM_SETICON, ICON_SMALL, small_new_icon);
        freeSmallIcon();
        small_icon = small_new_icon;
        used++;
        done_small = true;
      }
      if ((((int) Math.sqrt(size)) == large_icon_size) && (!done_large)) {
        long large_new_icon = createIcon(large_icon_size, large_icon_size, icon.asIntBuffer());
        sendMessage(hwnd, WM_SETICON, ICON_BIG, large_new_icon);
        freeLargeIcon();
        large_icon = large_new_icon;
        used++;
        done_large = true;

        // Problem: The taskbar icon won't update until Windows sends a WM_GETICON to our window
        // proc and we reply. But this method is usually called
        // on init and it might take a while before the next call to nUpdate (because of resources
        // being loaded, etc). So we wait for the next
        // WM_GETICON message (usually received about 100ms after WM_SETICON) to make sure the
        // taskbar icon has updated before we return to the user.
        // (We wouldn't need to do this if the event loop was running continuously on its own
        // thread.)
        iconsLoaded = false;

        // Track how long the wait takes and give up at 500ms, just in case.
        long time = System.nanoTime();
        long MAX_WAIT = 500L * 1000L * 1000L;
        while (true) {
          nUpdate();
          if (iconsLoaded || MAX_WAIT < System.nanoTime() - time) break;

          Thread.yield();
        }
      }
    }

    return used;
  }
Example #14
0
 public double getArrowRadius(Point p) {
   if ((x + defaultWidth / 2) == p.x) {
     return defaultHeight / 2;
   } else {
     double px = p.x - x - defaultWidth / 2;
     double py = p.y - y - defaultHeight / 2;
     double a = defaultWidth / 2;
     double b = defaultHeight / 2;
     double k = py / px;
     double xp = Math.sqrt(a * a * b * b / (b * b + k * k * a * a));
     double yp = k * xp;
     return Math.sqrt(xp * xp + yp * yp);
   }
 }
Example #15
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 #16
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;
  }
Example #17
0
  public PositionMark(float x, float y, Point2D.Float[] points) {
    super(x, y);
    int nPoints = points.length;
    Vector2f[] vectors = new Vector2f[nPoints];
    float[] xPts = new float[points.length];
    float[] yPts = new float[points.length];

    for (int i = 0; i < nPoints; i++) {
      xPts[i] = points[i].x;
      yPts[i] = points[i].y;
      vectors[i] = new Vector2f(xPts[i], yPts[i]);
    }

    shape = new Polygon2D(xPts, yPts, nPoints);
    boundingCircleRadius =
        (float)
            Math.sqrt(
                (shape.getBounds2D().getCenterX() - shape.getBounds2D().getMinX())
                        * (shape.getBounds2D().getCenterX() - shape.getBounds2D().getMinX())
                    + (shape.getBounds2D().getCenterY() - shape.getBounds2D().getMinY())
                        * (shape.getBounds2D().getCenterY() - shape.getBounds2D().getMinY()));
    body = new Body("FixedObstacle", new Polygon(vectors), 300f);
    body.setMoveable(false);
    body.setRotatable(false);
    body.setPosition(x, y);
    body.setRotation(0);
    setBaseDamping(4.5f);
    body.setDamping(baseDamping);
    body.setRotDamping(ROT_DAMPING_MUTIPLYING_CONST * baseDamping);
  }
Example #18
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;
      }
    }
  }
  public static double[] invertBilinear(Vec4 U, Vec4 X, Vec4 Y, Vec4 Z, Vec4 W) {
    Vec4 s1 = W.subtract3(X);
    Vec4 s2 = Z.subtract3(Y);
    Vec4 UminX = U.subtract3(X);
    Vec4 UminY = U.subtract3(Y);
    Vec4 normal = Z.subtract3(X).cross3(W.subtract3(Y));

    double A = s1.cross3(s2).dot3(normal);
    double B = s2.cross3(UminX).dot3(normal) - s1.cross3(UminY).dot3(normal);
    double C = UminX.cross3(UminY).dot3(normal);

    double descriminant = B * B - 4d * A * C;
    if (descriminant < 0) return null;
    descriminant = Math.sqrt(descriminant);

    double beta = B > 0 ? (-B - descriminant) / (2d * A) : 2d * C / (-B + descriminant);

    Vec4 Sbeta1 = Vec4.mix3(beta, X, W);
    Vec4 Sbeta2 = Vec4.mix3(beta, Y, Z);

    double alpha =
        U.subtract3(Sbeta1).dot3(Sbeta2.subtract3(Sbeta1)) / Sbeta2.subtract3(Sbeta1).dotSelf3();

    return new double[] {alpha, beta};
  }
Example #20
0
 // calculate the radius of a given ellipse with give angle
 private double getEllipseRadius(double a, double b, double theta) {
   double d =
       Math.pow(a, 2) * Math.pow(Math.cos(theta), 2)
           + Math.pow(b, 2) * Math.pow(Math.sin(theta), 2);
   double sd = Math.sqrt(d);
   return a * b / sd;
 }
Example #21
0
  public void mouseReleased(MouseEvent evt) {
    Graphics g = canvas.getGraphics();
    g.setColor(color);
    g.setPaintMode();
    end = evt.getPoint();

    if (type == 0) {
      g.drawRect(start.x, start.y, end.x - start.x, end.y - start.y);

      if (filled.getState() == true) g.fillRect(start.x, start.y, end.x - start.x, end.y - start.y);

      status.setText("2. Ecke des Rechtecks festgelegt");
    } else if (type == 1) {
      int radius;

      radius = (int) Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));

      g.drawOval(start.x - radius, start.y - radius, 2 * radius, 2 * radius);

      if (filled.getState() == true)
        g.fillOval(start.x - radius, start.y - radius, 2 * radius, 2 * radius);

      status.setText("Radius des Kreises festgelegt");
    } else if (type == 2) {
      g.drawOval(start.x, start.y, end.x - start.x, end.y - start.y);

      if (filled.getState() == true) g.fillOval(start.x, start.y, end.x - start.x, end.y - start.y);

      status.setText("Radius der Ellipse festgelegt");
    }
  }
Example #22
0
 public double distanciaEuclidiana(int x1, int x2, int y1, int y2) {
   double a, b, c;
   a = Math.pow(x2 - x1, 2);
   b = Math.pow(y2 - y1, 2);
   c = Math.sqrt(a + b);
   return (c);
 }
Example #23
0
  /**
   * Paints the graphic component
   *
   * @param g Graphic component
   */
  public void paint(Graphics g) {
    if (environment != null) {
      Sudoku env = (Sudoku) environment;
      Board board = env.getBoard();

      int n = SudokuLanguage.DIGITS;
      int sqrt_n = (int) (Math.sqrt(n) + 0.1);

      g.setColor(Color.lightGray);
      Font font = g.getFont();
      g.setFont(new Font(font.getName(), font.getStyle(), 20));
      for (int i = 0; i < n; i++) {
        int ci = getCanvasValue(i);
        if (i % sqrt_n == 0) {
          g.drawLine(ci, DRAW_AREA_SIZE + MARGIN, ci, MARGIN);
          g.drawLine(DRAW_AREA_SIZE + MARGIN, ci, MARGIN, ci);
        }

        for (int j = 0; j < n; j++) {
          int cj = getCanvasValue(j);
          int value = board.get(i, j);
          if (value > 0) {
            g.setColor(Color.black);
            g.drawString("" + value, cj + CELL_SIZE / 5, ci + CELL_SIZE);
            g.setColor(Color.lightGray);
          }
        }
      }
      g.drawLine(DRAW_AREA_SIZE + MARGIN, DRAW_AREA_SIZE + MARGIN, DRAW_AREA_SIZE + MARGIN, MARGIN);
      g.drawLine(DRAW_AREA_SIZE + MARGIN, DRAW_AREA_SIZE + MARGIN, MARGIN, DRAW_AREA_SIZE + MARGIN);
    }
  }
Example #24
0
 /*
  *	@param	a			Quell-Wellenform
  *	@param	env			Ziel-RMS
  *	@param	average		Laenge der Samples in a, aus denen jeweils ein RMS berechnet wird
  *						(RMS = sqrt( energy/average ))
  *	@param	length		Zahl der generierten RMS (in env)
  *	@param	lastEnergy	Rueckgabewert aus dem letzten Aufruf dieser Routine
  *						(richtige Initialisierung siehe process(): summe der quadrate der prebuffered samples)
  *	@return				neuer Energiewert, der beim naechsten Aufruf als lastEnergy uebergeben werden muss
  */
 protected double calcEnv(float[] a, float[] env, int average, int length, double lastEnergy) {
   for (int i = 0, j = average; i < length; i++, j++) { //   zu alten leistungswert "vergessen" und
     lastEnergy = lastEnergy - a[i] * a[i] + a[j] * a[j]; // neuen addieren
     env[i] = (float) Math.sqrt(lastEnergy / average);
   }
   return lastEnergy;
 }
 /** Computes and returns the distance between two entities */
 public int getDistance(WorldEntity e) {
   Point wp = e.getPosition();
   Point mep = getPosition();
   int dx = wp.x - mep.x;
   int dy = wp.y - mep.y;
   return ((int) Math.round(Math.sqrt(dx * dx + dy * dy)));
 }
Example #26
0
 /**
  * Returns the perimeter length of ROIs created using the wand tool and the particle analyzer. The
  * algorithm counts edge pixels as 1 and corner pixels as sqrt(2). It does this by calculating the
  * total length of the ROI boundary and subtracting 2-sqrt(2) for each non-adjacent corner. For
  * example, a 1x1 pixel ROI has a boundary length of 4 and 2 non-adjacent edges so the perimeter
  * is 4-2*(2-sqrt(2)). A 2x2 pixel ROI has a boundary length of 8 and 4 non-adjacent edges so the
  * perimeter is 8-4*(2-sqrt(2)).
  */
 double getTracedPerimeter() {
   int sumdx = 0;
   int sumdy = 0;
   int nCorners = 0;
   int dx1 = xp[0] - xp[nPoints - 1];
   int dy1 = yp[0] - yp[nPoints - 1];
   int side1 = Math.abs(dx1) + Math.abs(dy1); // one of these is 0
   boolean corner = false;
   int nexti, dx2, dy2, side2;
   for (int i = 0; i < nPoints; i++) {
     nexti = i + 1;
     if (nexti == nPoints) nexti = 0;
     dx2 = xp[nexti] - xp[i];
     dy2 = yp[nexti] - yp[i];
     sumdx += Math.abs(dx1);
     sumdy += Math.abs(dy1);
     side2 = Math.abs(dx2) + Math.abs(dy2);
     if (side1 > 1 || !corner) {
       corner = true;
       nCorners++;
     } else corner = false;
     dx1 = dx2;
     dy1 = dy2;
     side1 = side2;
   }
   double w = 1.0, h = 1.0;
   if (imp != null) {
     Calibration cal = imp.getCalibration();
     w = cal.pixelWidth;
     h = cal.pixelHeight;
   }
   return sumdx * w + sumdy * h - (nCorners * ((w + h) - Math.sqrt(w * w + h * h)));
 }
    private void generateLookupTables() {
      mySat = new float[myWidth * myHeight];
      myHues = new float[myWidth * myHeight];
      myAlphas = new int[myWidth * myHeight];
      float radius = getRadius();

      // blend is used to create a linear alpha gradient of two extra pixels
      float blend = (radius + 2f) / radius - 1f;

      // Center of the color wheel circle
      int cx = myWidth / 2;
      int cy = myHeight / 2;

      for (int x = 0; x < myWidth; x++) {
        int kx = x - cx; // Kartesian coordinates of x
        int squarekx = kx * kx; // Square of kartesian x

        for (int y = 0; y < myHeight; y++) {
          int ky = cy - y; // Kartesian coordinates of y

          int index = x + y * myWidth;
          mySat[index] = (float) Math.sqrt(squarekx + ky * ky) / radius;
          if (mySat[index] <= 1f) {
            myAlphas[index] = 0xff000000;
          } else {
            myAlphas[index] =
                (int) ((blend - Math.min(blend, mySat[index] - 1f)) * 255 / blend) << 24;
            mySat[index] = 1f;
          }
          if (myAlphas[index] != 0) {
            myHues[index] = (float) (Math.atan2(ky, kx) / Math.PI / 2d);
          }
        }
      }
    }
 @Override
 public Dimension getOptimalPositionedSize(
     Rectangle[] componentAreas, Constraint[][] constraints) {
   if (componentAreas.length == 0) return new Dimension(0, 0);
   int componentsPerColumn, componentsPerRow;
   if (columns == 0) {
     if (rows == 0) {
       double square = Math.sqrt(componentAreas.length);
       componentsPerColumn = (int) square;
       componentsPerRow = (int) square;
       if (square - (int) square > 0) componentsPerColumn++;
     } else {
       componentsPerRow = componentAreas.length / rows;
       if (componentAreas.length % rows > 0) componentsPerRow++;
       componentsPerColumn = rows;
     }
   } else if (rows == 0) {
     componentsPerColumn = componentAreas.length / columns;
     if (componentAreas.length % columns > 0) componentsPerColumn++;
     componentsPerRow = columns;
   } else {
     componentsPerRow = columns;
     componentsPerColumn = rows;
   }
   int maxElementWidth = 0, maxElementHeight = 0;
   for (Rectangle component : componentAreas) {
     maxElementWidth = Math.max(maxElementWidth, component.width);
     maxElementHeight = Math.max(maxElementHeight, component.height);
   }
   return new Dimension(
       maxElementWidth * componentsPerRow, maxElementHeight * componentsPerColumn);
 }
  // calculate the coordinates of the startpoint (endpoint) if parameter is
  // true (false) of the arrow when drawing this link
  private Point calcCoord(boolean startpoint) {
    if (!startpoint && (end == null)) return openEnd;

    int deltaX;
    int deltaY;

    if (end == null) {
      deltaX = start.getX() - openEnd.x;
      deltaY = start.getY() - openEnd.y;
    } else {
      deltaX = start.getX() - end.getX();
      deltaY = start.getY() - end.getY();
    }

    double dist = Math.sqrt(deltaX * deltaX + deltaY * deltaY);

    double prop = (Client.RADIUS) / dist;

    int offsetX = (int) Math.round(deltaX * prop);
    int offsetY = (int) Math.round(deltaY * prop);

    if (startpoint) {
      return new Point(start.getX() - offsetX, start.getY() - offsetY);
    } else return new Point(end.getX() + offsetX, end.getY() + offsetY);
  }
Example #30
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
  }