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:com.nextbreakpoint.nextfractal.mandelbrot.core.Expression.java

public static double funcAtan(double x) {
    return Math.atan(x);
}

From source file:chiliad.parser.pdf.extractor.vectorgraphics.operator.BeginInlineImage.java

/**
 * process : BI : begin inline image.//  w  ww .j  a v a  2s .co m
 *
 * @param operator The operator that is being executed.
 * @param arguments List
 * @throws IOException If there is an error displaying the inline image.
 */
@Override
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    VectorGraphicsExtractor extractor = (VectorGraphicsExtractor) context;
    PDPage page = extractor.getPage();
    //begin inline image object
    ImageParameters params = operator.getImageParameters();
    PDInlinedImage image = new PDInlinedImage();
    image.setImageParameters(params);
    image.setImageData(operator.getImageData());
    if (params.isStencil()) {
        //TODO implement inline image stencil masks 
        LOG.warn("Stencil masks are not implemented, background may be incorrect");
    }
    BufferedImage awtImage = image.createImage(context.getColorSpaces());

    if (awtImage == null) {
        LOG.warn("BeginInlineImage.process(): createImage returned NULL");
        return;
    }
    int imageWidth = awtImage.getWidth();
    int imageHeight = awtImage.getHeight();
    double pageHeight = extractor.getPageSize().getHeight();

    Matrix ctm = extractor.getGraphicsState().getCurrentTransformationMatrix();
    int pageRotation = page.findRotation();

    AffineTransform ctmAT = ctm.createAffineTransform();
    ctmAT.scale(1f / imageWidth, 1f / imageHeight);
    Matrix rotationMatrix = new Matrix();
    rotationMatrix.setFromAffineTransform(ctmAT);
    // calculate the inverse rotation angle
    // scaleX = m00 = cos
    // shearX = m01 = -sin
    // tan = sin/cos
    double angle = Math.atan(ctmAT.getShearX() / ctmAT.getScaleX());
    Matrix translationMatrix = null;
    if (pageRotation == 0 || pageRotation == 180) {
        translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getXScale()),
                (float) (pageHeight - 2 * ctm.getYPosition() - Math.cos(angle) * ctm.getYScale()));
    } else if (pageRotation == 90 || pageRotation == 270) {
        translationMatrix = Matrix.getTranslatingInstance((float) (Math.sin(angle) * ctm.getYScale()),
                (float) (pageHeight - 2 * ctm.getYPosition()));
    }
    rotationMatrix = rotationMatrix.multiply(translationMatrix);
    rotationMatrix.setValue(0, 1, (-1) * rotationMatrix.getValue(0, 1));
    rotationMatrix.setValue(1, 0, (-1) * rotationMatrix.getValue(1, 0));
    AffineTransform at = new AffineTransform(rotationMatrix.getValue(0, 0), rotationMatrix.getValue(0, 1),
            rotationMatrix.getValue(1, 0), rotationMatrix.getValue(1, 1), rotationMatrix.getValue(2, 0),
            rotationMatrix.getValue(2, 1));
    extractor.drawImage(awtImage, at);
}

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

public ArrayList<Double> CalculateUserTrends(ArrayList<String> users_features) 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();
            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;//from   www .java 2 s  . c  o  m
            }
            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.moeaframework.util.tree.NodeTest.java

@Test
public void testAtan() {
    Node node = new Atan().setArgument(0, new Constant(Math.PI / 4.0));

    Assert.assertTrue(//from w  w  w .  jav a 2s . c  om
            NumberArithmetic.equals(Math.atan(Math.PI / 4.0), (Number) node.evaluate(new UnusedEnvironment())));
}

From source file:org.interpss.numeric.datatype.ComplexFunc.java

/**
 * Angle function, return the angle in rad of this obj
 * /*  w  ww.  j  a va2s . com*/
 * @return the resulting angle in rad
 */
public static double arg(final Complex c) {
    // the angle in the plane in rad
    if (c.getReal() == 0.0) {
        if (c.getImaginary() > 0.0) {
            return Math.toRadians(90.0);
        } else if (c.getImaginary() < 0.0) {
            return Math.toRadians(-90.0);
        } else {
            return 0.0;
        }
    } else {
        double ang = Math.atan(c.getImaginary() / c.getReal());
        if (c.getReal() < 0.0)
            ang += Math.PI;
        return ang;
    }
}

From source file:name.hashbrown.getmeadrink.MapActivity.java

private LatLng toLatLong(double wgs_x, double wgs_y) {
    if (Math.abs(wgs_x) < 180 && Math.abs(wgs_y) < 90) {
        return new LatLng(0.0, 0.0);
    }//from  w  w w . ja v  a  2s .  c om

    if ((Math.abs(wgs_x) > 20037508.3427892) || (Math.abs(wgs_y) > 20037508.3427892)) {
        return new LatLng(0.0, 0.0);
    }

    double x = wgs_x;
    double y = wgs_y;
    double num3 = x / 6378137.0;
    double num4 = num3 * 57.295779513082323;
    double num5 = Math.floor((double) ((num4 + 180.0) / 360.0));
    double num6 = num4 - (num5 * 360.0);
    double num7 = 1.5707963267948966 - (2.0 * Math.atan(Math.exp((-1.0 * y) / 6378137.0)));

    double lon = num6;
    double lat = num7 * 57.295779513082323;
    return new LatLng(lat, lon);
}

From source file:com.joliciel.jochre.boundaries.features.SlopeDifferenceFeature.java

@Override
public FeatureResult<Double> checkInternal(Split split, RuntimeEnvironment env) {
    FeatureResult<Double> result = null;
    FeatureResult<Integer> contourDistanceResult = contourDistanceFeature.check(split, env);
    if (contourDistanceResult != null) {
        int contourDistance = contourDistanceResult.getOutcome();

        int[][] verticalContour = split.getShape().getVerticalContour();
        int x = split.getPosition();
        Shape shape = split.getShape();
        int topStart = verticalContour[x][0];
        int bottomStart = verticalContour[x][1];

        SimpleRegression topRightRegression = new SimpleRegression();
        SimpleRegression bottomRightRegression = new SimpleRegression();
        SimpleRegression topLeftRegression = new SimpleRegression();
        SimpleRegression bottomLeftRegression = new SimpleRegression();

        topRightRegression.addData(x, topStart);
        topLeftRegression.addData(x, topStart);
        bottomRightRegression.addData(x, bottomStart);
        bottomLeftRegression.addData(x, bottomStart);

        for (int i = 1; i <= contourDistance; i++) {
            if (x + i < shape.getWidth()) {
                topRightRegression.addData(x + i, verticalContour[x + i][0]);
                bottomRightRegression.addData(x + i, verticalContour[x + i][1]);
            }//from   w  ww  .j  a  v  a2  s. com
            if (x - i >= 0) {
                topLeftRegression.addData(x - i, verticalContour[x - i][0]);
                bottomLeftRegression.addData(x - i, verticalContour[x - i][1]);
            }
        }

        // get the slopes
        double topRightSlope = topRightRegression.getSlope();
        double bottomRightSlope = bottomRightRegression.getSlope();
        double topLeftSlope = topLeftRegression.getSlope();
        double bottomLeftSlope = bottomLeftRegression.getSlope();

        // convert slopes to angles
        double topRightAngle = Math.atan(topRightSlope);
        double bottomRightAngle = Math.atan(bottomRightSlope);
        double topLeftAngle = Math.atan(topLeftSlope);
        double bottomLeftAngle = Math.atan(bottomLeftSlope);

        // calculate the right & left-hand differences
        double rightDiff = Math.abs(topRightAngle - bottomRightAngle);
        double leftDiff = Math.abs(topLeftAngle - bottomLeftAngle);

        // normalise the differences from 0 to 1
        rightDiff = rightDiff / Math.PI;
        leftDiff = leftDiff / Math.PI;

        double product = rightDiff * leftDiff;

        if (LOG.isTraceEnabled()) {
            LOG.trace("topRightAngle: " + topRightAngle);
            LOG.trace("bottomRightAngle: " + bottomRightAngle);
            LOG.trace("topLeftAngle: " + topLeftAngle);
            LOG.trace("bottomLeftAngle: " + bottomLeftAngle);
            LOG.trace("rightDiff: " + rightDiff);
            LOG.trace("leftDiff: " + leftDiff);
            LOG.trace("product: " + product);
        }

        result = this.generateResult(product);
    }
    return result;
}

From source file:com.opengamma.strata.math.impl.minimization.SumToOneTest.java

@Test
public void solverTest2() {
    double[] w = new double[] { 3.0, 4.0 };
    final int n = w.length;
    Function<DoubleArray, DoubleArray> func = new Function<DoubleArray, DoubleArray>() {

        @Override//  w  ww.j  a  va  2 s.c o m
        public DoubleArray apply(DoubleArray x) {
            double a = x.get(0);
            double theta = x.get(1);
            double c1 = Math.cos(theta);
            return DoubleArray.of(a * c1 * c1, a * (1 - c1 * c1));
        }
    };

    DoubleArray sigma = DoubleArray.filled(n, 1e-4);
    DoubleArray start = DoubleArray.of(0.0, 0.8);

    LeastSquareResults res = SOLVER.solve(DoubleArray.copyOf(w), sigma, func, start/*, maxJump*/);
    assertEquals("chi sqr", 0.0, res.getChiSq(), 1e-9);
    double[] fit = res.getFitParameters().toArray();
    assertEquals(7.0, fit[0], 1e-9);
    assertEquals(Math.atan(Math.sqrt(4 / 3.)), fit[1], 1e-9);
}

From source file:pyromaniac.Algorithm.MultinomialOneSidedTest.java

public void runTest() throws Exception {
    //not significant if no observations below and no observations above
    if (observationsBelowMode == 0 && observationsAboveMode == 0) {
        this.p = 1;
    } //significant if the number of observations above mode is equal to that at the mode. 
    /*         else if(N <= 5 && observationsAtMode != N)
    {//from  w  w  w . j  a  va 2s  . com
       this.significant = true;
       this.p = 0;
    }*/
    else if (alpha > 0
            && (observationsAboveMode == observationsAtMode || observationsBelowMode == observationsAtMode)) {
        this.significantAbove = true;
        this.significantBelow = true;
        //this.significantCombined = true;
        this.p = 0;
    } else {

        int indexBelowMode = 1;
        int indexAboveMode = 2;

        double[] X = new double[] { this.observationsAtMode, this.observationsBelowMode,
                this.observationsAboveMode };
        double[] xDivN = new double[] { (double) this.observationsAtMode / (double) this.N,
                (double) this.observationsBelowMode / (double) this.N,
                (double) this.observationsAboveMode / (double) this.N };
        HashSet<Integer> gamma = new HashSet<Integer>();

        if (verbose) {
            for (int i = 0; i < X.length; i++) {
                logger.writeLog("X[" + i + "] = " + X[i], AcaciaLogger.LOG_DEBUG);
                logger.writeLog("XDivN[" + i + "] = " + xDivN[i], AcaciaLogger.LOG_DEBUG);
                logger.writeLog("P[" + i + "] = " + P[i], AcaciaLogger.LOG_DEBUG);
            }
        }

        for (int i = 1; i < xDivN.length; i++) {
            if (xDivN[i] >= P[i]) {
                gamma.add(i);
            }
        }

        double sumX = 0;
        double sumP = 0;

        for (int index : gamma) {
            sumX += X[index];
            sumP += P[index];
        }

        while (gamma.size() < 2) {
            boolean added = false;

            for (int i = 1; i < xDivN.length; i++) {
                double adjP = X[i] * (1 - sumP) / (this.N - sumX);

                if (adjP > P[i] & !gamma.contains(i)) {
                    gamma.add(i);
                    added = true;
                }
            }

            if (!added) {
                break;
            }

            sumP = 0;
            sumX = 0;

            for (int index : gamma) {
                sumX += X[index];
                sumP += P[index];
            }
        }

        NormalDistribution norm = new NormalDistribution();

        double w2Num = Math.pow(((N - sumX) - N * (1 - sumP)), 2);
        double w2Denom = (N * (1 - sumP));
        double resSum = 0;
        for (int index : gamma) {
            resSum += Math.pow(X[index] - N * P[index], 2) / (N * P[index]);
        }

        double w2 = (w2Num / w2Denom) + resSum;
        double m = Math
                .sqrt(P[indexBelowMode] * P[indexAboveMode] / (1 - P[indexBelowMode] - P[indexAboveMode]));
        double calcP = (0.25 + (Math.atan(m) / (2 * Math.PI))) * Math.exp(-w2 / 2)
                + (1 - norm.cumulativeProbability(Math.sqrt(w2)));

        this.p = calcP;

        if (this.alpha > 0) {
            boolean sig = (this.p <= this.alpha);
            this.significantAbove = sig;
            this.significantBelow = sig;
            //   this.significantCombined = sig;
        } else //alpha == zero
        {
        }
    }
}

From source file:org.apache.drill.exec.fn.impl.TestNewMathFunctions.java

@Test
public void testTrigoMathFunc() throws Throwable {
    final Object[] expected = new Object[] { Math.sin(45), Math.cos(45), Math.tan(45), Math.asin(45),
            Math.acos(45), Math.atan(45), Math.sinh(45), Math.cosh(45), Math.tanh(45) };
    runTest(expected, "functions/testTrigoMathFunctions.json");
}