List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
From source file:moa.classifiers.core.statisticaltests.Cramer.java
private Complex[] fft(Complex[] x) { int N = x.length; // base case/* w w w .j a v a 2 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:com.alvermont.terraj.fracplanet.geom.TriangleMeshFlat.java
/** * Create the mesh object// w ww .java 2 s . c o 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.GnomonicProjection.java
/** * Carry out the projection//www. j a va2s .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: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>(); ///* w w w . j a va2 s . co 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; }
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;/*from w w w. ja 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:fr.amap.viewer3d.object.camera.TrackballCamera.java
@Override public void rotateAroundPoint(Vec3F axis, Vec3F pivot, float angle) { if (axis.x != 0) { //this.angleX = angle; this.angleX = this.angleX + angle; float r = (float) Math.sqrt(Math.pow(pivot.z - location.z, 2) + Math.pow(pivot.y - location.y, 2)); float z = (float) (pivot.z + r * Math.cos(this.angleX)); float y = (float) (pivot.y + r * Math.sin(this.angleX)); location.z = z;//from w w w. j a v a 2s.co m location.y = y; } else if (axis.y != 0) { //this.angleY = angle; this.angleY = this.angleY + angle; /* if(Math.toDegrees(angleY)>360){ angleY = (float) Math.toRadians(Math.toDegrees(angleY) - 360); }else if(Math.toDegrees(angleY)<0){ angleY = (float) Math.toRadians(360 - Math.toDegrees(-angleY)); } */ float r = (float) Math.sqrt(Math.pow(pivot.x - location.x, 2) + Math.pow(pivot.z - location.z, 2)); float x = (float) (pivot.x + r * Math.cos(this.angleY)); float z = (float) (pivot.z + r * Math.sin(this.angleY)); location.x = x; location.z = z; } else if (axis.z != 0) { //this.angleZ = angle; this.angleZ = this.angleZ + angle; float r = (float) Math.sqrt(Math.pow(pivot.x - location.x, 2) + Math.pow(pivot.y - location.y, 2)); float x = (float) (pivot.x + r * Math.cos(this.angleZ)); float y = (float) (pivot.y + r * Math.sin(this.angleZ)); location.x = x; location.y = y; } target = pivot; updateViewMatrix(); }
From source file:chiliad.parser.pdf.extractor.vectorgraphics.operator.BeginInlineImage.java
/** * process : BI : begin inline image./*w w w. ja v a 2 s . co m*/ * * @param operator The operator that is being executed. * @param arguments List * @throws IOException If there is an error displaying the inline image. */ @Override public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { VectorGraphicsExtractor extractor = (VectorGraphicsExtractor) context; PDPage page = extractor.getPage(); //begin inline image object ImageParameters params = operator.getImageParameters(); PDInlinedImage image = new PDInlinedImage(); image.setImageParameters(params); image.setImageData(operator.getImageData()); if (params.isStencil()) { //TODO implement inline image stencil masks LOG.warn("Stencil masks are not implemented, background may be incorrect"); } BufferedImage awtImage = image.createImage(context.getColorSpaces()); if (awtImage == null) { LOG.warn("BeginInlineImage.process(): createImage returned NULL"); return; } int imageWidth = awtImage.getWidth(); int imageHeight = awtImage.getHeight(); double pageHeight = extractor.getPageSize().getHeight(); Matrix ctm = extractor.getGraphicsState().getCurrentTransformationMatrix(); int pageRotation = page.findRotation(); AffineTransform ctmAT = ctm.createAffineTransform(); ctmAT.scale(1f / imageWidth, 1f / imageHeight); Matrix rotationMatrix = new Matrix(); rotationMatrix.setFromAffineTransform(ctmAT); // calculate the inverse rotation angle // scaleX = m00 = cos // shearX = m01 = -sin // tan = sin/cos double angle = Math.atan(ctmAT.getShearX() / ctmAT.getScaleX()); Matrix translationMatrix = null; if (pageRotation == 0 || pageRotation == 180) { translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getXScale()), (float) (pageHeight - 2 * ctm.getYPosition() - Math.cos(angle) * ctm.getYScale())); } else if (pageRotation == 90 || pageRotation == 270) { translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getYScale()), (float) (pageHeight - 2 * ctm.getYPosition())); } rotationMatrix = rotationMatrix.multiply(translationMatrix); rotationMatrix.setValue(0, 1, (-1) * rotationMatrix.getValue(0, 1)); rotationMatrix.setValue(1, 0, (-1) * rotationMatrix.getValue(1, 0)); AffineTransform at = new AffineTransform(rotationMatrix.getValue(0, 0), rotationMatrix.getValue(0, 1), rotationMatrix.getValue(1, 0), rotationMatrix.getValue(1, 1), rotationMatrix.getValue(2, 0), rotationMatrix.getValue(2, 1)); extractor.drawImage(awtImage, at); }
From source file:Similaridade.GraficosSimilaridade.java
public static XYDataset newDataset2OndasComDeslocada(CapturaAtual onda1, CapturaAtual onda2, int deslocamento, double correlacao) { //metodo que cria um CategoryDataset para ser usado em grafico de linhas float valOnda1[] = new float[Configuracoes.PONTOSONDA]; float valOnda2[] = new float[Configuracoes.PONTOSONDA]; float sen1[] = new float[Configuracoes.HARMONICAS]; float cos1[] = new float[Configuracoes.HARMONICAS]; float sen2[] = new float[Configuracoes.HARMONICAS]; float cos2[] = new float[Configuracoes.HARMONICAS]; int i;/* w w w . j a va 2 s. c om*/ float s1, s2, tempo[] = new float[Configuracoes.PONTOSONDA]; XYSeriesCollection result = new XYSeriesCollection(); for (i = 0; i < Configuracoes.HARMONICAS; i++) { sen1[i] = 0; cos1[i] = 0; sen2[i] = 0; cos2[i] = 0; } i = 0; for (HarmAtual oa : onda1.getHarmAtual()) { sen1[i] = oa.getSen(); cos1[i] = oa.getCos(); i++; } i = 0; for (HarmAtual oa : onda2.getHarmAtual()) { sen2[i] = oa.getSen(); cos2[i] = oa.getCos(); i++; } XYSeries series1 = new XYSeries(String.valueOf(onda1.getCodCaptura())); XYSeries series3 = new XYSeries("Shift " + String.valueOf(onda2.getCodCaptura())); tempo[0] = 0; //(float) 1 / 60; for (i = 0; i < Configuracoes.PONTOSONDA; i++) { if (TIRADOVM == 0) { s1 = onda1.getValorMedio() / 2; s2 = onda2.getValorMedio() / 2; } else { s1 = onda1.getValorMedio(); s2 = onda2.getValorMedio(); } for (int x = 0; x < Configuracoes.HARMONICAS; x++) { if (TIRADOVM == 0) { s1 += (float) (sen1[x] * Math.sin(2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i])) + (cos1[x] * Math.cos(-2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i])); s2 += (float) (sen2[x] * Math.sin(2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i])) + (cos2[x] * Math.cos(-2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i])); } else { s1 += (float) (sen1[x] * Math.sin(2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i])) + (cos1[x] * Math.cos(2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i])); s2 += (float) (sen2[x] * Math.sin(2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i])) + (cos2[x] * Math.cos(2 * Math.PI * ((x + 1) * Configuracoes.FREQBASE) * tempo[i])); } } if (TIRADOVM == 0) { valOnda1[i] = (int) ((s1 * (2.0)) / 256.0); valOnda1[i] = (valOnda1[i] - onda1.getOffset()); valOnda2[i] = (int) ((s2 * (2.0)) / 256.0); valOnda2[i] = (valOnda2[i] - onda2.getOffset()); } else { valOnda1[i] = (s1); valOnda2[i] = (s2); } valOnda1[i] = (valOnda1[i]) / onda1.getGain(); valOnda2[i] = (valOnda2[i]) / onda2.getGain(); series1.add(tempo[i] * 1000, valOnda1[i]); if (i == (Configuracoes.PONTOSONDA - 1)) { break; } tempo[i + 1] = (tempo[i] + (float) (1.0 / (60 * 256))); } int j = 0; if (correlacao < 0) { for (i = 0; i < Configuracoes.PONTOSONDA; i++) { if ((i + deslocamento) <= (Configuracoes.PONTOSONDA - 1)) { series3.add(tempo[i] * 1000, -1 * valOnda2[i + deslocamento]); } else { series3.add(tempo[i] * 1000, -1 * valOnda2[j++]); } } } else { for (i = 0; i < Configuracoes.PONTOSONDA; i++) { if ((i + deslocamento) <= (Configuracoes.PONTOSONDA - 1)) { series3.add(tempo[i] * 1000, valOnda2[i + deslocamento]); } else { series3.add(tempo[i] * 1000, valOnda2[j++]); } } } result.addSeries(series1); result.addSeries(series3); return result; }
From source file:com.opengamma.strata.math.impl.minimization.SumToOneTest.java
@Test public void solverTest2() { double[] w = new double[] { 3.0, 4.0 }; final int n = w.length; Function<DoubleArray, DoubleArray> func = new Function<DoubleArray, DoubleArray>() { @Override// w ww . j ava 2s . c o m public DoubleArray apply(DoubleArray x) { double a = x.get(0); double theta = x.get(1); double c1 = Math.cos(theta); return DoubleArray.of(a * c1 * c1, a * (1 - c1 * c1)); } }; DoubleArray sigma = DoubleArray.filled(n, 1e-4); DoubleArray start = DoubleArray.of(0.0, 0.8); LeastSquareResults res = SOLVER.solve(DoubleArray.copyOf(w), sigma, func, start/*, maxJump*/); assertEquals("chi sqr", 0.0, res.getChiSq(), 1e-9); double[] fit = res.getFitParameters().toArray(); assertEquals(7.0, fit[0], 1e-9); assertEquals(Math.atan(Math.sqrt(4 / 3.)), fit[1], 1e-9); }
From source file:io.github.malapert.jwcs.coordsystem.Utility.java
/** * Calculates the matrix that represents a 3d rotation around the Z axis. * /*w w w . j ava 2s . c o m*/ * @param angle Rotation angle in degrees * @return A 3x3 matrix representing the rotation about angle around Z axis. */ public final static RealMatrix rotZ(double angle) { double angleRadians = Math.toRadians(angle); double[][] array = { { Math.cos(angleRadians), Math.sin(angleRadians), 0.d }, { -1 * Math.sin(angleRadians), Math.cos(angleRadians), 0.d }, { 0.d, 0.d, 1.d } }; return MatrixUtils.createRealMatrix(array); }