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:whitebox.stats.Kriging.java

/**
 * Calculates the bin values based on sector classification and for
 * AnIsotropic model/*  w  w w .  jav a2  s.  c o m*/
 *
 * @param Range
 * @param Angle
 * @param Tolerance
 * @param BandWidth
 */
void calcBins4Sec(double Range, double Angle, double Tolerance, double BandWidth) {
    int ad = 0;
    if (Range % this.LagSize == 0) {
        ad = 0;
    }
    double width = 0;

    if (this.Anisotropic) {

        bins = new bin[(int) Math.ceil(Range / this.LagSize) + ad][1];
        int r = 0;
        for (int i = 0; i < Pairs.size(); i++) {
            boolean tt = Between(Angle, Tolerance, Pairs.get(i).Direction);
            width = Pairs.get(i).Distance * Math.cos((Math.PI / 2) - Angle + Pairs.get(i).Direction);
            if (tt && Pairs.get(i).Distance < Range && Math.abs(width) <= BandWidth) {

                r = (int) Math.floor(Pairs.get(i).Distance / LagSize);
                if (bins[r][0] == null) {
                    bin bb = new bin();
                    bins[r][0] = bb;
                }

                bins[r][0].Distance += Pairs.get(i).Distance;
                bins[r][0].Value += Pairs.get(i).MomentI;
                bins[r][0].Size++;
            }
        }
        for (int i = 0; i < bins.length; i++) {
            if (bins[i][0] == null) {
                bin bb = new bin();
                bins[i][0] = bb;
            }
            bins[i][0].Distance = bins[i][0].Distance / bins[i][0].Size;
            bins[i][0].Value = bins[i][0].Value / bins[i][0].Size;
        }
    }
    //==========================

}

From source file:MyJava3D.java

public void setLightAngle(Vector3d angle) {
    this.lightAngle = angle;
    //System.out.println( "LightAngle: " + lightAngle );

    CT = Math.cos(DEG_TO_RAD * viewAngle.x);
    ST = Math.sin(DEG_TO_RAD * viewAngle.x);
    CP = Math.cos(DEG_TO_RAD * viewAngle.y);
    SP = Math.sin(DEG_TO_RAD * viewAngle.y);

    light.x = (float) (Math.sin(DEG_TO_RAD * lightAngle.y) * Math.cos(DEG_TO_RAD * lightAngle.x));
    light.y = (float) (Math.sin(DEG_TO_RAD * lightAngle.y) * Math.sin(DEG_TO_RAD * lightAngle.x));
    light.z = (float) (Math.cos(DEG_TO_RAD * lightAngle.y));
}

From source file:chat.client.agent.ChatClientAgent.java

public static float distance(float lat1, float lng1, float lat2, float lng2) {
    double earthRadius = 3958.75;
    double dLat = Math.toRadians(lat2 - lat1);
    double dLng = Math.toRadians(lng2 - lng1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1))
            * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double dist = earthRadius * c;

    int meterConversion = 1609;

    return new Float(dist * meterConversion).floatValue();
}

From source file:com.facebook.presto.operator.scalar.MathFunctions.java

@Description("cosine")
@ScalarFunction/*from  ww  w. j av  a 2  s.  co m*/
@SqlType(StandardTypes.DOUBLE)
public static double cos(@SqlType(StandardTypes.DOUBLE) double num) {
    return Math.cos(num);
}

From source file:com.irsa.OnTheGoActivity.java

private double gps2m(double lat_a, double lng_a, double lat_b, double lng_b) {
    double radLat1 = (lat_a * Math.PI / 180.0);
    double radLat2 = (lat_b * Math.PI / 180.0);
    double a = radLat1 - radLat2;
    double b = (lng_a - lng_b) * Math.PI / 180.0;
    double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
            + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
    s = s * EARTH_RADIUS;/* ww w  .j  a v  a 2s . c  om*/
    s = Math.round(s * 10000) / 10000;
    return s;

}

From source file:de.biomedical_imaging.ij.steger.Width.java

private void fix_locations(double[] width_l, double[] width_r, double[] grad_l, double[] grad_r, double[] pos_x,
        double[] pos_y, double[] correction, double[] contr, double[] asymm, double sigma, int mode,
        boolean correct_pos, Line cont) {
    int i;//from   w w w .ja  v  a  2  s.com
    int num_points;
    double px, py;
    double nx, ny;
    double w_est, r_est;
    MutableDouble w_real, h_real, corr;
    w_real = new MutableDouble();
    h_real = new MutableDouble();
    corr = new MutableDouble();
    MutableDouble w_strong = new MutableDouble();
    MutableDouble w_weak = new MutableDouble();
    double correct, asymmetry, response, width, contrast;
    boolean weak_is_r;
    boolean correct_start, correct_end;
    Convol convol = new Convol();
    fill_gaps(width_l, grad_l, null, cont);
    fill_gaps(width_r, grad_r, null, cont);

    num_points = cont.num;

    /* Calculate true line width, asymmetry, and position correction. */
    if (correct_pos) {
        /* Do not correct the position of a junction point if its width is found
           by interpolation, i.e., if the position could be corrected differently
           for each junction point, thereby destroying the junction. */
        correct_start = ((cont.getContourClass() == LinesUtil.contour_class.cont_no_junc
                || cont.getContourClass() == LinesUtil.contour_class.cont_end_junc
                || cont.getContourClass() == LinesUtil.contour_class.cont_closed)
                && (width_r[0] > 0 && width_l[0] > 0));
        correct_end = ((cont.getContourClass() == LinesUtil.contour_class.cont_no_junc
                || cont.getContourClass() == LinesUtil.contour_class.cont_start_junc
                || cont.getContourClass() == LinesUtil.contour_class.cont_closed)
                && (width_r[(num_points - 1)] > 0 && width_l[(num_points - 1)] > 0));
        /* Calculate the true width and assymetry, and its corresponding
           correction for each line point. */
        for (i = 0; i < num_points; i++) {
            if (width_r[i] > 0 && width_l[i] > 0) {
                w_est = (width_r[i] + width_l[i]) * LINE_WIDTH_COMPENSATION;
                if (grad_r[i] <= grad_l[i]) {
                    r_est = grad_r[i] / grad_l[i];
                    weak_is_r = true;
                } else {
                    r_est = grad_l[i] / grad_r[i];
                    weak_is_r = false;
                }
                Correct.line_corrections(sigma, w_est, r_est, w_real, h_real, corr, w_strong, w_weak);
                w_real.setValue(w_real.getValue() / LINE_WIDTH_COMPENSATION);
                corr.setValue(corr.getValue() / LINE_WIDTH_COMPENSATION);
                width_r[i] = w_real.getValue();
                width_l[i] = w_real.getValue();
                if (weak_is_r) {
                    asymm[i] = h_real.getValue();
                    correction[i] = -corr.getValue();
                } else {
                    asymm[i] = -h_real.getValue();
                    correction[i] = corr.getValue();
                }
            }
        }

        fill_gaps(width_l, correction, asymm, cont);
        for (i = 0; i < num_points; i++)
            width_r[i] = width_l[i];

        /* Adapt the correction for junction points if necessary. */
        if (!correct_start)
            correction[0] = 0;
        if (!correct_end)
            correction[(num_points - 1)] = 0;

        for (i = 0; i < num_points; i++) {
            px = pos_x[i];
            py = pos_y[i];
            nx = Math.cos(cont.angle[i]);
            ny = Math.sin(cont.angle[i]);
            px = px + correction[i] * nx;
            py = py + correction[i] * ny;
            pos_x[i] = px;
            pos_y[i] = py;
        }
    }

    /* Update the position of a line and add the extracted width. */
    cont.width_l = new float[num_points];
    cont.width_r = new float[num_points];
    for (i = 0; i < num_points; i++) {
        cont.width_l[i] = (float) width_l[i];
        cont.width_r[i] = (float) width_r[i];
        cont.row[i] = (float) pos_x[i];
        cont.col[i] = (float) pos_y[i];
    }

    /* Now calculate the true contrast. */
    if (correct_pos) {
        cont.asymmetry = new float[num_points];
        cont.intensity = new float[num_points];
        for (i = 0; i < num_points; i++) {
            response = cont.response[i];
            asymmetry = Math.abs(asymm[i]);
            correct = Math.abs(correction[i]);
            width = cont.width_l[i];
            if (width < MIN_LINE_WIDTH)
                contrast = 0;
            else
                contrast = (response / Math.abs(convol.phi2(correct + width, sigma)
                        + (asymmetry - 1) * convol.phi2(correct - width, sigma)));

            if (contrast > MAX_CONTRAST)
                contrast = 0;
            contr[i] = contrast;
        }
        fill_gaps(contr, null, null, cont);
        for (i = 0; i < num_points; i++) {
            cont.asymmetry[i] = (float) asymm[i];
            if (mode == LinesUtil.MODE_LIGHT)
                cont.intensity[i] = (float) contr[i];
            else
                cont.intensity[i] = (float) -contr[i];
        }
    }
}

From source file:es.emergya.geo.util.Lambert.java

/**
 * initializes from cartesian coordinates
 *
 * @param X/*w w w .java 2  s .c  om*/
 *            1st coordinate in meters
 * @param Y
 *            2nd coordinate in meters
 * @param Z
 *            3rd coordinate in meters
 * @param ell
 *            reference ellipsoid
 */
private LatLon Geographic(double X, double Y, double Z, Ellipsoid ell) {
    double norm = Math.sqrt(X * X + Y * Y);
    double lg = 2.0 * Math.atan(Y / (X + norm));
    double lt = Math.atan(Z / (norm * (1.0 - (ell.a * ell.e2 / Math.sqrt(X * X + Y * Y + Z * Z)))));
    double delta = 1.0;
    while (delta > epsilon) {
        double s2 = Math.sin(lt);
        s2 *= s2;
        double l = Math.atan(
                (Z / norm) / (1.0 - (ell.a * ell.e2 * Math.cos(lt) / (norm * Math.sqrt(1.0 - ell.e2 * s2)))));
        delta = Math.abs(l - lt);
        lt = l;
    }
    double s2 = Math.sin(lt);
    s2 *= s2;
    // h = norm / Math.cos(lt) - ell.a / Math.sqrt(1.0 - ell.e2 * s2);
    return new LatLon(lt, lg);
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.tree.NumberArithmetic.java

/**
 * Returns the trigonometric cosine of the number.
 * //from ww w. ja v a2 s.  c o  m
 * @param a the number
 * @return the trigonometric cosine of the number
 * @see Math#cos(double)
 */
public static Number cos(Number a) {
    return Math.cos(a.doubleValue());
}

From source file:HiResCoordTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    Transform3D t3dTilt = new Transform3D();
    t3dTilt.rotX(0.3);/*from   w  w  w  .  j  a v a 2 s  .  c  om*/

    TransformGroup objTrans = new TransformGroup(t3dTilt);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    TransformGroup objTransPlanets = new TransformGroup();
    objTransPlanets.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTransPlanets, yAxis, 0.0f,
            (float) Math.PI * 2.0f);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), m_TranslateSunZ);
    rotator.setSchedulingBounds(bounds);
    objTransPlanets.addChild(rotator);

    // create the sun
    TransformGroup sunTg = createSun();

    // create Earth
    Transform3D t3dEarth = new Transform3D();
    t3dEarth.setScale(m_EarthRadius);
    t3dEarth.setTranslation(new Vector3d(m_EarthOrbit, 0, 0));
    objTransPlanets.addChild(createPlanet("Earth", new Color3f(0, 0.1f, 1.0f), t3dEarth, null));

    // create Mars
    Transform3D t3dMars = new Transform3D();
    t3dMars.setTranslation(
            new Vector3d(Math.sin(Math.PI * 1.5) * m_MarsOrbit, 0, Math.cos(Math.PI * 0.5) * m_MarsOrbit));
    t3dMars.setScale(m_MarsRadius);
    objTransPlanets.addChild(createPlanet("Mars", new Color3f(1, 0, 0), t3dMars, null));

    // create Mercury
    Transform3D t3dMercury = new Transform3D();
    t3dMercury.setTranslation(
            new Vector3d(Math.sin(Math.PI) * m_MercuryOrbit, 0, Math.cos(Math.PI) * m_MercuryOrbit));
    t3dMercury.setScale(m_MercuryRadius);
    objTransPlanets.addChild(createPlanet("Mercury", new Color3f(0.5f, 0.5f, 0.5f), t3dMercury, null));

    sunTg.addChild(objTransPlanets);
    objTrans.addChild(sunTg);
    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:GearTest.java

void addBodyDisks(float shaftRadius, float bodyOuterRadius, float thickness, Appearance look) {
    int gearBodySegmentVertexCount; // #(segments) per tooth-unit
    int gearBodyTotalVertexCount; // #(vertices) in a gear face
    int gearBodyStripCount[] = new int[1]; // per strip (1) vertex count

    // A ray from the gear center, used in normal calculations
    float xDirection, yDirection;

    // The x and y coordinates at each point of a facet and at each
    // point on the gear: at the shaft, the root of the teeth, and
    // the outer point of the teeth
    float xRoot0, yRoot0, xShaft0, yShaft0;
    float xRoot3, yRoot3, xShaft3, yShaft3;
    float xRoot4, yRoot4, xShaft4, yShaft4;

    // Temporary variables for storing coordinates and vectors
    Point3f coordinate = new Point3f(0.0f, 0.0f, 0.0f);

    // Gear start differential angle. All gears are constructed with the
    // center of a tooth at Z-axis angle = 0.
    double gearStartAngle = -1.0 * toothTopCenterAngle;

    // Temporaries that store start angle for each portion of tooth facet
    double toothStartAngle, toothTopStartAngle, toothDeclineStartAngle, toothValleyStartAngle,
            nextToothStartAngle;/*from w  ww  . j a  v a2  s  . c o m*/

    Shape3D newShape;
    int index;

    // The z coordinates for the body disks
    final float frontZ = -0.5f * thickness;
    final float rearZ = 0.5f * thickness;

    /*
     * Construct the gear's front body (front facing torus disk) __2__ - | -
     * 4 - /| /- / / | /| \ 0\ / | / / > \ / | / | > \ / | / / | \ / ____|/ | >
     * \-- --__/ | 1 3 5
     *  
     */
    gearBodySegmentVertexCount = 4;
    gearBodyTotalVertexCount = 2 + gearBodySegmentVertexCount * toothCount;
    gearBodyStripCount[0] = gearBodyTotalVertexCount;

    TriangleStripArray frontGearBody = new TriangleStripArray(gearBodyTotalVertexCount,
            GeometryArray.COORDINATES | GeometryArray.NORMALS, gearBodyStripCount);

    xDirection = (float) Math.cos(gearStartAngle);
    yDirection = (float) Math.sin(gearStartAngle);
    xShaft0 = shaftRadius * xDirection;
    yShaft0 = shaftRadius * yDirection;
    xRoot0 = bodyOuterRadius * xDirection;
    yRoot0 = bodyOuterRadius * yDirection;

    coordinate.set(xRoot0, yRoot0, frontZ);
    frontGearBody.setCoordinate(0, coordinate);
    frontGearBody.setNormal(0, frontNormal);

    coordinate.set(xShaft0, yShaft0, frontZ);
    frontGearBody.setCoordinate(1, coordinate);
    frontGearBody.setNormal(1, frontNormal);

    for (int count = 0; count < toothCount; count++) {
        index = 2 + count * 4;
        toothStartAngle = gearStartAngle + circularPitchAngle * (double) count;
        toothValleyStartAngle = toothStartAngle + toothValleyAngleIncrement;
        nextToothStartAngle = toothStartAngle + circularPitchAngle;

        xDirection = (float) Math.cos(toothValleyStartAngle);
        yDirection = (float) Math.sin(toothValleyStartAngle);
        xShaft3 = shaftRadius * xDirection;
        yShaft3 = shaftRadius * yDirection;
        xRoot3 = bodyOuterRadius * xDirection;
        yRoot3 = bodyOuterRadius * yDirection;

        xDirection = (float) Math.cos(nextToothStartAngle);
        yDirection = (float) Math.sin(nextToothStartAngle);
        xShaft4 = shaftRadius * xDirection;
        yShaft4 = shaftRadius * yDirection;
        xRoot4 = bodyOuterRadius * xDirection;
        yRoot4 = bodyOuterRadius * yDirection;

        coordinate.set(xRoot3, yRoot3, frontZ);
        frontGearBody.setCoordinate(index, coordinate);
        frontGearBody.setNormal(index, frontNormal);

        coordinate.set(xShaft3, yShaft3, frontZ);
        frontGearBody.setCoordinate(index + 1, coordinate);
        frontGearBody.setNormal(index + 1, frontNormal);

        coordinate.set(xRoot4, yRoot4, frontZ);
        frontGearBody.setCoordinate(index + 2, coordinate);
        frontGearBody.setNormal(index + 2, frontNormal);

        coordinate.set(xShaft4, yShaft4, frontZ);
        frontGearBody.setCoordinate(index + 3, coordinate);
        frontGearBody.setNormal(index + 3, frontNormal);
    }
    newShape = new Shape3D(frontGearBody, look);
    this.addChild(newShape);

    // Construct the gear's rear body (rear facing torus disc)
    TriangleStripArray rearGearBody = new TriangleStripArray(gearBodyTotalVertexCount,
            GeometryArray.COORDINATES | GeometryArray.NORMALS, gearBodyStripCount);
    xDirection = (float) Math.cos(gearStartAngle);
    yDirection = (float) Math.sin(gearStartAngle);
    xShaft0 = shaftRadius * xDirection;
    yShaft0 = shaftRadius * yDirection;
    xRoot0 = bodyOuterRadius * xDirection;
    yRoot0 = bodyOuterRadius * yDirection;

    coordinate.set(xShaft0, yShaft0, rearZ);
    rearGearBody.setCoordinate(0, coordinate);
    rearGearBody.setNormal(0, rearNormal);

    coordinate.set(xRoot0, yRoot0, rearZ);
    rearGearBody.setCoordinate(1, coordinate);
    rearGearBody.setNormal(1, rearNormal);

    for (int count = 0; count < toothCount; count++) {
        index = 2 + count * 4;
        toothStartAngle = gearStartAngle + circularPitchAngle * (double) count;
        toothValleyStartAngle = toothStartAngle + toothValleyAngleIncrement;
        nextToothStartAngle = toothStartAngle + circularPitchAngle;

        xDirection = (float) Math.cos(toothValleyStartAngle);
        yDirection = (float) Math.sin(toothValleyStartAngle);
        xShaft3 = shaftRadius * xDirection;
        yShaft3 = shaftRadius * yDirection;
        xRoot3 = bodyOuterRadius * xDirection;
        yRoot3 = bodyOuterRadius * yDirection;

        xDirection = (float) Math.cos(nextToothStartAngle);
        yDirection = (float) Math.sin(nextToothStartAngle);
        xShaft4 = shaftRadius * xDirection;
        yShaft4 = shaftRadius * yDirection;
        xRoot4 = bodyOuterRadius * xDirection;
        yRoot4 = bodyOuterRadius * yDirection;

        coordinate.set(xShaft3, yShaft3, rearZ);
        rearGearBody.setCoordinate(index, coordinate);
        rearGearBody.setNormal(index, rearNormal);

        coordinate.set(xRoot3, yRoot3, rearZ);
        rearGearBody.setCoordinate(index + 1, coordinate);
        rearGearBody.setNormal(index + 1, rearNormal);

        coordinate.set(xShaft4, yShaft4, rearZ);
        rearGearBody.setCoordinate(index + 2, coordinate);
        rearGearBody.setNormal(index + 2, rearNormal);

        coordinate.set(xRoot4, yRoot4, rearZ);
        rearGearBody.setCoordinate(index + 3, coordinate);
        rearGearBody.setNormal(index + 3, rearNormal);

    }
    newShape = new Shape3D(rearGearBody, look);
    this.addChild(newShape);
}