List of usage examples for java.lang Math cos
@HotSpotIntrinsicCandidate public static double cos(double a)
From source file:matteroverdrive.util.RenderUtils.java
public static void drawCircle(double radius, int segments) { glBegin(GL_POLYGON);/* w w w .ja va 2s .c o m*/ for (int i = 0; i < segments; i++) { glVertex3d(Math.sin((i / (double) segments) * Math.PI * 2) * radius, Math.cos((i / (double) segments) * Math.PI * 2) * radius, 0); } glEnd(); }
From source file:rod_design_compute.ShowPanel.java
private void drawBasePoint(Point point, Graphics g) { int x = toScreenX(point.X); int y = toScreenY(point.Y); int lengthTri = 4 * radiusBase; int x1 = (int) (x - lengthTri * Math.sin(Math.toRadians(30))); int y1 = (int) (y + lengthTri * Math.cos(Math.toRadians(30))); int x2 = (int) (x + lengthTri * Math.sin(Math.toRadians(30))); int y2 = (int) (y + lengthTri * Math.cos(Math.toRadians(30))); g.drawLine(x, y, x1, y1);/*from ww w.ja v a 2 s . c o m*/ g.drawLine(x, y, x2, y2); g.drawLine(x1 - radiusBase, y1, x2 + radiusBase, y2); g.drawLine(x1, y1, x1 - radiusBase, y1 + radiusBase); g.drawLine(x1 + radiusBase, y1, x1 + radiusBase - radiusBase, y1 + radiusBase); g.drawLine(x1 + 2 * radiusBase, y1, x1 + 2 * radiusBase - radiusBase, y1 + radiusBase); g.drawLine(x1 + 3 * radiusBase, y1, x1 + 3 * radiusBase - radiusBase, y1 + radiusBase); g.drawLine(x1 + 4 * radiusBase, y1, x1 + 4 * radiusBase - radiusBase, y1 + radiusBase); g.setColor(Color.white); g.fillOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2); g.setColor(Color.black); g.drawOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2); }
From source file:RadialLayout.java
/** * This is called when the panel is first displayed, and every time its size * changes./*from www . ja va 2 s . c om*/ * Note: You CAN'T assume preferredLayoutSize or minimumLayoutSize will be * called -- in the case of applets, at least, they probably won't be. * * @param parent the parent. * @see LayoutManager */ public void layoutContainer(final Container parent) { final Insets insets = parent.getInsets(); final int maxWidth = parent.getSize().width - (insets.left + insets.right); final int maxHeight = parent.getSize().height - (insets.top + insets.bottom); final int nComps = parent.getComponentCount(); int x = 0; int y = 0; // Go through the components' sizes, if neither preferredLayoutSize nor // minimumLayoutSize has been called. if (this.sizeUnknown) { setSizes(parent); } if (nComps < 2) { final Component c = parent.getComponent(0); if (c.isVisible()) { final Dimension d = c.getPreferredSize(); c.setBounds(x, y, d.width, d.height); } } else { double radialCurrent = Math.toRadians(90); final double radialIncrement = 2 * Math.PI / nComps; final int midX = maxWidth / 2; final int midY = maxHeight / 2; final int a = midX - this.maxCompWidth; final int b = midY - this.maxCompHeight; for (int i = 0; i < nComps; i++) { final Component c = parent.getComponent(i); if (c.isVisible()) { final Dimension d = c.getPreferredSize(); x = (int) (midX - (a * Math.cos(radialCurrent)) - (d.getWidth() / 2) + insets.left); y = (int) (midY - (b * Math.sin(radialCurrent)) - (d.getHeight() / 2) + insets.top); // Set the component's size and position. c.setBounds(x, y, d.width, d.height); } radialCurrent += radialIncrement; } } }
From source file:com.esri.geoevent.solutions.processor.rangefan.RangeFanProcessor.java
private Geometry constructRangeFan(double x, double y, double range, String unit, double bearing, double traversal) throws Exception { try {/* www. j ava 2 s . c o m*/ Polygon fan = new Polygon(); Point center = new Point(); center.setX(x); center.setY(y); Point centerProj = (Point) GeometryEngine.project(center, srIn, srBuffer); double centerX = centerProj.getX(); double centerY = centerProj.getY(); bearing = GeometryUtility.Geo2Arithmetic(bearing); double leftAngle = bearing - (traversal / 2); double rightAngle = bearing + (traversal / 2); int count = (int) Math.round(Math.abs(leftAngle - rightAngle)); fan.startPath(centerProj); UnitConverter uc = new UnitConverter(); range = uc.Convert(range, unit, srBuffer); for (int i = 0; i < count; ++i) { double d = Math.toRadians(leftAngle + i); double arcX = centerX + (range * Math.cos(d)); double arcY = centerY + (range * Math.sin(d)); Point arcPt = new Point(arcX, arcY); fan.lineTo(arcPt); } fan.closeAllPaths(); return fan; } catch (Exception e) { LOG.error(e.getMessage()); throw e; } }
From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java
@Test public void cosNegative() { try {// w ww . j a v a 2s .c o m Expression expression = getExpressionWithFunctionContext("cos(-10)"); assertEquals(ExpressionType.DOUBLE, expression.getExpressionType()); assertEquals(Math.cos(-10), expression.evaluateNumerical(), 1e-15); } catch (ExpressionException e) { assertNotNull(e.getMessage()); } }
From source file:es.udc.gii.common.eaf.benchmark.real_param.cec2005.CEC2005ObjectiveFunction.java
public double ackley(double[] x) { double s1 = 0.0d; double s2 = 0.0d; for (int i = 0; i < x.length; i++) { s1 += x[i] * x[i];/*from ww w .j av a 2s. co m*/ s2 += Math.cos(2 * Math.PI * x[i]); } return -20 * Math.exp(-0.2 * Math.sqrt(1.0 / x.length * s1)) - Math.exp(1.0 / x.length * s2) + 20 + Math.E; }
From source file:de.thkwalter.et.schlupfbezifferung.SchlupfbezifferungController.java
/** * Diese Methode berechnet das Inversionszentrum (in A). Das Inversionszentrum liegt auf der gedrehten Ortskurve unter * dem Polarwinkel von 315 Grad.// w w w .j av a2 s. co m * * @return Das Inversionzentrum (in A) */ private Vector2D inversionszentrumBerechnen() { // Der Mittelpunkt der gedrehten Ortskurve (in A) wird gelesen. Vector2D mittelpunktOrtskurve = this.schlupfbezifferungModell.getOrtskurve().getMittelpunktOrtskurve(); double m_x = mittelpunktOrtskurve.getX(); double m_y = mittelpunktOrtskurve.getY(); // Der Radius der Ortskurve (in A) wird gelesen. double r = this.schlupfbezifferungModell.getOrtskurve().getRadiusOrtskurve(); // Das Inversionszentrum (in A) wird berechnet. double x_0 = m_x + r * Math.cos(7 * Math.PI / 4); double y_0 = m_y + r * Math.sin(7 * Math.PI / 4); Vector2D inversionszentrum = new Vector2D(x_0, y_0); // Das Inversionszentrum (in A) wird zurckgegeben. return inversionszentrum; }
From source file:experiment.FastCosineTransformer_bug2.java
/** * Perform the FCT algorithm (including inverse). * /*from ww w . j a v a2 s. c o m*/ * @param f * the real data array to be transformed * @return the real transformed array * @throws MathIllegalArgumentException * if the length of the data array is not a power of two plus * one */ protected double[] fct(double[] f) throws MathIllegalArgumentException { final double[] transformed = new double[f.length]; final int n = f.length - 1; if (!ArithmeticUtils.isPowerOfTwo(n)) { throw new MathIllegalArgumentException(LocalizedFormats.NOT_POWER_OF_TWO_PLUS_ONE, Integer.valueOf(f.length)); } if (n == 1) { // trivial case transformed[0] = 0.5 * (f[0] + f[1]); transformed[1] = 0.5 * (f[0] - f[1]); return transformed; } test test1 = new test(); // construct a new array and perform FFT on it final double[] x = new double[n]; x[0] = 0.5 * (f[0] + f[n]); String funname = "cosh/"; double tempexpression = 0; double ta = 3.24, tb = 2.31, tc = 7.86, td = 5.12; int te = 2; boolean tf = false; x[n >> 1] = f[n >> 1]; ta = tb + tc + mid((int) ta + 1, (int) tb, (int) tc) + td; // temporary variable for transformed[1] double t1 = 0.5 * (f[0] - f[n]); ta = (te >> 2) + tc % tb + td; ta = tb + tc + td; ta = tb + tc - td; ta = tb + tc + td + te; ta = tb * tc * td; ta = tb * tc / td; ta = tb * tc * td * te; ta = ta * ta + tb * tb + tc * tc; ta = tc - (td + te); ta = tc + tb - (td + te + tc); ta = tc * tb / tc + test1.a + 3; ta = tc + tb / td - test1.f.a; ta = td + Math.cos(ta + tc - td - te * tb) + tb; ta = Math.min(tc, td + 1) + 1; for (int i = 1; i < (n >> 1); i++) { final double a = 0.5 * (f[i] + f[n - i]); final double b = FastMath.sin(i * FastMath.PI / n) * (f[i] - f[n - i]); /***** * bug2 store in Data2 FastMath.sin(i * FastMath.PI / n) to * FastMath.sin(2*i * FastMath.PI / n) *******/ final double c = FastMath.cos(i * FastMath.PI / n) * (f[i] - f[n - i]); x[i] = a + b; x[n - i] = a - b; tempexpression = t1; t1 = t1 + c; } FastFourierTransformer transformer; transformer = new FastFourierTransformer(DftNormalization.STANDARD); Complex[] y = transformer.transform(x, TransformType.FORWARD); // reconstruct the FCT result for the original array transformed[0] = y[0].getReal(); transformed[1] = t1; for (int i = 1; i < (n >> 1); i++) { transformed[2 * i] = y[i].getReal(); /*** * bug 1, store in Data1, add Math.abs() on transformed[2 * i - 1] - * y[i].getImaginary() ***/ transformed[2 * i + 1] = transformed[2 * i - 1] - y[i].getImaginary(); } transformed[n] = y[n >> 1].getReal(); return transformed; }
From source file:fi.hsl.parkandride.dev.DevController.java
private static Integer sineWaveUtilization(DateTime d, Integer maxCapacity) { // Peaks at 16, so we subtract 16 hours. final double x = (d.minusHours(16).getMinuteOfDay() * 2.0 * Math.PI) / (24.0 * 60.0); // 1 + cos(x) is in range 0..2 so we have to divide the max capacity by 2 final double usedSpaces = (maxCapacity / 2.0) * (1 + Math.cos(x)); return (int) (maxCapacity - usedSpaces); }
From source file:at.uni_salzburg.cs.ros.artificer.VehicleData.java
/** * {@inheritDoc}// ww w .j a v a2 s . com */ @Override public void update() { if (startTime >= clock.currentTimeMillis()) { // do nothing, wait for new task. node.getLog().debug("Waiting for new task."); busy = false; } else if (endTime >= clock.currentTimeMillis()) { busy = true; currentTaskId = newTaskId; heading = newHeading; double completion = 1.0 - (endTime - clock.currentTimeMillis()) / (double) (endTime - startTime); CartesianCoordinate cp = distanceVector.multiply(completion * completion * (3 - 2 * completion)) .add(cartesianStarPosition); PolarCoordinate pos = geodeticSystem.rectangularToPolarCoordinates(cp); currentPosition.setLatitude(pos.getLatitude()); currentPosition.setLongitude(pos.getLongitude()); currentPosition.setAltitude(pos.getAltitude()); node.getLog().info(String.format("VehicleData.update() %f %d %d", completion, (endTime - clock.currentTimeMillis()), (endTime - startTime))); } else { newTaskId = incrementTaskCounter(); currentTaskId = 0; node.getLog().info("Generate new task. " + newTaskId); startPosition = currentPosition; startTime = clock.currentTimeMillis() + (long) (MAXIMUM_WAIT_TIME_FOR_NEW_TASK * RandomUtils.nextDouble()); busy = false; double latitude = minLat + (maxLat - minLat) * RandomUtils.nextDouble(); double longitude = minLng + (maxLng - minLng) * RandomUtils.nextDouble(); double altitude = minAlt + (maxAlt - minAlt) * RandomUtils.nextDouble(); targetPosition.setLatitude(latitude); targetPosition.setLongitude(longitude); targetPosition.setAltitude(altitude); PolarCoordinate s = new PolarCoordinate(startPosition.getLatitude(), startPosition.getLongitude(), startPosition.getAltitude()); PolarCoordinate t = new PolarCoordinate(targetPosition.getLatitude(), targetPosition.getLongitude(), targetPosition.getAltitude()); cartesianStarPosition = geodeticSystem.polarToRectangularCoordinates(s); CartesianCoordinate target = geodeticSystem.polarToRectangularCoordinates(t); distanceVector = target.subtract(cartesianStarPosition); distance = distanceVector.norm(); endTime = startTime + (long) (1000 * distance / velocity); if (Math.abs(t.getLatitude() - s.getLatitude()) < 1E-6 && Math.abs(t.getLongitude() - s.getLongitude()) < 1E-6) { newHeading = 0; } else { newHeading = (float) Math.atan2( (s.getLongitude() - t.getLongitude()) * Math.cos(t.getLatitude() * PI180TH), t.getLatitude() - s.getLatitude()); if (newHeading < 0) { newHeading += 2 * Math.PI; } newHeading /= PI180TH; } } }