Example usage for java.lang Math cos

List of usage examples for java.lang Math cos

Introduction

In this page you can find the example usage for java.lang Math cos.

Prototype

@HotSpotIntrinsicCandidate
public static double cos(double a) 

Source Link

Document

Returns the trigonometric cosine of an angle.

Usage

From source file:gdsc.smlm.function.gaussian.SingleFreeCircularGaussian2DFunction.java

public void initialise(double[] a) {
    background = a[BACKGROUND];/*  w w  w.  j  ava  2  s . c  om*/
    x0pos = a[X_POSITION];
    x1pos = a[Y_POSITION];

    // Precalculate multiplication factors
    final double theta = a[ANGLE];
    final double sx = a[X_SD];
    final double sy = a[Y_SD];
    final double sx2 = sx * sx;
    final double sy2 = sy * sy;
    final double sx3 = sx2 * sx;
    final double sy3 = sy2 * sy;
    final double cosSqt = Math.cos(theta) * Math.cos(theta);
    final double sinSqt = Math.sin(theta) * Math.sin(theta);
    final double sin2t = Math.sin(2 * theta);

    n = ONE_OVER_TWO_PI / (sx * sy);
    height = a[SIGNAL] * n;

    // All prefactors are negated since the Gaussian uses the exponential to the negative:
    // (A/2*pi*sx*sy) * exp( -( a(x-x0)^2 + 2b(x-x0)(y-y0) + c(y-y0)^2 ) )

    aa = -0.5 * (cosSqt / sx2 + sinSqt / sy2);
    bb = -0.25 * (-sin2t / sx2 + sin2t / sy2);
    cc = -0.5 * (sinSqt / sx2 + cosSqt / sy2);

    // For the x-width gradient
    nx = -1 / sx;
    ax = cosSqt / sx3;
    bx = -0.5 * sin2t / sx3;
    cx = sinSqt / sx3;

    // For the y-width gradient
    ny = -1 / sy;
    ay = sinSqt / sy3;
    by = 0.5 * sin2t / sy3;
    cy = cosSqt / sy3;
}

From source file:org.eclipse.swt.examples.graphics.CardsTab.java

@Override
public void next(int width, int height) {
    rotationAngle = (rotationAngle + 10) % 360;

    // scaleVal goes from 0 to 1, then 1 to 0, then starts over
    scaleArg = (float) ((scaleArg == 1) ? scaleArg - 0.1 : scaleArg + 0.1);
    scale = (float) Math.cos(scaleArg);

    movClubX += inc_club;//from   w ww .j  a va 2  s. c  om
    movDiamondX += inc_diamond;
    movHeart += inc_hearts;
    movSpade += inc_spade;

    scaleWidth = (float) ((movClubY / height) * 0.35 + 0.15);
    movClubY = 2 * height / 5 * (float) Math.sin(0.01 * movClubX - 90) + 2 * height / 5;
    movDiamondY = 2 * height / 5 * (float) Math.cos(0.01 * movDiamondX) + 2 * height / 5;

    if (movClubX + clubWidth * scaleWidth > width) {
        movClubX = width - clubWidth * scaleWidth;
        inc_club = -inc_club;
    }
    if (movClubX < 0) {
        movClubX = 0;
        inc_club = -inc_club;
    }
    if (movDiamondX + diamondWidth * scaleWidth > width) {
        movDiamondX = width - diamondWidth * scaleWidth;
        inc_diamond = -inc_diamond;
    }
    if (movDiamondX < 0) {
        movDiamondX = 0;
        inc_diamond = -inc_diamond;
    }
    if (movHeart + heartWidth * heartScale > width) {
        movHeart = width - heartWidth * heartScale;
        inc_hearts = -inc_hearts;
    }
    if (movHeart < 0) {
        movHeart = 0;
        inc_hearts = -inc_hearts;
    }
    if (movSpade + spadeHeight * spadeScale > height) {
        movSpade = height - spadeHeight * spadeScale;
        inc_spade = -inc_spade;
    }
    if (movSpade < 0) {
        movSpade = 0;
        inc_spade = -inc_spade;
    }
}

From source file:Main.java

/**
 * Creates a region surrounding a line segment by 'widening' the line
 * segment.  A typical use for this method is the creation of a
 * 'clickable' region for a line that is displayed on-screen.
 *
 * @param line  the line (<code>null</code> not permitted).
 * @param width  the width of the region.
 *
 * @return A region that surrounds the line.
 *//*from  w  ww.ja va  2 s .  c  o  m*/
public static Shape createLineRegion(final Line2D line, final float width) {
    final GeneralPath result = new GeneralPath();
    final float x1 = (float) line.getX1();
    final float x2 = (float) line.getX2();
    final float y1 = (float) line.getY1();
    final float y2 = (float) line.getY2();
    if ((x2 - x1) != 0.0) {
        final double theta = Math.atan((y2 - y1) / (x2 - x1));
        final float dx = (float) Math.sin(theta) * width;
        final float dy = (float) Math.cos(theta) * width;
        result.moveTo(x1 - dx, y1 + dy);
        result.lineTo(x1 + dx, y1 - dy);
        result.lineTo(x2 + dx, y2 - dy);
        result.lineTo(x2 - dx, y2 + dy);
        result.closePath();
    } else {
        // special case, vertical line
        result.moveTo(x1 - width / 2.0f, y1);
        result.lineTo(x1 + width / 2.0f, y1);
        result.lineTo(x2 + width / 2.0f, y2);
        result.lineTo(x2 - width / 2.0f, y2);
        result.closePath();
    }
    return result;
}

From source file:frk.gpssimulator.support.NavUtils.java

/**
 * Returns coordinates of position which is given distance and bearing from given point.
 * @param pt1//from  ww  w  .  ja va  2  s  .c o m
 * @param dist
 * @param brg
 * @return
 */
public static Point getPosition(Point pt1, double d, double brg) {
    if (Double.doubleToRawLongBits(d) == 0) {
        return pt1;
    }

    double lat1 = Math.toRadians(pt1.getLatitude());
    double lon1 = Math.toRadians(pt1.getLongitude());
    double brgAsRadians = Math.toRadians(brg);

    double lat2 = Math.asin(Math.sin(lat1) * Math.cos(d / EARTH_RADIUS_IN_METERS)
            + Math.cos(lat1) * Math.sin(d / EARTH_RADIUS_IN_METERS) * Math.cos(brgAsRadians));
    double x = Math.sin(brgAsRadians) * Math.sin(d / EARTH_RADIUS_IN_METERS) * Math.cos(lat1);
    double y = Math.cos(d / EARTH_RADIUS_IN_METERS) - Math.sin(lat1) * Math.sin(lat2);
    double lon2 = lon1 + Math.atan2(x, y);

    return new Point(Math.toDegrees(lat2), Math.toDegrees(lon2), null);

}

From source file:gdsc.smlm.function.gaussian.SingleEllipticalGaussian2DFunction.java

public void initialise(double[] a) {
    background = a[BACKGROUND];//from w  w w . j a va2  s.com
    x0pos = a[X_POSITION];
    x1pos = a[Y_POSITION];

    // Precalculate multiplication factors
    final double theta = a[ANGLE];
    final double sx = a[X_SD];
    final double sy = a[Y_SD];
    final double sx2 = sx * sx;
    final double sy2 = sy * sy;
    final double sx3 = sx2 * sx;
    final double sy3 = sy2 * sy;
    final double cosSqt = Math.cos(theta) * Math.cos(theta);
    final double sinSqt = Math.sin(theta) * Math.sin(theta);
    final double sincost = Math.sin(theta) * Math.cos(theta);
    final double sin2t = Math.sin(2 * theta);
    final double cos2t = Math.cos(2 * theta);

    n = ONE_OVER_TWO_PI / (sx * sy);
    height = a[SIGNAL] * n;

    // All prefactors are negated since the Gaussian uses the exponential to the negative:
    // (A/2*pi*sx*sy) * exp( -( a(x-x0)^2 + 2b(x-x0)(y-y0) + c(y-y0)^2 ) )

    aa = -0.5 * (cosSqt / sx2 + sinSqt / sy2);
    bb = -0.25 * (-sin2t / sx2 + sin2t / sy2);
    cc = -0.5 * (sinSqt / sx2 + cosSqt / sy2);

    // For the angle gradient
    aa2 = -(-sincost / sx2 + sincost / sy2);
    bb2 = -0.5 * (-cos2t / sx2 + cos2t / sy2);
    cc2 = -(sincost / sx2 - sincost / sy2);

    // For the x-width gradient
    nx = -1 / sx;
    ax = cosSqt / sx3;
    bx = -0.5 * sin2t / sx3;
    cx = sinSqt / sx3;

    // For the y-width gradient
    ny = -1 / sy;
    ay = sinSqt / sy3;
    by = 0.5 * sin2t / sy3;
    cy = cosSqt / sy3;
}

From source file:es.udc.gii.common.eaf.benchmark.multiobjective.dtlz2.R_Dtlz2_Objective.java

@Override
public double evaluate(double[] x) {

    int nx = x.length;

    int i = 0, j = 0;
    int k = nx - numberOfObjectives + 1;
    double g = 0;

    double[] z = new double[nx];
    double[] zz = new double[nx];
    double[] p = new double[nx];
    double[] psum = new double[numberOfObjectives];

    // denormalize vector:
    for (i = 0; i < nx; i++) {
        x[i] = (bounds[1][i] - bounds[0][i]) / 2 * x[i] + (bounds[1][i] + bounds[0][i]) / 2;
    }//  ww  w  .  j ava 2s.c  o  m

    for (i = 0; i < nx; i++) {
        z[i] = 0;
        for (j = 0; j < nx; j++) {
            z[i] += M[i][j] * x[j];
        }
        if (z[i] >= 0 && z[i] <= 1) {
            zz[i] = z[i];
            p[i] = 0;
        } else if (z[i] < 0) {
            zz[i] = -lambda[i] * z[i];
            p[i] = -z[i];
        } else {
            zz[i] = 1 - lambda[i] * (z[i] - 1);
            p[i] = z[i] - 1;
        }
    }

    for (j = 0; j < numberOfObjectives; j++) {
        psum[j] = 0;
    }

    for (i = nx - k + 1; i <= nx; i++) {
        g += Math.pow(zz[i - 1] - 0.5, 2) - Math.cos(20 * Math.PI * (zz[i - 1] - 0.5));
        for (j = 0; j < numberOfObjectives; j++) {
            psum[j] = Math.sqrt(Math.pow(psum[j], 2) + Math.pow(p[i - 1], 2));
        }
    }

    g = 100 * (k + g);

    double ff = (1 + g);

    for (j = numberOfObjectives - objNumber; j >= 1; j--) {
        ff *= Math.cos(zz[j - 1] * Math.PI / 2.0);
        psum[objNumber - 1] = Math.sqrt(Math.pow(psum[objNumber - 1], 2) + Math.pow(p[j - 1], 2));
    }

    if (objNumber > 1) {
        ff *= Math.sin(zz[(numberOfObjectives - objNumber + 1) - 1] * Math.PI / 2.0);
        psum[objNumber - 1] = Math.sqrt(
                Math.pow(psum[objNumber - 1], 2) + Math.pow(p[(numberOfObjectives - objNumber + 1) - 1], 2));
    }

    return 2.0 / (1 + Math.exp(-psum[objNumber - 1])) * (ff + 1);
}

From source file:at.uni_salzburg.cs.ros.artificer.LocationData.java

/**
 * @param configuration configuration//from   www  .ja  va 2 s  . c  o  m
 * @param location location
 */
public LocationData(Configuration configuration, Location location) {
    clock = configuration.getClock();
    this.location = location;
    simDetails = configuration.getLocationSimulationDetails();
    velocity = simDetails.get(location.getLocationId()).getAverageSpeed();
    mutation = simDetails.get(location.getLocationId()).getMutationSpeed();

    minLatitude = simDetails.get(location.getLocationId()).getMinLatitude();
    maxLatitude = simDetails.get(location.getLocationId()).getMaxLatitude();
    minLongitude = simDetails.get(location.getLocationId()).getMinLongitude();
    maxLongitude = simDetails.get(location.getLocationId()).getMaxLongitude();

    moving = Math.abs(velocity) > 1E-6 || Math.abs(mutation) > 1E-4;
    heading = RandomUtils.nextDouble() * 2.0 * Math.PI;
    headingSouth = Math.sin(heading) * velocity;
    headingEast = Math.cos(heading) * velocity;
}

From source file:es.udc.gii.common.eaf.benchmark.multiobjective.dtlz2.S_Dtlz2_Objective.java

@Override
public double evaluate(double[] x) {
    int nx = x.length;

    int i = 0;/*from  www.  j  a  va 2 s  . com*/
    int j = 0;
    int k = nx - numberOfObjectives + 1;
    double g = 0;
    double[] z = new double[nx];
    double[] zz = new double[nx];
    double[] p = new double[nx];
    double[] psum = new double[numberOfObjectives];

    // denormalize vector:
    for (i = 0; i < nx; i++) {
        x[i] = (bounds[1][i] - bounds[0][i]) / 2 * x[i] + (bounds[1][i] + bounds[0][i]) / 2;
    }

    for (i = 0; i < nx; i++) {
        z[i] = x[i] - o[i];

        if (z[i] < 0) {
            zz[i] = -lambda[i] * z[i];
            p[i] = -z[i] / d[i];
        } else {
            zz[i] = z[i];
            p[i] = 0;
        }
    }

    for (j = 0; j < numberOfObjectives; j++) {
        psum[j] = 0;
    }

    for (i = nx - k + 1; i <= nx; i++) {
        g += Math.pow(zz[i - 1] - 0.5, 2);
        for (j = 0; j < numberOfObjectives; j++) {
            psum[j] = Math.sqrt(Math.pow(psum[j], 2) + Math.pow(p[i - 1], 2));
        }
    }

    double ff = (1 + g);

    for (j = numberOfObjectives - objNumber; j >= 1; j--) {
        ff *= Math.cos(zz[j - 1] * Math.PI / 2.0);
        psum[objNumber - 1] = Math.sqrt(Math.pow(psum[objNumber - 1], 2) + Math.pow(p[j - 1], 2));
    }

    if (objNumber > 1) {
        ff *= Math.sin(zz[(numberOfObjectives - objNumber + 1) - 1] * Math.PI / 2.0);
        psum[objNumber - 1] = Math.sqrt(
                Math.pow(psum[objNumber - 1], 2) + Math.pow(p[(numberOfObjectives - objNumber + 1) - 1], 2));
    }

    return 2.0 / (1 + Math.exp(-psum[objNumber - 1])) * (ff + 1);
}

From source file:com.opengamma.analytics.math.TrigonometricFunctionUtils.java

public static ComplexNumber cos(final ComplexNumber z) {
    Validate.notNull(z, "z");
    final double x = z.getReal();
    final double y = z.getImaginary();
    return new ComplexNumber(Math.cos(x) * Math.cosh(y), -Math.sin(x) * Math.sinh(y));
}

From source file:com.griddynamics.jagger.reporting.LatencyPlotReportProvider.java

private JFreeChart createChart(String title) {

    if (false) {/*from  ww w  .  j  a va 2  s  . c  o m*/
        Map<Date, Double> s1 = new HashMap<Date, Double>();
        Map<Date, Double> s2 = new HashMap<Date, Double>();
        long time = System.currentTimeMillis();
        for (int i = 0; i < 100; i++) {
            s1.put(new Date(time + i * 1000), Math.sin(i / 10.0));
            s2.put(new Date(time + i * 1000), Math.cos(i / 5.0));
        }
        ChartHelper.TimeSeriesChartSpecification spec1 = new ChartHelper.TimeSeriesChartSpecification();
        spec1.setData(s1);
        spec1.setLabel("Latency 1");
        ChartHelper.TimeSeriesChartSpecification spec2 = new ChartHelper.TimeSeriesChartSpecification();
        spec2.setData(s2);
        spec2.setLabel("Latency 2");

        return ChartHelper.createTimeSeriesChart(title, Arrays.asList(spec1, spec2), "Time", "Latency",
                ChartHelper.ColorTheme.LIGHT);
    }

    if (false) {

        List<List<Double>> data = getBarData();
        List<String> zoneLabels = new ArrayList<String>();
        for (int i = 0; i < 16; i++) {
            zoneLabels.add(i + "%");
        }
        JFreeChart chart = ChartHelper.createStackedBarChart(title, data, zoneLabels, "Time", "Latency",
                ChartHelper.ColorTheme.DARK);

        return chart;
    }

    if (true) {
        XYSeriesCollection areas = getSeriesCollection(16);
        XYSeriesCollection lines = getSeriesCollection(2);
        JFreeChart chart = ChartHelper.createStackedAreaChart(title, areas, lines, "Time", "Latency",
                ChartHelper.ColorTheme.LIGHT);

        return chart;
    }

    return null;
}