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:com.opengamma.analytics.math.ComplexMathUtils.java

public static ComplexNumber pow(final ComplexNumber z1, final ComplexNumber z2) {
    ArgumentChecker.notNull(z1, "z1");
    ArgumentChecker.notNull(z2, "z2");
    final double mod = mod(z1);
    final double arg = arg(z1);
    final double mult = Math.pow(mod, z2.getReal()) * Math.exp(-z2.getImaginary() * arg);
    final double theta = z2.getReal() * arg + z2.getImaginary() * Math.log(mod);
    return new ComplexNumber(mult * Math.cos(theta), mult * Math.sin(theta));
}

From source file:de.romankreisel.faktotum.beans.BundesbruderBean.java

public void rotateProfilePictureClockwise(BundesbruderEntity bundesbruder, double angle) throws IOException {
    BufferedImage image = this.getImageFromByteArray(bundesbruder.getPictureOriginal());
    double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle));
    int w = image.getWidth(), h = image.getHeight();
    int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math.floor(h * cos + w * sin);
    GraphicsConfiguration gc = image.createGraphics().getDeviceConfiguration();
    BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.TRANSLUCENT);
    Graphics2D g = result.createGraphics();
    g.translate((neww - w) / 2, (newh - h) / 2);
    g.rotate(angle, w / 2, h / 2);/*w  w  w .ja v a  2  s .c  o  m*/
    g.drawRenderedImage(image, null);
    g.dispose();
    this.setProfilePicture(bundesbruder, this.storeImageToByteArray(image));
}

From source file:ExtendedGeneralPath.java

/**
 * This constructs an unrotated Arc2D from the SVG specification of an
 * Elliptical arc.  To get the final arc you need to apply a rotation
 * transform such as://from w  ww. j  a v  a  2  s .  c om
 *
 * AffineTransform.getRotateInstance
 *     (angle, arc.getX()+arc.getWidth()/2, arc.getY()+arc.getHeight()/2);
 */
public static Arc2D computeArc(double x0, double y0, double rx, double ry, double angle, boolean largeArcFlag,
        boolean sweepFlag, double x, double y) {
    //
    // Elliptical arc implementation based on the SVG specification notes
    //

    // Compute the half distance between the current and the final point
    double dx2 = (x0 - x) / 2.0;
    double dy2 = (y0 - y) / 2.0;
    // Convert angle from degrees to radians
    angle = Math.toRadians(angle % 360.0);
    double cosAngle = Math.cos(angle);
    double sinAngle = Math.sin(angle);

    //
    // Step 1 : Compute (x1, y1)
    //
    double x1 = (cosAngle * dx2 + sinAngle * dy2);
    double y1 = (-sinAngle * dx2 + cosAngle * dy2);
    // Ensure radii are large enough
    rx = Math.abs(rx);
    ry = Math.abs(ry);
    double Prx = rx * rx;
    double Pry = ry * ry;
    double Px1 = x1 * x1;
    double Py1 = y1 * y1;
    // check that radii are large enough
    double radiiCheck = Px1 / Prx + Py1 / Pry;
    if (radiiCheck > 1) {
        rx = Math.sqrt(radiiCheck) * rx;
        ry = Math.sqrt(radiiCheck) * ry;
        Prx = rx * rx;
        Pry = ry * ry;
    }

    //
    // Step 2 : Compute (cx1, cy1)
    //
    double sign = (largeArcFlag == sweepFlag) ? -1 : 1;
    double sq = ((Prx * Pry) - (Prx * Py1) - (Pry * Px1)) / ((Prx * Py1) + (Pry * Px1));
    sq = (sq < 0) ? 0 : sq;
    double coef = (sign * Math.sqrt(sq));
    double cx1 = coef * ((rx * y1) / ry);
    double cy1 = coef * -((ry * x1) / rx);

    //
    // Step 3 : Compute (cx, cy) from (cx1, cy1)
    //
    double sx2 = (x0 + x) / 2.0;
    double sy2 = (y0 + y) / 2.0;
    double cx = sx2 + (cosAngle * cx1 - sinAngle * cy1);
    double cy = sy2 + (sinAngle * cx1 + cosAngle * cy1);

    //
    // Step 4 : Compute the angleStart (angle1) and the angleExtent (dangle)
    //
    double ux = (x1 - cx1) / rx;
    double uy = (y1 - cy1) / ry;
    double vx = (-x1 - cx1) / rx;
    double vy = (-y1 - cy1) / ry;
    double p, n;
    // Compute the angle start
    n = Math.sqrt((ux * ux) + (uy * uy));
    p = ux; // (1 * ux) + (0 * uy)
    sign = (uy < 0) ? -1.0 : 1.0;
    double angleStart = Math.toDegrees(sign * Math.acos(p / n));

    // Compute the angle extent
    n = Math.sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy));
    p = ux * vx + uy * vy;
    sign = (ux * vy - uy * vx < 0) ? -1.0 : 1.0;
    double angleExtent = Math.toDegrees(sign * Math.acos(p / n));
    if (!sweepFlag && angleExtent > 0) {
        angleExtent -= 360f;
    } else if (sweepFlag && angleExtent < 0) {
        angleExtent += 360f;
    }
    angleExtent %= 360f;
    angleStart %= 360f;

    //
    // We can now build the resulting Arc2D in double precision
    //
    Arc2D.Double arc = new Arc2D.Double();
    arc.x = cx - rx;
    arc.y = cy - ry;
    arc.width = rx * 2.0;
    arc.height = ry * 2.0;
    arc.start = -angleStart;
    arc.extent = -angleExtent;

    return arc;
}

From source file:ddf.catalog.transformer.OverlayMetacardTransformer.java

private static Vector scaleByLatitude(Vector v, double lat) {
    double lon = v.get(0) * Math.cos(Math.toRadians(lat));
    return new BasicVector(new double[] { lon, v.get(1) });
}

From source file:edu.stanford.slac.archiverappliance.PB.data.BoundaryConditionsSimulationValueGenerator.java

/**
 * Get a value based on the DBR type. /*from  w  w w .j  av a  2  s  .c o m*/
 * We should check for boundary conditions here and make sure PB does not throw exceptions when we come close to MIN_ and MAX_ values 
 * @param type
 * @param secondsIntoYear
 * @return
 */
public SampleValue getSampleValue(ArchDBRTypes type, int secondsIntoYear) {
    switch (type) {
    case DBR_SCALAR_STRING:
        return new ScalarStringSampleValue(Integer.toString(secondsIntoYear));
    case DBR_SCALAR_SHORT:
        if (0 <= secondsIntoYear && secondsIntoYear < 1000) {
            // Check for some numbers around the minimum value
            return new ScalarValue<Short>((short) (Short.MIN_VALUE + secondsIntoYear));
        } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) {
            // Check for some numbers around the maximum value
            return new ScalarValue<Short>((short) (Short.MAX_VALUE - (secondsIntoYear - 1000)));
        } else {
            // Check for some numbers around 0
            return new ScalarValue<Short>((short) (secondsIntoYear - 2000));
        }
    case DBR_SCALAR_FLOAT:
        if (0 <= secondsIntoYear && secondsIntoYear < 1000) {
            // Check for some numbers around the minimum value
            return new ScalarValue<Float>(Float.MIN_VALUE + secondsIntoYear);
        } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) {
            // Check for some numbers around the maximum value
            return new ScalarValue<Float>(Float.MAX_VALUE - (secondsIntoYear - 1000));
        } else {
            // Check for some numbers around 0. Divide by a large number to make sure we cater to the number of precision digits
            return new ScalarValue<Float>((secondsIntoYear - 2000.0f) / secondsIntoYear);
        }
    case DBR_SCALAR_ENUM:
        return new ScalarValue<Short>((short) secondsIntoYear);
    case DBR_SCALAR_BYTE:
        return new ScalarValue<Byte>(((byte) (secondsIntoYear % 255)));
    case DBR_SCALAR_INT:
        if (0 <= secondsIntoYear && secondsIntoYear < 1000) {
            // Check for some numbers around the minimum value
            return new ScalarValue<Integer>(Integer.MIN_VALUE + secondsIntoYear);
        } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) {
            // Check for some numbers around the maximum value
            return new ScalarValue<Integer>(Integer.MAX_VALUE - (secondsIntoYear - 1000));
        } else {
            // Check for some numbers around 0
            return new ScalarValue<Integer>(secondsIntoYear - 2000);
        }
    case DBR_SCALAR_DOUBLE:
        if (0 <= secondsIntoYear && secondsIntoYear < 1000) {
            // Check for some numbers around the minimum value
            return new ScalarValue<Double>(Double.MIN_VALUE + secondsIntoYear);
        } else if (1000 <= secondsIntoYear && secondsIntoYear < 2000) {
            // Check for some numbers around the maximum value
            return new ScalarValue<Double>(Double.MAX_VALUE - (secondsIntoYear - 1000));
        } else {
            // Check for some numbers around 0. Divide by a large number to make sure we cater to the number of precision digits
            return new ScalarValue<Double>((secondsIntoYear - 2000.0) / (secondsIntoYear * 1000000));
        }
    case DBR_WAVEFORM_STRING:
        // Varying number of copies of a typical value
        return new VectorStringSampleValue(
                Collections.nCopies(secondsIntoYear, Integer.toString(secondsIntoYear)));
    case DBR_WAVEFORM_SHORT:
        return new VectorValue<Short>(Collections.nCopies(1, (short) secondsIntoYear));
    case DBR_WAVEFORM_FLOAT:
        // Varying number of copies of a typical value
        return new VectorValue<Float>(
                Collections.nCopies(secondsIntoYear, (float) Math.cos(secondsIntoYear * Math.PI / 3600)));
    case DBR_WAVEFORM_ENUM:
        return new VectorValue<Short>(Collections.nCopies(1024, (short) secondsIntoYear));
    case DBR_WAVEFORM_BYTE:
        // Large number of elements in the array
        return new VectorValue<Byte>(
                Collections.nCopies(65536 * secondsIntoYear, ((byte) (secondsIntoYear % 255))));
    case DBR_WAVEFORM_INT:
        // Varying number of copies of a typical value
        return new VectorValue<Integer>(
                Collections.nCopies(secondsIntoYear, secondsIntoYear * secondsIntoYear));
    case DBR_WAVEFORM_DOUBLE:
        // Varying number of copies of a typical value
        return new VectorValue<Double>(
                Collections.nCopies(secondsIntoYear, Math.sin(secondsIntoYear * Math.PI / 3600)));
    case DBR_V4_GENERIC_BYTES:
        // Varying number of copies of a typical value
        ByteBuffer buf = ByteBuffer.allocate(1024 * 10);
        buf.put(Integer.toString(secondsIntoYear).getBytes());
        buf.flip();
        return new ByteBufSampleValue(buf);
    default:
        throw new RuntimeException("We seemed to have missed a DBR type when generating sample data");
    }
}

From source file:com.inc.playground.playground.utils.NetworkUtilities.java

public static Double calculateDistance(double lon1, double lat1, double lon2, double lat2) {
    //calculate air distance
    double R = 6371; // Radius of the earth in km
    double dLat = deg2rad(lat2 - lat1); // deg2rad below
    double dLon = deg2rad(lon2 - lon1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
            + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double d = R * c; // Distance in km
    return Math.round(d * 10d) / 10d; //round 1 point after digit
}

From source file:blue.soundObject.jmask.Oscillator.java

private double cos(double phpt) {
    return Math.cos(PI2 * phpt) * 0.5 + 0.5;
}

From source file:jat.core.cm.TwoBodyAPL.java

public double[] randv(double ta) {
    double p = a * (1.0 - e * e);
    double cta = Math.cos(ta);
    double sta = Math.sin(ta);
    double opecta = 1.0 + e * cta;
    double sqmuop = Math.sqrt(this.mu / p);

    VectorN xpqw = new VectorN(6);
    xpqw.x[0] = p * cta / opecta;//  w w w .  j  a v  a 2s . com
    xpqw.x[1] = p * sta / opecta;
    xpqw.x[2] = 0.0;
    xpqw.x[3] = -sqmuop * sta;
    xpqw.x[4] = sqmuop * (e + cta);
    xpqw.x[5] = 0.0;

    Matrix cmat = PQW2ECI();

    VectorN rpqw = new VectorN(xpqw.x[0], xpqw.x[1], xpqw.x[2]);
    VectorN vpqw = new VectorN(xpqw.x[3], xpqw.x[4], xpqw.x[5]);

    VectorN rijk = cmat.times(rpqw);
    VectorN vijk = cmat.times(vpqw);

    double[] out = new double[6];

    for (int i = 0; i < 3; i++) {
        out[i] = rijk.x[i];
        out[i + 3] = vijk.x[i];
    }

    return out;
}

From source file:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java

public static Number funcExp(MutableNumber out, Number x) {
    double d = Math.exp(x.r());
    return out.set(d * Math.cos(x.i()), d * Math.sin(x.i()));
}

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

public static ComplexNumber pow(final ComplexNumber z, final double x) {
    final double mod = mod(z);
    final double arg = arg(z);
    final double mult = Math.pow(mod, x);
    return new ComplexNumber(mult * Math.cos(x * arg), mult * Math.sin(x * arg));
}