List of usage examples for java.lang Math sin
@HotSpotIntrinsicCandidate public static double sin(double a)
From source file:de.openali.odysseus.chart.framework.util.img.GenericChartLabelRenderer.java
private Rectangle calcSize(final GC gc, final int degree) { if (m_titleBean == null) return new Rectangle(0, 0, 0, 0); final Point textSize = calcTextSize(gc, m_titleBean.getText()); final int border = isDrawBorder() ? m_borderStyle.getStroke().getWidth() : 0; final Point overAllSize = new Point( textSize.x + border * 2 + m_titleBean.getInsets().left + m_titleBean.getInsets().right, textSize.y + border * 2 + m_titleBean.getInsets().top + m_titleBean.getInsets().bottom); final Rectangle textRect = getTextRect(m_titleBean.getTextAnchorX(), m_titleBean.getTextAnchorY(), overAllSize);// www. j ava 2 s.c om final double radian = Math.toRadians(degree); final double cosi = Math.cos(radian); final double sinu = Math.sin(radian); final double rotX = cosi * textRect.x + sinu * textRect.y; final double rotY = sinu * textRect.x + cosi * textRect.y; final double rotWidth = Math.abs(cosi * textRect.width) + Math.abs(sinu * textRect.height); final double rotHeight = Math.abs(sinu * textRect.width) + Math.abs(cosi * textRect.height); return new Rectangle((int) Math.round(rotX), (int) Math.round(rotY), (int) Math.round(rotWidth), (int) Math.round(rotHeight)); }
From source file:edu.ucsf.valelab.saim.calculations.SaimCalc.java
public static double fieldStrength(final double wavelength, final double angle, final double nSample, final double dOx, final double distance) { Complex rTE = fresnelTE(wavelength, angle, dOx, nSample); double phaseDiff = PhaseDiff(wavelength, angle, nSample, distance); Complex tmp = new Complex(Math.cos(phaseDiff), Math.sin(phaseDiff)); Complex fieldStrength = rTE.multiply(tmp); fieldStrength = fieldStrength.add(1.0); return fieldStrength.getReal() * fieldStrength.getReal() + fieldStrength.getImaginary() * fieldStrength.getImaginary(); }
From source file:com.alvermont.terraj.planet.project.GnomonicProjection.java
/** * Carry out the projection/*from w w w . j ava 2 s .co m*/ */ public void project() { setcolours(); final int width = getParameters().getProjectionParameters().getWidth(); final int height = getParameters().getProjectionParameters().getHeight(); final double lat = getParameters().getProjectionParameters().getLatitudeRadians(); final double lon = getParameters().getProjectionParameters().getLongitudeRadians(); final double scale = getParameters().getProjectionParameters().getScale(); final double hgrid = getParameters().getProjectionParameters().getHgrid(); final double vgrid = getParameters().getProjectionParameters().getVgrid(); final boolean doShade = getParameters().getProjectionParameters().isDoShade(); cacheParameters(); colours = new short[width][height]; shades = new short[width][height]; final double sla = Math.sin(lat); final double cla = Math.cos(lat); final double slo = Math.sin(lon); final double clo = Math.cos(lon); depth = (3 * ((int) (log2(scale * height)))) + 6; double x; double y; double z; double x1; double y1; double z1; double zz; double theta1; double theta2; double ymin; double ymax; int i; int j; ymin = 2.0; ymax = -2.0; progress.progressStart(height, "Generating Terrain"); for (j = 0; j < height; ++j) { progress.progressStep(j); for (i = 0; i < width; ++i) { x = ((2.0 * i) - width) / height / scale; y = ((2.0 * j) - height) / height / scale; zz = Math.sqrt(1.0 / (1.0 + (x * x) + (y * y))); x = x * zz; y = y * zz; z = Math.sqrt(1.0 - (x * x) - (y * y)); x1 = (clo * x) + (slo * sla * y) + (slo * cla * z); y1 = (cla * y) - (sla * z); z1 = (-slo * x) + (clo * sla * y) + (clo * cla * z); if (y1 < ymin) { ymin = y1; } if (y1 > ymax) { ymax = y1; } colours[i][j] = (short) planet0(x1, y1, z1); if (doShade) { shades[i][j] = shade; } } } progress.progressComplete("Terrain Generated"); if (hgrid != 0.0) { /* draw horizontal gridlines */ for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid) ; for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) { y = Math.sin(Math.toRadians(theta1)); if ((ymin <= y) && (y <= ymax)) { zz = Math.sqrt(1 - (y * y)); for (theta2 = -Math.PI; theta2 < Math.PI; theta2 += (0.5 / width / scale)) { x = Math.sin(theta2) * zz; z = Math.cos(theta2) * zz; x1 = (clo * x) - (slo * z); y1 = (slo * sla * x) + (cla * y) + (clo * sla * z); z1 = (slo * cla * x) - (sla * y) + (clo * cla * z); if (z1 != 0.0) { i = (int) (0.5 * (((height * scale * x1) / z1) + width)); j = (int) (0.5 * (((height * scale * y1) / z1) + height)); if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) { colours[i][j] = BLACK; } } } } } } if (vgrid != 0.0) { /* draw vertical gridlines */ for (theta2 = -Math.PI; theta2 < Math.PI; theta2 += (0.5 / width / scale)) { y = Math.sin(theta2); if ((ymin <= y) && (y <= ymax)) { for (theta1 = 0.0; theta1 < 360.0; theta1 += vgrid) { x = Math.sin(Math.toRadians(theta1)) * Math.cos(theta2); z = Math.cos(Math.toRadians(theta1)) * Math.cos(theta2); x1 = (clo * x) - (slo * z); y1 = (slo * sla * x) + (cla * y) + (clo * sla * z); z1 = (slo * cla * x) - (sla * y) + (clo * cla * z); if (z1 != 0.0) { i = (int) (0.5 * (((height * scale * x1) / z1) + width)); j = (int) (0.5 * (((height * scale * y1) / z1) + height)); if ((0 <= i) && (i < width) && (0 <= j) && (j < height)) { colours[i][j] = BLACK; } } } } } } if (doShade) { smoothshades(); } doOutlining(); }
From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java
@Test public void sinNegative() { try {//from ww w. j ava 2 s . c o m Expression expression = getExpressionWithFunctionContext("sin(-10)"); assertEquals(ExpressionType.DOUBLE, expression.getExpressionType()); assertEquals(Math.sin(-10), expression.evaluateNumerical(), 1e-15); } catch (ExpressionException e) { assertNotNull(e.getMessage()); } }
From source file:moa.classifiers.core.statisticaltests.Cramer.java
private Complex[] fft(Complex[] x) { int N = x.length; // base case/*w ww . ja va2 s. c om*/ if (N == 1) { return new Complex[] { x[0] }; } // radix 2 Cooley-Tukey FFT if (N % 2 != 0) { throw new RuntimeException("N is not a power of 2"); } // fft of even terms Complex[] even = new Complex[N / 2]; for (int k = 0; k < N / 2; k++) { even[k] = x[2 * k]; } Complex[] q = fft(even); // fft of odd terms Complex[] odd = even; // reuse the array for (int k = 0; k < N / 2; k++) { odd[k] = x[2 * k + 1]; } Complex[] r = fft(odd); // combine Complex[] yy = new Complex[N]; for (int k = 0; k < N / 2; k++) { double kth = -2 * k * Math.PI / N; Complex wk = new Complex(Math.cos(kth), Math.sin(kth)); yy[k] = q[k].add(wk.multiply(r[k])); yy[k + N / 2] = q[k].subtract(wk.multiply(r[k])); } return yy; }
From source file:BackEnd.B_calculation.java
private double getI_image() { double I_image = I * Math.sin(phase * (Math.PI / 180)); return I_image; }
From source file:es.udc.gii.common.eaf.benchmark.multiobjective.wfg.Wfg_Objective.java
protected double concave(double[] x, int m, int M) { int i;/* w ww . j a va 2 s. c o m*/ double result = 1.0; for (i = 1; i <= M - m; i++) { result *= Math.sin(x[i - 1] * Math.PI / 2.0); } if (m != 1) { result *= Math.cos(x[M - m] * Math.PI / 2.0); } return correct_to_01(result, EPSILON); }
From source file:com.alvermont.terraj.fracplanet.geom.TriangleMeshFlat.java
/** * Create the mesh object//from w w w . jav a 2s.co m */ protected void buildMesh() { switch (this.ttype) { case TRIANGLE: for (int i = 0; i < 3; ++i) { addVertex(new SimpleVertex(new SimpleXYZ((float) Math.cos(i * 2.0 * Math.PI / 3.0), (float) Math.sin(i * 2.0 * Math.PI / 3.0), z))); } addTriangle(new SimpleTriangle(0, 1, 2)); break; case SQUARE: addVertex(new SimpleVertex(new SimpleXYZ(0.0f, 0.0f, z))); for (int i = 0; i < 4; ++i) { addVertex(new SimpleVertex(new SimpleXYZ((float) Math.cos(i * Math.PI / 2.0), (float) Math.sin(i * Math.PI / 2.0), z))); } for (int i = 0; i < 4; ++i) { addTriangle(new SimpleTriangle(0, 1 + i, 1 + (i + 1) % 4)); } break; case HEXAGON: default: addVertex(new SimpleVertex(new SimpleXYZ(0.0f, 0.0f, z))); for (int i = 0; i < 6; ++i) { addVertex(new SimpleVertex(new SimpleXYZ((float) Math.cos(i * Math.PI / 3.0), (float) Math.sin(i * Math.PI / 3.0), z))); } for (int i = 0; i < 6; ++i) { addTriangle(new SimpleTriangle(0, 1 + i, 1 + (i + 1) % 6)); } break; } }
From source file:com.alvermont.terraj.planet.project.MercatorProjection.java
/** * Carry out the projection// w w w . ja va 2s . co m */ public void project() { setcolours(); final int width = getParameters().getProjectionParameters().getWidth(); final int height = getParameters().getProjectionParameters().getHeight(); final double lat = getParameters().getProjectionParameters().getLatitudeRadians(); final double lon = getParameters().getProjectionParameters().getLongitudeRadians(); final double scale = getParameters().getProjectionParameters().getScale(); final double hgrid = getParameters().getProjectionParameters().getHgrid(); final double vgrid = getParameters().getProjectionParameters().getVgrid(); final boolean doShade = getParameters().getProjectionParameters().isDoShade(); cacheParameters(); colours = new short[width][height]; shades = new short[width][height]; double y; double scale1; double cos2; double theta1; int i; int j; int k; y = Math.sin(lat); y = (1.0 + y) / (1.0 - y); y = 0.5 * Math.log(y); k = (int) ((0.5 * y * width * scale) / Math.PI); progress.progressStart(height, "Generating Terrain"); for (j = 0; j < height; ++j) { // if (debug && ((j % (Height/25)) == 0)) // {fprintf(stderr, "%c", view); fflush(stderr);} progress.progressStep(j); y = (Math.PI * ((2.0 * (j - k)) - height)) / width / scale; y = Math.exp(2. * y); y = (y - 1.) / (y + 1.); scale1 = (scale * width) / height / Math.sqrt(1.0 - (y * y)) / Math.PI; cos2 = Math.sqrt(1.0 - (y * y)); depth = (3 * ((int) (log2(scale1 * height)))) + 3; for (i = 0; i < width; ++i) { theta1 = lon - (0.5 * Math.PI) + ((Math.PI * ((2.0 * i) - width)) / width / scale); colours[i][j] = (short) planet0(Math.cos(theta1) * cos2, y, -Math.sin(theta1) * cos2); if (doShade) { shades[i][j] = shade; } } } progress.progressComplete("Terrain Generated"); if (hgrid != 0.0) { /* draw horizontal gridlines */ for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid) ; for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) { y = Math.sin(Math.toRadians(theta1)); y = (1.0 + y) / (1.0 - y); y = 0.5 * Math.log(y); j = (height / 2) + (int) ((0.5 * y * width * scale) / Math.PI) + k; if ((j >= 0) && (j < height)) { for (i = 0; i < width; ++i) colours[i][j] = BLACK; } } } if (vgrid != 0.0) { /* draw vertical gridlines */ for (theta1 = 0.0; theta1 > -360.0; theta1 -= vgrid) ; for (theta1 = theta1; theta1 < 360.0; theta1 += vgrid) { i = (int) (0.5 * width * (1.0 + ((scale * (Math.toRadians(theta1) - lon)) / Math.PI))); if ((i >= 0) && (i < width)) { for (j = 0; j < height; ++j) colours[i][j] = BLACK; } } } if (doShade) { smoothshades(); } }
From source file:net.ostis.scpdev.scg.geometry.LayoutRunnable.java
private void calculateForces() { int n = nodes.size(); RealVector[] forces = new RealVector[n]; for (int i = 0; i < n; ++i) forces[i] = new ArrayRealVector(nullVector); Map<IFigure, Integer> obj_f = new HashMap<IFigure, Integer>(); ///*from w w w .j a v a2 s.c o m*/ // Calculation repulsion forces. // for (int idx = 0; idx < n; ++idx) { SCgNodeShape obj = nodes.get(idx); obj_f.put(obj, idx); Point p1 = translateToCenter(obj.getBounds().getLocation()); RealVector p1v = new ArrayRealVector(2); p1v.setEntry(0, p1.x); p1v.setEntry(1, p1.y); double l = nullVector.getDistance(p1v); RealVector f = p1v.mapMultiply(gravity * (l - 3.0)); forces[idx] = forces[idx].subtract(f); for (int jdx = idx + 1; jdx < n; ++jdx) { Point p2 = translateToCenter(nodes.get(jdx).getBounds().getLocation()); RealVector p2v = new ArrayRealVector(2); p2v.setEntry(0, p2.x); p2v.setEntry(1, p2.y); l = p1v.getDistance(p2v) / 50; if (l > max_rep_length) continue; if (l > 0.5) { f = p1v.subtract(p2v).mapMultiply(repulsion / l / l); } else { f = new ArrayRealVector(new double[] { Math.cos(0.17 * idx) * length * 7, Math.sin(0.17 * (idx + 1)) * length * 7 }); } forces[idx] = forces[idx].add(f); forces[jdx] = forces[jdx].subtract(f); } } // // Calculation springs. // for (SCgPairConnection line : lines) { SCgPair pair = line.getModel(); SCgObject begin = pair.getBegin(); SCgObject end = pair.getEnd(); if (begin == null || end == null) continue; IFigure beginFigure = obj2figure.get(begin); IFigure endFigure = obj2figure.get(end); Point p1 = translateToCenter(beginFigure.getBounds().getLocation()); Point p2 = translateToCenter(endFigure.getBounds().getLocation()); RealVector p1v = new ArrayRealVector(2); p1v.setEntry(0, p1.x); p1v.setEntry(1, p1.y); RealVector p2v = new ArrayRealVector(2); p2v.setEntry(0, p2.x); p2v.setEntry(1, p2.y); double l = p1v.getDistance(p2v) / 50; RealVector f = null; if (l > 0) { RealVector pv = p2v.subtract(p1v); pv.unitize(); int cnt = begin.getInputCount() + end.getOutputCount(); f = pv.mapMultiply(rigidity * (l - Math.max(length, cnt / 3.0)) / l); if (nullVector.getDistance(f) > 10) f = pv.mapMultiply(rigidity / l); } else { f = new ArrayRealVector(nullVector); } if (obj_f.containsKey(beginFigure)) { int index = obj_f.get(beginFigure); forces[index] = forces[index].add(f); } if (obj_f.containsKey(endFigure)) { int index = obj_f.get(endFigure); forces[index] = forces[index].subtract(f); } } double maxf = 0.0; for (int idx = 0; idx < n; ++idx) { RealVector f = forces[idx]; f.mapMultiplyToSelf(stepSize); maxf = Math.max(maxf, nullVector.getDistance(f)); IFigure node = nodes.get(idx); Point location = translateToCenter(node.getBounds().getLocation()); location.x += f.getEntry(0); location.y += f.getEntry(1); node.setLocation(translateFromCenter(location)); } if (maxf > maxForce) { stepSize = stepMaxSize; } else { stepSize *= 0.97; } needLayout = stepSize > stepMinSize; }