Example usage for java.lang Math atan

List of usage examples for java.lang Math atan

Introduction

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

Prototype

public static double atan(double a) 

Source Link

Document

Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2.

Usage

From source file:org.lightjason.agentspeak.action.builtin.TestCActionMath.java

/**
 * data provider generator for single-value tests
 * @return data/*from  w  w w  . j a  va  2 s .co  m*/
 */
@DataProvider
public static Object[] singlevaluegenerate() {
    return Stream.concat(

            singlevaluetestcase(

                    Stream.of(2.5, 9.1, 111.7, 889.9),

                    Stream.of(CNextPrime.class),

                    (i) -> (double) Primes.nextPrime(i.intValue())),

            singlevaluetestcase(

                    Stream.of(-2, -6, 4, -1, -5, 3, 49, 30, 6, 5, 1.3, 2.8, 9.7, 1, 8, 180, Math.PI),

                    Stream.of(CAbs.class, CACos.class, CASin.class, CATan.class, CCeil.class, CCos.class,
                            CCosh.class, CDegrees.class, CExp.class, CIsPrime.class, CLog.class, CLog10.class,
                            CFloor.class, CRadians.class, CRound.class, CSignum.class, CSin.class, CSinh.class,
                            CSqrt.class, CTan.class, CTanh.class),

                    (i) -> Math.abs(i.doubleValue()), (i) -> Math.acos(i.doubleValue()),
                    (i) -> Math.asin(i.doubleValue()), (i) -> Math.atan(i.doubleValue()),
                    (i) -> Math.ceil(i.doubleValue()), (i) -> Math.cos(i.doubleValue()),
                    (i) -> Math.cosh(i.doubleValue()), (i) -> Math.toDegrees(i.doubleValue()),
                    (i) -> Math.exp(i.doubleValue()), (i) -> Primes.isPrime(i.intValue()),
                    (i) -> Math.log(i.doubleValue()), (i) -> Math.log10(i.doubleValue()),
                    (i) -> Math.floor(i.doubleValue()), (i) -> Math.toRadians(i.doubleValue()),
                    (i) -> Math.round(i.doubleValue()), (i) -> Math.signum(i.doubleValue()),
                    (i) -> Math.sin(i.doubleValue()), (i) -> Math.sinh(i.doubleValue()),
                    (i) -> Math.sqrt(i.doubleValue()), (i) -> Math.tan(i.doubleValue()),
                    (i) -> Math.tanh(i.doubleValue()))

    ).toArray();
}

From source file:edu.umich.eecs.tac.viewer.role.advertiser.CampaignGrpahsPanel.java

private double calcEffectiveReachRatio(double currentReach, double expectedReach) {
    return 2 / ERR_A * (Math.atan(ERR_A * currentReach / expectedReach - ERR_B) - Math.atan(-ERR_B));
}

From source file:org.cirdles.geoapp.LatLongToUTM.java

private static BigDecimal calcConformalLatitude(BigDecimal eccentricity, BigDecimal latitudeRadians) {

    BigDecimal conformalLatitude;

    double latRadDouble = latitudeRadians.doubleValue();
    double eccDouble = eccentricity.doubleValue();
    double confLatDouble;

    Atanh atanh = new Atanh();
    Asinh asinh = new Asinh();

    confLatDouble = Math.atan(Math.sinh(
            asinh.value(Math.tan(latRadDouble)) - eccDouble * atanh.value(eccDouble * Math.sin(latRadDouble))));

    conformalLatitude = new BigDecimal(confLatDouble);

    return conformalLatitude;

}

From source file:org.knowrob.vis.model.util.algorithm.ACCUM.java

/**
 * Calculate hue and saturation for curvature properties.
 * /*  w  w w  . j  av a  2s  .c om*/
 * @param curvatures
 *            maps curvatures to vertices
 * @param smoothSigma
 *            sigma value for smoothing the curvature. Set to 0 to disable smoothing.
 * @param m
 *            model needed to calculate hue saturation scale
 */
public static void setCurvatureHueSaturation(HashMap<Vertex, Curvature> curvatures, Model m,
        float smoothSigma) {
    if (smoothSigma > 0.0f) {
        float scaledSigma = smoothSigma * m.feature_size();
        diffuse_curv(m, curvatures, scaledSigma);
    }

    float cscale = 120.0f * typical_scale(curvatures, m);
    cscale = cscale * cscale;
    int nv = m.getVertices().size();
    for (int i = 0; i < nv; i++) {
        Curvature c = curvatures.get(m.getVertices().get(i));
        float H = 0.5f * (c.getCurvatureMax() + c.getCurvatureMin());
        // mean curvature -> don't set the mean curvature here as we want only the initial one to be stored and this method is public
        float K = c.getCurvatureMax() * c.getCurvatureMin();
        // Gaussian curvature -> don't set the Gaussian curvature here as we want only the initial one to be stored and this method is public
        float h = (float) (4.0f / 3.0f * Math.abs(Math.atan2(H * H - K, H * H * Math.signum(H))));
        float s = (float) ((2 / Math.PI) * Math.atan((2.0f * H * H - K) * cscale));
        c.setHue(h);
        c.setSaturation(s);
    }
}

From source file:com.compomics.cell_coord.computation.impl.TrackOperatorImpl.java

@Override
public void computeAngles(Track track) {
    Double[][] steps = track.getSteps();
    Double[] angles = new Double[steps.length];
    for (int row = 0; row < angles.length; row++) {
        // This method computes the phase theta by computing an arc tangent of y/x in the range of -pi to pi.
        double d = steps[row][1] / steps[row][0]; // if division is 0, the cell is going exactly back on its path!
        Double angleRadians = Math.atan(d) + 0; // need to add 0 to avoid signed 0 in Java
        // go from radians to degrees
        Double angleDegrees = Math.toDegrees(angleRadians);
        // if the angle is NaN (both deltaX and deltaY are zero), the cell stays exactly on place 
        if (angleDegrees < 0) {
            angleDegrees = angleDegrees + 360;
        }/*from ww  w .j  av  a  2s. co  m*/
        angles[row] = angleDegrees;
    }
    track.setAngles(angles);
}

From source file:org.renjin.primitives.MathGroup.java

@Deferrable
@Builtin//from  w  w w .  j  ava2s  . c om
@DataParallel(value = PreserveAttributeStyle.ALL, passNA = true)
public static double atan(double x) {
    return Math.atan(x);
}

From source file:gr.iit.demokritos.cru.cps.ai.ProfileMerger.java

public ArrayList<Double> CalculateUserTrends(ArrayList<String> users_features, Double start_time)
        throws ParseException {

    SimpleDateFormat sdfu = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss");
    ArrayList<Double> result = new ArrayList<Double>();

    for (int i = 0; i < users_features.size(); i++) {
        SimpleRegression regression = new SimpleRegression();
        String[] features = ((String) users_features.get(i)).split(";");

        double average = 0.0;
        double f = 0.0;
        for (String s : features) {

            String[] inside_feature = s.split(",");

            //make timestamp secs
            Date udate = sdfu.parse(inside_feature[1]);
            double sec = udate.getTime();

            if (sec > start_time) {
                continue;
            }/* w  w w.j  a  v a2s  . c o  m*/
            average += Double.parseDouble(inside_feature[0]);
            //fix mls regr

            regression.addData(sec, Double.parseDouble(inside_feature[0]));

            average = average / features.length;

            f = Math.atan(regression.getSlope());// atan of slope is the angle of the regression in rad
            if (Double.isNaN(f)) {
                f = 0;
            }
            if (f != 0 && (Math.toDegrees(f) > 90 || Math.toDegrees(f) < -90)) {
                if ((Math.toDegrees(f) / 90) % 2 == 0) {//make angles in [-90,90]
                    f = Math.toDegrees(f) % Math.toDegrees(Math.PI / 2);
                } else {
                    f = -Math.toDegrees(f) % Math.toDegrees(Math.PI / 2);
                }
            }
            f = f + Math.PI / 2;//refrain trend=0                    

        }

        result.add(f);
        result.add(f * average);

    }
    return result;

}

From source file:org.akvo.caddisfly.sensor.colorimetry.strip.util.OpenCVUtil.java

@SuppressWarnings("UnusedParameters")
public static Mat detectStrip(Mat stripArea, StripTest.Brand brand, double ratioW, double ratioH) {
    List<Mat> channels = new ArrayList<>();
    Mat sArea = stripArea.clone();//from  w w w  .  j a  v a  2 s. c o m

    // Gaussian blur
    Imgproc.medianBlur(sArea, sArea, 3);
    Core.split(sArea, channels);

    // create binary image
    Mat binary = new Mat();

    // determine min and max NOT USED
    Imgproc.threshold(channels.get(0), binary, 128, MAX_RGB_INT_VALUE, Imgproc.THRESH_BINARY);

    // compute first approximation of line through length of the strip
    final WeightedObservedPoints points = new WeightedObservedPoints();
    final WeightedObservedPoints corrPoints = new WeightedObservedPoints();

    double tot, yTot;
    for (int i = 0; i < binary.cols(); i++) { // iterate over cols
        tot = 0;
        yTot = 0;
        for (int j = 0; j < binary.rows(); j++) { // iterate over rows
            if (binary.get(j, i)[0] > 128) {
                yTot += j;
                tot++;
            }
        }
        if (tot > 0) {
            points.add((double) i, yTot / tot);
        }
    }

    // order of coefficients is (b + ax), so [b, a]
    final PolynomialCurveFitter fitter = PolynomialCurveFitter.create(1);
    List<WeightedObservedPoint> pointsList = points.toList();
    final double[] coefficient = fitter.fit(pointsList);

    // second pass, remove outliers
    double estimate, actual;

    for (int i = 0; i < pointsList.size(); i++) {
        estimate = coefficient[1] * pointsList.get(i).getX() + coefficient[0];
        actual = pointsList.get(i).getY();
        if (actual > LOWER_PERCENTAGE_BOUND * estimate && actual < UPPER_PERCENTAGE_BOUND * estimate) {
            //if the point differs less than +/- 10%, keep the point
            corrPoints.add(pointsList.get(i).getX(), pointsList.get(i).getY());
        }
    }

    final double[] coefficientCorr = fitter.fit(corrPoints.toList());
    double slope = coefficientCorr[1];
    double offset = coefficientCorr[0];

    // compute rotation angle
    double rotAngleDeg = Math.atan(slope) * 180 / Math.PI;

    //determine a point on the line, in the middle of strip, in the horizontal middle of the whole image
    int midPointX = binary.cols() / 2;
    int midPointY = (int) Math.round(midPointX * slope + offset);

    // rotate around the midpoint, to straighten the binary strip
    Mat dstBinary = new Mat(binary.rows(), binary.cols(), binary.type());
    Point center = new Point(midPointX, midPointY);
    Mat rotMat = Imgproc.getRotationMatrix2D(center, rotAngleDeg, 1.0);
    Imgproc.warpAffine(binary, dstBinary, rotMat, binary.size(),
            Imgproc.INTER_CUBIC + Imgproc.WARP_FILL_OUTLIERS);

    // also apply rotation to colored strip
    Mat dstStrip = new Mat(stripArea.rows(), stripArea.cols(), stripArea.type());
    Imgproc.warpAffine(stripArea, dstStrip, rotMat, binary.size(),
            Imgproc.INTER_CUBIC + Imgproc.WARP_FILL_OUTLIERS);

    // Compute white points in each row
    double[] rowCount = new double[dstBinary.rows()];
    int rowTot;
    for (int i = 0; i < dstBinary.rows(); i++) { // iterate over rows
        rowTot = 0;
        for (int j = 0; j < dstBinary.cols(); j++) { // iterate over cols
            if (dstBinary.get(i, j)[0] > 128) {
                rowTot++;
            }
        }
        rowCount[i] = rowTot;
    }

    // find width by finding rising and dropping edges
    // rising edge  = largest positive difference
    // falling edge = largest negative difference
    int risePos = 0;
    int fallPos = 0;
    double riseVal = 0;
    double fallVal = 0;
    for (int i = 0; i < dstBinary.rows() - 1; i++) {
        if (rowCount[i + 1] - rowCount[i] > riseVal) {
            riseVal = rowCount[i + 1] - rowCount[i];
            risePos = i + 1;
        }
        if (rowCount[i + 1] - rowCount[i] < fallVal) {
            fallVal = rowCount[i + 1] - rowCount[i];
            fallPos = i;
        }
    }

    // cut out binary strip
    Point stripTopLeft = new Point(0, risePos);
    Point stripBottomRight = new Point(dstBinary.cols(), fallPos);

    org.opencv.core.Rect stripAreaRect = new org.opencv.core.Rect(stripTopLeft, stripBottomRight);
    Mat binaryStrip = dstBinary.submat(stripAreaRect);

    // also cut out colored strip
    Mat colorStrip = dstStrip.submat(stripAreaRect);

    // now right end of strip
    // method: first rising edge

    double[] colCount = new double[binaryStrip.cols()];
    int colTotal;
    for (int i = 0; i < binaryStrip.cols(); i++) { // iterate over cols
        colTotal = 0;
        for (int j = 0; j < binaryStrip.rows(); j++) { // iterate over rows
            if (binaryStrip.get(j, i)[0] > 128) {
                colTotal++;
            }
        }

        //Log.d("Caddisfly", String.valueOf(colTotal));
        colCount[i] = colTotal;
    }

    stripAreaRect = getStripRectangle(binaryStrip, colCount, brand.getStripLength(), ratioW);

    Mat resultStrip = colorStrip.submat(stripAreaRect).clone();

    // release Mat objects
    stripArea.release();
    sArea.release();
    binary.release();
    dstBinary.release();
    dstStrip.release();
    binaryStrip.release();
    colorStrip.release();

    return resultStrip;
}

From source file:Satellite.java

public static double[] Convert_To_Lat_Long(double[] posVec) {
    double Xcomp = posVec[0];
    double Ycomp = posVec[1];
    double Zcomp = posVec[2];

    double longitude;
    double latitude;
    double altitude;

    //Done so all cases of longitudes are right
    if (Ycomp > 0) {
        if (Xcomp > 0) {
            longitude = Math.toDegrees(Math.atan(Ycomp / Xcomp));
        } else {/*from   w  w  w  .  jav a 2s.c  o m*/
            longitude = 180 - Math.toDegrees(Math.atan(Math.abs(Ycomp / Xcomp)));
        }
    } else {
        if (Xcomp > 0) {
            longitude = -1 * Math.toDegrees(Math.atan(Math.abs(Ycomp / Xcomp)));
        } else {
            longitude = -1 * (180 - Math.toDegrees(Math.atan(Ycomp / Xcomp)));
        }
    }

    //Calculate latitude
    latitude = Math.toDegrees(Math.atan(Zcomp / Math.sqrt(Xcomp * Xcomp + Ycomp * Ycomp)));

    //Calculate radius and altitude
    double EPR = 6356800; //Earth Polar Radius in meters
    double EER = 6378100; //Earth Equator Radius in meters

    double earthRadius = Math
            .sqrt((Math.pow(EPR * EPR * Math.cos(latitude), 2) + Math.pow(EER * EER * Math.cos(latitude), 2))
                    / (Math.pow(EPR * Math.cos(latitude), 2) + Math.pow(EER * Math.cos(latitude), 2)));
    double orbitRadius = Math.sqrt(Xcomp * Xcomp + Ycomp * Ycomp + Zcomp * Zcomp);
    altitude = orbitRadius - earthRadius;
    return new double[] { latitude, longitude, altitude };
}

From source file:org.cirdles.geoapp.LatLongToUTM.java

private static BigDecimal calcXiPrimeNorth(BigDecimal changeInLongitudeRadians, BigDecimal tauPrime) {

    double cosOfLatRad = Math.cos(changeInLongitudeRadians.doubleValue());

    BigDecimal xiPrime = new BigDecimal(Math.atan(tauPrime.doubleValue() / cosOfLatRad));

    return xiPrime;
}