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); } }
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; }
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]); } }
protected void plotScatterDiagram() { // plot sample as one dimensional scatter plot and Gaussian double xmax = 5.; double xmin = -5.; DatanGraphics.openWorkstation(getClass().getName(), "E3Min_1.ps"); DatanGraphics.setFormat(0., 0.); DatanGraphics.setWindowInComputingCoordinates(xmin, xmax, 0., .5); DatanGraphics.setViewportInWorldCoordinates(-.15, .9, .16, .86); DatanGraphics.setWindowInWorldCoordinates(-.414, 1., 0., 1.); DatanGraphics.setBigClippingWindow(); DatanGraphics.chooseColor(2); DatanGraphics.drawFrame(); DatanGraphics.drawScaleX("y"); DatanGraphics.drawScaleY("f(y)"); DatanGraphics.drawBoundary(); double xpl[] = new double[2]; double ypl[] = new double[2]; // plot scatter diagram DatanGraphics.chooseColor(1); for (int i = 0; i < y.length; i++) { xpl[0] = y[i]; xpl[1] = y[i]; ypl[0] = 0.; ypl[0] = .1; DatanGraphics.drawPolyline(xpl, ypl); } // draw Gaussian corresponding to solution int npl = 100; xpl = new double[npl]; ypl = new double[npl]; double fact = 1. / (Math.sqrt(2. * Math.PI) * x.getElement(1)); double dpl = (xmax - xmin) / (double) (npl - 1); for (int i = 0; i < npl; i++) { xpl[i] = xmin + (double) i * dpl; ypl[i] = fact * Math.exp(-.5 * Math.pow((xpl[i] - x.getElement(0)) / x.getElement(1), 2.)); } DatanGraphics.chooseColor(5); DatanGraphics.drawPolyline(xpl, ypl); // draw caption String sn = "N = " + nny; numForm.setMaximumFractionDigits(3); numForm.setMinimumFractionDigits(3); String sx1 = ", x_1# = " + numForm.format(x.getElement(0)); String sx2 = ", x_2# = " + numForm.format(x.getElement(1)); String sdx1 = ", &D@x_1# = " + numForm.format(Math.sqrt(cx.getElement(0, 0))); String sdx2 = ", &D@x_2# = " + numForm.format(Math.sqrt(cx.getElement(1, 1))); caption = sn + sx1 + sx2 + sdx1 + sdx2; DatanGraphics.setBigClippingWindow(); DatanGraphics.chooseColor(2); DatanGraphics.drawCaption(1., caption); DatanGraphics.closeWorkstation(); }
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; } } }
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); }
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); } } } }
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"); } }
/** find minimum distance from ray to barb tail */ public synchronized float checkClose(double[] origin, double[] direction) { if (barbValues == null) return Float.MAX_VALUE; float o_x = (float) origin[0]; float o_y = (float) origin[1]; float o_z = (float) origin[2]; float d_x = (float) direction[0]; float d_y = (float) direction[1]; float d_z = (float) direction[2]; /* System.out.println("origin = " + o_x + " " + o_y + " " + o_z); System.out.println("direction = " + d_x + " " + d_y + " " + d_z); */ float x = barbValues[2] - o_x; float y = barbValues[3] - o_y; float z = 0.0f - o_z; float dot = x * d_x + y * d_y + z * d_z; x = x - dot * d_x; y = y - dot * d_y; z = z - dot * d_z; offsetx = x; offsety = y; offsetz = z; return (float) Math.sqrt(x * x + y * y + z * z); // distance }
/* * @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; }
private void connectRightChild(Graphics g, int x1, int y1, int x2, int y2) { double r = Math.sqrt(virticalGap * virticalGap + (x2 - x1) * (x2 - x1)); int x11 = (int) (x1 - radius * (x1 - x2) / r); int y11 = (int) (y1 - radius * virticalGap / r); int x21 = (int) (x2 + radius * (x1 - x2) / r); int y21 = (int) (y2 + radius * virticalGap / r); g.drawLine(x11, y11, x21, y21); }
private void callObjectAtLocation(int x, int y) { for (Hex o : _hexes) { if (Math.sqrt((o.getX() - x) * (o.getX() - x) + (o.getY() - y) * (o.getY() - y)) < o.getRadius()) { o.clicked(x, y); return; } } }
@Override public void mousePressed(MouseEvent e) { Point p = e.getPoint(); double tamanho; if (!normalizerFinished) { if (!drawing) { pathNormalizer = new GeneralPath(); pathNormalizer.moveTo(p.x, p.y); previous = new Point(p.x, p.y); drawing = true; } else { // Codigo para medir em duas dimensoes if (normalizerCounter == 0) { // Linha X primeiro pathNormalizer.lineTo(p.x, previous.y); pixX = p.x < previous.x ? (previous.x - p.x) : (p.x - previous.x); normalizerCounter++; } else if (normalizerCounter == 1) { pathNormalizer.moveTo(previous.x, previous.y); pathNormalizer.lineTo(previous.x, p.y); pixY = p.y < previous.y ? (previous.y - p.y) : (p.y - previous.y); normalizerCounter++; } else { drawing = false; normalizerFinished = true; pathNormalizer.reset(); pixelToCentimetersConfig(); } } } else { if (!drawing) { path = new GeneralPath(); path.moveTo(p.x, p.y); previous = new Point(p.x, p.y); drawing = true; } else { if (!newLine) { path.lineTo(p.x, p.y); tamanho = Math.sqrt( (p.x - previous.x) * (p.x - previous.x) + (p.y - previous.y) * (p.y - previous.y)); newLine = true; // Adicionando nova linha lineList.add(new MyLine(previous, p)); } else { path.moveTo(p.x, p.y); previous = new Point(p.x, p.y); newLine = false; } } } repaint(); }
/** * set configuration of the panels according to the puzzle state * * @param nPuzzle gives the size of the puzzle, e.g. a 15 puzzle, possible values are 3, 8, 15 * @param panelType */ public void setConfiguration(final int nPuzzle, final PanelType panelType) { rows = (int) Math.sqrt(nPuzzle + 1); cols = rows; this.panelType = panelType; puzzleState = getPuzzle(); biggerFont = new Font("SansSerif", Font.BOLD, CELL_SIZE / 2); setPreferredSize(new Dimension(CELL_SIZE * cols, CELL_SIZE * rows)); setBackground(Color.black); }
public void postProcess() { double stdDev; double n = num; for (int i = 0; i < len; i++) { if (num > 1) { stdDev = (n * sum2[i] - sum[i] * sum[i]) / n; if (stdDev > 0.0) result[i] = (float) Math.sqrt(stdDev / (n - 1.0)); else result[i] = 0f; } else result[i] = 0f; } }
public void squareRoot() { if (secondNum == 0.0) { display.setText("ERROR"); firstNum = 0.0; secondNum = 0.0; operators = true; doClear = true; } else { secondNum = Math.sqrt(secondNum); display.setText(String.valueOf(secondNum)); } }
public Line(int x1, int y1, int x2, int y2) { t1 = new RSTile(x1, y1); t2 = new RSTile(x2, y2); x = x1; y = y1; this.x2 = x2; this.y2 = y2; xdist = x2 - x1; ydist = y2 - y1; centerX = x + (int) (0.5 * xdist); centerY = y + (int) (0.5 * ydist); dist = Math.sqrt(xdist * xdist + ydist * ydist); }
/** * Get the curve length; assumes curve is float[2][len] and seg_length is float[len-1] * * @param curve the curve * @param seg_length the segment lengths * @return the length of the curve */ public static float curveLength(float[][] curve, float[] seg_length) { int len = curve[0].length; float curve_length = 0.0f; for (int i = 0; i < len - 1; i++) { seg_length[i] = (float) Math.sqrt( ((curve[0][i + 1] - curve[0][i]) * (curve[0][i + 1] - curve[0][i])) + ((curve[1][i + 1] - curve[1][i]) * (curve[1][i + 1] - curve[1][i]))); curve_length += seg_length[i]; } return curve_length; }
public void mousePressed(MouseEvent e) { requestFocus(); Point p = e.getPoint(); int size = Math.min( MAX_SIZE, Math.min( getWidth() - imagePadding.left - imagePadding.right, getHeight() - imagePadding.top - imagePadding.bottom)); p.translate(-(getWidth() / 2 - size / 2), -(getHeight() / 2 - size / 2)); if (mode == ColorPicker.BRI || mode == ColorPicker.SAT) { // the two circular views: double radius = ((double) size) / 2.0; double x = p.getX() - size / 2.0; double y = p.getY() - size / 2.0; double r = Math.sqrt(x * x + y * y) / radius; double theta = Math.atan2(y, x) / (Math.PI * 2.0); if (r > 1) r = 1; if (mode == ColorPicker.BRI) { setHSB((float) (theta + .25f), (float) (r), bri); } else { setHSB((float) (theta + .25f), sat, (float) (r)); } } else if (mode == ColorPicker.HUE) { float s = ((float) p.x) / ((float) size); float b = ((float) p.y) / ((float) size); if (s < 0) s = 0; if (s > 1) s = 1; if (b < 0) b = 0; if (b > 1) b = 1; setHSB(hue, s, b); } else { int x2 = p.x * 255 / size; int y2 = p.y * 255 / size; if (x2 < 0) x2 = 0; if (x2 > 255) x2 = 255; if (y2 < 0) y2 = 0; if (y2 > 255) y2 = 255; if (mode == ColorPicker.RED) { setRGB(red, x2, y2); } else if (mode == ColorPicker.GREEN) { setRGB(x2, green, y2); } else { setRGB(x2, y2, blue); } } }
public String calculateInCentimeters() { String result; result = ""; double distX, distY, dist; pixelToCentimetersConfig(); for (MyLine m : lineList) { distX = (m.getP2().getX() - m.getP1().getX()) / propX; distY = (m.getP1().getY() - m.getP2().getY()) / propY; dist = Math.sqrt(distX * distX + distY * distY); result += String.format("%.2f", dist) + "\n"; } return result; }
/** Inform all registered MeasureToolListeners of a new distance. */ private void reportDistance(boolean finalDistance) { if (dragStartPos == null || dragCurrentPos == null) return; final double dx = dragCurrentPos.x - dragStartPos.x; final double dy = dragCurrentPos.y - dragStartPos.y; final double d = Math.sqrt(dx * dx + dy * dy); final double angle = Math.atan2(dy, dx); Iterator iterator = this.listeners.iterator(); while (iterator.hasNext()) { MeasureToolListener listener = (MeasureToolListener) iterator.next(); if (finalDistance) listener.newDistance(d, angle, this.mapComponent); else listener.distanceChanged(d, angle, this.mapComponent); } }
private Picture initialImage() { pic2 = new Picture(500, 600); pic1 = new Picture(500, 600); for (int x = 0; x < pic2.width(); x++) for (int y = 0; y < pic2.height(); y++) { double dist = 1.0 - Math.sqrt((x - 300) * (x - 300) + (y - 200) * (y - 200)) / 500; int red = (int) (dist < 0.5 ? 0 : Math.min(Math.pow(dist, 0.4) + Math.pow(dist - 0.5, 0.1), 1.0) * 255); int green = (int) (dist * 255); int blue = 0; pic2.set(x, y, new Color(red, green, blue)); } return pic2; }
Board() { addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { exit(); } }); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setSize(screenSize); setLocation(0, 0); r3 = Math.sqrt(3); Button ng, eg, ab; ng = new Button("New Game"); eg = new Button("Exit Game"); ab = new Button("About"); gold = new ImageIcon("./coin2.jpg").getImage(); silver = new ImageIcon("./coin1.jpg").getImage(); Panel pan = new Panel(); pan.setLayout(new FlowLayout()); pan.add(ng); pan.add(eg); pan.add(ab); setLayout(new BorderLayout()); add(pan, BorderLayout.NORTH); newGame(); ng.addActionListener(this); eg.addActionListener(this); ab.addActionListener(this); addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { int mx = e.getX(), my = e.getY(); place(mx, my); } }); }
private class MinLogLikeGauss extends DatanUserFunction { double[] y; double sqrt2pi = Math.sqrt(2. * Math.PI); double big = 1.E10, small = 1.E-10; double f; MinLogLikeGauss(double[] y) { this.y = y; } public double getValue(DatanVector x) { double result; double a = sqrt2pi * x.getElement(1); if (a < small) f = big; else f = Math.log(a); result = (double) y.length * f; for (int i = 0; i < y.length; i++) { f = Math.pow((y[i] - x.getElement(0)), 2.) / (2. * x.getElement(1) * x.getElement(1)); result += f; } return result; } }
/*------------------------------------------------------------------*/ void getSplineInterpolationCoefficients(double[] c, double tolerance) { double z[] = {Math.sqrt(3.0) - 2.0}; double lambda = 1.0; if (c.length == 1) { return; } for (int k = 0; (k < z.length); k++) { lambda = lambda * (1.0 - z[k]) * (1.0 - 1.0 / z[k]); } for (int n = 0; (n < c.length); n++) { c[n] = c[n] * lambda; } for (int k = 0; (k < z.length); k++) { c[0] = getInitialCausalCoefficientMirrorOnBounds(c, z[k], tolerance); for (int n = 1; (n < c.length); n++) { c[n] = c[n] + z[k] * c[n - 1]; } c[c.length - 1] = getInitialAntiCausalCoefficientMirrorOnBounds(c, z[k], tolerance); for (int n = c.length - 2; (0 <= n); n--) { c[n] = z[k] * (c[n + 1] - c[n]); } } } /* end getSplineInterpolationCoefficients */
public void move() { objtimer++; // move if (xmot.random && objtimer % (int) (35 * xmot.randomchg) == 0) { xspeed = xmot.speed * random(-1, 1, 2); } if (ymot.random && objtimer % (int) (35 * ymot.randomchg) == 0) { yspeed = ymot.speed * random(-1, 1, 2); } if (player != null) { double playerdist = Math.sqrt((player.x - x) * (player.x - x) + (player.y - y) * (player.y - y)) * 100.0 / (pfWidth()); if (xmot.toplayer && playerdist > xmot.toplayermin && playerdist < xmot.toplayermax) { xspeed = 0; x += xmot.speed * (player.x > x ? 1 : -1); } else if (xmot.frplayer && playerdist > xmot.frplayermin && playerdist < xmot.frplayermax) { xspeed = 0; x += xmot.speed * (player.x < x ? 1 : -1); } if (ymot.toplayer && playerdist > ymot.toplayermin && playerdist < ymot.toplayermax) { yspeed = 0; y += ymot.speed * (player.y > y ? 1 : -1); } else if (ymot.frplayer && playerdist > ymot.frplayermin && playerdist < ymot.frplayermax) { yspeed = 0; y += ymot.speed * (player.y < y ? 1 : -1); } } // react to background int bounces = 0; if (bouncesides.equals("any")) { bounces |= 15; } else if (bouncesides.equals("top")) { bounces |= 1; } else if (bouncesides.equals("bottom")) { bounces |= 2; } else if (bouncesides.equals("topbottom")) { bounces |= 3; } else if (bouncesides.equals("left")) { bounces |= 4; } else if (bouncesides.equals("right")) { bounces |= 8; } else if (bouncesides.equals("leftright")) { bounces |= 12; } if ((bounces & 1) != 0 && y < 0) { y = 0; if (yspeed < 0) yspeed = -yspeed; } if ((bounces & 2) != 0 && y > pfHeight() - 16) { y = pfHeight() - 16; if (yspeed > 0) yspeed = -yspeed; } if ((bounces & 4) != 0 && x < 0) { x = 0; if (xspeed < 0) xspeed = -xspeed; } if ((bounces & 8) != 0 && x > pfWidth() - 16) { x = pfWidth() - 16; if (xspeed > 0) xspeed = -xspeed; } // shoot if (shoot && shootfreq > 0.0 && objtimer % (int) (shootfreq * 35) == 0) { if (shootdir.equals("left")) { new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, -shootspeed, 0); } else if (shootdir.equals("right")) { new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, shootspeed, 0); } else if (shootdir.equals("up")) { new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, 0, -shootspeed); } else if (shootdir.equals("down")) { new AgentBullet(x, y, bullettype, sprite, diebgtype | blockbgtype, 0, shootspeed); } else if (shootdir.equals("player") && player != null) { double angle = Math.atan2(player.x - x, player.y - y); new AgentBullet( x, y, bullettype, sprite, diebgtype | blockbgtype, shootspeed * Math.sin(angle), shootspeed * Math.cos(angle)); } } }
protected void process() { int i, j, len, ch, chunkLength; long progOff, progLen; float f1; // io AudioFile inF = null; AudioFile outF = null; AudioFileDescr inStream; AudioFileDescr outStream; FloatFile[] floatF = null; File tempFile[] = null; // buffers float[][] inBuf, outBuf; float[] win; float[] convBuf1, convBuf2; float[] tempFlt; int inChanNum, inLength, inputStep, outputStep, winSize; int transLen, skip, inputLen, outputLen, fltLen; int framesRead, framesWritten; float warp, a1, b0, b1, x0, x1, y0, y1, b0init; Param ampRef = new Param(1.0, Param.ABS_AMP); // transform-Referenz Param peakGain; float gain = 1.0f; // gain abs amp float maxAmp = 0.0f; PathField ggOutput; topLevel: try { // ---- open input, output ---- // input inF = AudioFile.openAsRead(new File(pr.text[PR_INPUTFILE])); inStream = inF.getDescr(); inChanNum = inStream.channels; inLength = (int) inStream.length; // this helps to prevent errors from empty files! if ((inLength * inChanNum) < 1) throw new EOFException(ERR_EMPTY); // .... check running .... if (!threadRunning) break topLevel; // output ggOutput = (PathField) gui.getItemObj(GG_OUTPUTFILE); if (ggOutput == null) throw new IOException(ERR_MISSINGPROP); outStream = new AudioFileDescr(inStream); ggOutput.fillStream(outStream); outF = AudioFile.openAsWrite(outStream); // .... check running .... if (!threadRunning) break topLevel; // ---- parameter inits ---- warp = Math.max(-0.98f, Math.min(0.98f, (float) (pr.para[PR_WARP].val / 100))); // DAFx2000 'b' f1 = (1.0f - warp) / (1.0f + warp); // DAFx2000 (25) winSize = 32 << pr.intg[PR_FRAMESIZE]; // DAFx2000 'N' j = winSize >> 1; transLen = (int) (f1 * winSize + 0.5f); // DAFx2000 'P' (26) i = pr.intg[PR_OVERLAP] + 1; while (((float) transLen / (float) i) > j) i++; inputStep = (int) (((float) transLen / (float) i) + 0.5f); // DAFx2000 'L' fltLen = Math.max(winSize, transLen); // System.out.println( "inputStep "+inputStep+"; winSize "+winSize+"; transLen "+transLen+"; // fltLen "+fltLen+"; warp "+warp+"; � "+f1 ); win = Filter.createFullWindow(winSize, Filter.WIN_HANNING); // DAFx2000 (27) outputStep = inputStep; b0init = (float) Math.sqrt(1.0f - warp * warp); progOff = 0; progLen = (long) inLength * (2 + inChanNum); // + winSize; tempFlt = new float[fltLen]; inputLen = winSize + inputStep; inBuf = new float[inChanNum][inputLen]; outputLen = transLen + outputStep; outBuf = new float[inChanNum][outputLen]; // normalization requires temp files if (pr.intg[PR_GAINTYPE] == GAIN_UNITY) { tempFile = new File[inChanNum]; floatF = new FloatFile[inChanNum]; for (ch = 0; ch < inChanNum; ch++) { // first zero them because an exception might be thrown tempFile[ch] = null; floatF[ch] = null; } for (ch = 0; ch < inChanNum; ch++) { tempFile[ch] = IOUtil.createTempFile(); floatF[ch] = new FloatFile(tempFile[ch], GenericFile.MODE_OUTPUT); } progLen += (long) inLength; } else { gain = (float) ((Param.transform(pr.para[PR_GAIN], Param.ABS_AMP, ampRef, null)).val); } // .... check running .... if (!threadRunning) break topLevel; // ----==================== the real stuff ====================---- framesRead = 0; framesWritten = 0; skip = 0; while (threadRunning && (framesWritten < inLength)) { chunkLength = Math.min(inputLen, inLength - framesRead + skip); // ---- read input chunk ---- len = Math.max(0, chunkLength - skip); inF.readFrames(inBuf, skip, len); framesRead += len; progOff += len; // off += len; // .... progress .... setProgression((float) progOff / (float) progLen); // .... check running .... if (!threadRunning) break topLevel; // zero padding if (chunkLength < inputLen) { for (ch = 0; ch < inChanNum; ch++) { convBuf1 = inBuf[ch]; for (i = chunkLength; i < convBuf1.length; i++) { convBuf1[i] = 0.0f; } } } for (ch = 0; threadRunning && (ch < inChanNum); ch++) { convBuf1 = inBuf[ch]; convBuf2 = outBuf[ch]; for (i = 0, j = fltLen; i < winSize; i++) { tempFlt[--j] = convBuf1[i] * win[i]; } while (j > 0) { tempFlt[--j] = 0.0f; } a1 = -warp; // inital allpass b0 = b0init; b1 = 0.0f; for (j = 0; j < transLen; j++) { x1 = 0.0f; y1 = 0.0f; // for( i = 0; i < transLen; i++ ) { // DAFx2000 (2 resp. 3) for (i = 0; i < fltLen; i++) { // DAFx2000 (2 resp. 3) x0 = tempFlt[i]; y0 = b0 * x0 + b1 * x1 - a1 * y1; tempFlt[i] = y0; // (work with double precision while computing cascades) y1 = y0; x1 = x0; } a1 = -warp; // cascaded allpasses b0 = -warp; b1 = 1.0f; convBuf2[j] += (float) y1; } // .... progress .... progOff += chunkLength - skip; setProgression((float) progOff / (float) progLen); } // for channels // .... check running .... if (!threadRunning) break topLevel; chunkLength = Math.min(outputStep, inLength - framesWritten); // ---- write output chunk ---- if (floatF != null) { for (ch = 0; ch < inChanNum; ch++) { floatF[ch].writeFloats(outBuf[ch], 0, chunkLength); } progOff += chunkLength; // off += len; framesWritten += chunkLength; // .... progress .... setProgression((float) progOff / (float) progLen); } else { for (ch = 0; ch < inChanNum; ch++) { Util.mult(outBuf[ch], 0, chunkLength, gain); } outF.writeFrames(outBuf, 0, chunkLength); progOff += chunkLength; // off += len; framesWritten += chunkLength; // .... progress .... setProgression((float) progOff / (float) progLen); } // .... check running .... if (!threadRunning) break topLevel; // check max amp for (ch = 0; ch < inChanNum; ch++) { convBuf1 = outBuf[ch]; for (i = 0; i < chunkLength; i++) { f1 = Math.abs(convBuf1[i]); if (f1 > maxAmp) { maxAmp = f1; } } } // overlaps skip = winSize; for (ch = 0; ch < inChanNum; ch++) { System.arraycopy(inBuf[ch], inputStep, inBuf[ch], 0, winSize); convBuf1 = outBuf[ch]; System.arraycopy(convBuf1, outputStep, convBuf1, 0, transLen); for (i = transLen; i < outputLen; ) { convBuf1[i++] = 0.0f; } } } // until framesWritten == outLength // .... check running .... if (!threadRunning) break topLevel; // ----==================== normalize output ====================---- if (pr.intg[PR_GAINTYPE] == GAIN_UNITY) { peakGain = new Param((double) maxAmp, Param.ABS_AMP); gain = (float) (Param.transform( pr.para[PR_GAIN], Param.ABS_AMP, new Param(1.0 / peakGain.val, peakGain.unit), null)) .val; normalizeAudioFile(floatF, outF, inBuf, gain, 1.0f); maxAmp *= gain; for (ch = 0; ch < inChanNum; ch++) { floatF[ch].cleanUp(); floatF[ch] = null; tempFile[ch].delete(); tempFile[ch] = null; } } // .... check running .... if (!threadRunning) break topLevel; // ---- Finish ---- outF.close(); outF = null; outStream = null; inF.close(); inF = null; inStream = null; inBuf = null; // inform about clipping/ low level handleClipping(maxAmp); } catch (IOException e1) { setError(e1); } catch (OutOfMemoryError e2) { inStream = null; outStream = null; inBuf = null; convBuf1 = null; convBuf2 = null; System.gc(); setError(new Exception(ERR_MEMORY)); ; } // ---- cleanup (topLevel) ---- if (inF != null) { inF.cleanUp(); inF = null; } if (outF != null) { outF.cleanUp(); outF = null; } if (floatF != null) { for (ch = 0; ch < floatF.length; ch++) { if (floatF[ch] != null) { floatF[ch].cleanUp(); floatF[ch] = null; } if (tempFile[ch] != null) { tempFile[ch].delete(); tempFile[ch] = null; } } } } // process()
protected void plotParameterPlane() { double x1 = x.getElement(0); double x2 = x.getElement(1); double dx1 = Math.sqrt(cx.getElement(0, 0)); double dx2 = Math.sqrt(cx.getElement(1, 1)); double rho = (cx.getElement(1, 0)) / (dx1 * dx2); // prepare size of plot double xmin = x1 - 2. * dx1; double xmax = x1 + 2. * dx1; double ymin = x2 - 2. * dx2; double ymax = x2 + 2. * dx2; DatanGraphics.openWorkstation(getClass().getName(), "E3Min_2.ps"); DatanGraphics.setFormat(0., 0.); DatanGraphics.setWindowInComputingCoordinates(xmin, xmax, ymin, ymax); DatanGraphics.setViewportInWorldCoordinates(.2, .9, .16, .86); DatanGraphics.setWindowInWorldCoordinates(-.414, 1., 0., 1.); DatanGraphics.setBigClippingWindow(); DatanGraphics.chooseColor(2); DatanGraphics.drawFrame(); DatanGraphics.drawScaleX("x_1"); DatanGraphics.drawScaleY("x_2"); DatanGraphics.drawBoundary(); DatanGraphics.chooseColor(5); // draw data point with errors (and correlation) DatanGraphics.drawDatapoint(1, 1., x1, x2, dx1, dx2, rho); DatanGraphics.chooseColor(2); DatanGraphics.drawCaption(1., caption); // draw confidence contour double fcont = mllg.getValue(x) + .5; int nx = 100; int ny = 100; double dx = (xmax - xmin) / (int) nx; double dy = (ymax - ymin) / (int) ny; MinLogLikeGaussCont mllgc = new MinLogLikeGaussCont(); // System.out.println(" x = " + x.toString() + ", mllgc.getValue(x) = " + // mllgc.getValue(x.getElement(0), x.getElement(1))); DatanGraphics.setBigClippingWindow(); DatanGraphics.chooseColor(1); DatanGraphics.drawContour(xmin, ymin, dx, dy, nx, ny, fcont, mllgc); // draw asymmetric errors as horiyontal and vertical bars DatanGraphics.chooseColor(3); double[] xpl = new double[2]; double[] ypl = new double[2]; for (int i = 0; i < 2; i++) { if (i == 0) xpl[0] = x1 - dxasy[0][0]; else xpl[0] = x1 + dxasy[0][1]; xpl[1] = xpl[0]; ypl[0] = ymin; ypl[1] = ymax; DatanGraphics.drawPolyline(xpl, ypl); } for (int i = 0; i < 2; i++) { if (i == 0) ypl[0] = x2 - dxasy[1][0]; else ypl[0] = x2 + dxasy[1][1]; ypl[1] = ypl[0]; xpl[0] = xmin; xpl[1] = xmax; DatanGraphics.drawPolyline(xpl, ypl); } DatanGraphics.closeWorkstation(); }
private ArrayList<RSTile> generatePath(Line[] lines) { double minStep = 5, maxStep = 10, wander = 3; if (lines.length < 2) return null; ArrayList<RSTile> path = new ArrayList<RSTile>(); Line l1, l2 = lines[0]; double distFromCenter = random(0, l2.getDistance() + 1); RSTile p = l2.translate((int) distFromCenter); distFromCenter = l2.getDistance() / 2 - distFromCenter; double centerXdist, centerYdist, line1Xdist, line1Ydist, line2Xdist, line2Ydist; double line1dist, line2dist, centerDist; double x, y; double distOnLine, last, cap1, cap2, move; double distFromCenterX1, distFromCenterY1, distFromCenterX2, distFromCenterY2; double force1, force2, slopeX, slopeY, slopeDist; boolean finished; int lastX = p.getX(), lastY = p.getY(), curX, curY; double dist, xdist, ydist; for (int i = 1; i < lines.length; i++) { l1 = l2; l2 = lines[i]; centerXdist = l2.getCenterX() - l1.getCenterX(); centerYdist = l2.getCenterY() - l1.getCenterY(); centerDist = Math.sqrt(centerXdist * centerXdist + centerYdist * centerYdist); line1Xdist = l2.getX() - l1.getX(); line1Ydist = l2.getY() - l1.getY(); line2Xdist = l2.getX2() - l1.getX2(); line2Ydist = l2.getY2() - l1.getY2(); centerXdist /= centerDist; centerYdist /= centerDist; line1Xdist /= centerDist; line1Ydist /= centerDist; line2Xdist /= centerDist; line2Ydist /= centerDist; distOnLine = 0; last = 0; finished = false; while (!finished) { distOnLine += random(minStep, maxStep); if (distOnLine >= centerDist) { distOnLine = centerDist; finished = true; } x = centerXdist * distOnLine + l1.getCenterX(); y = centerYdist * distOnLine + l1.getCenterY(); distFromCenterX1 = x - (line1Xdist * distOnLine + l1.getX()); distFromCenterY1 = y - (line1Ydist * distOnLine + l1.getY()); distFromCenterX2 = x - (line2Xdist * distOnLine + l1.getX2()); distFromCenterY2 = y - (line2Ydist * distOnLine + l1.getY2()); slopeX = distFromCenterX2 - distFromCenterX1; slopeY = distFromCenterY2 - distFromCenterY1; slopeDist = Math.sqrt(slopeX * slopeX + slopeY * slopeY); slopeX /= slopeDist; slopeY /= slopeDist; line1dist = Math.sqrt(distFromCenterX1 * distFromCenterX1 + distFromCenterY1 * distFromCenterY1); line2dist = Math.sqrt(distFromCenterX2 * distFromCenterX2 + distFromCenterY2 * distFromCenterY2); move = (distOnLine - last) / maxStep * wander; force1 = line1dist + distFromCenter; force2 = line2dist - distFromCenter; cap1 = Math.min(move, force1); cap2 = Math.min(move, force2); if (force1 < 0) distFromCenter -= force1; else if (force2 < 0) distFromCenter += force2; else distFromCenter += random(-cap1, cap2); if (finished) { RSTile t = l2.translateFromCenter(distFromCenter); curX = t.getX(); curY = t.getY(); } else { curX = (int) Math.round(distOnLine * centerXdist + l1.getCenterX() + distFromCenter * slopeX); curY = (int) Math.round(distOnLine * centerYdist + l1.getCenterY() + distFromCenter * slopeY); } xdist = curX - lastX; ydist = curY - lastY; dist = Math.sqrt(xdist * xdist + ydist * ydist); xdist /= dist; ydist /= dist; for (int j = 0; j < dist; j++) path.add( new RSTile((int) Math.round(xdist * j + lastX), (int) Math.round(ydist * j + lastY))); last = distOnLine; lastX = curX; lastY = curY; } } return cutUp(path); }
public void updatebeta() { for (int i = 0; i <= ncurves; i++) { brightmincc[i] = (bright1[i] * beta) / Math.sqrt(intensity1[i] / intensity2[i]); eminccarray[i].setText("" + (float) brightmincc[i]); } }