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:copter.MPU9150.java

private List<Double> readAccel() {

    try {/*from  w  w w.j a  va2  s. c  o m*/
        accelData = new byte[6];
        //gyroData = new byte[6];

        //You can read one registry at a time,
        //or you can read multiple consecutive ones, 
        //in our case we are reading 6 consecutive registries
        //from 0x3B, meaning we are reading all the 
        //accelerometer measurements
        int r = device.read(0x3B, accelData, 0, 6);
        if (r != 6) {
            //System.out.println("Error reading accel data, < 6 bytes");
        }
        //Convert the values to integers, using the
        //helper method asInt
        int accelX = ((int) (accelData[0] / 4));
        int accelY = ((int) (accelData[2] / 4));
        int accelZ = ((int) (accelData[4] / 4));
        double Ax = Math.atan(accelX / Math.sqrt(accelY * accelY + accelZ * accelZ)) * 180 / Math.PI;
        double Ay = Math.atan(accelY / Math.sqrt(accelX * accelX + accelZ * accelZ)) * 180 / Math.PI;
        double Az = Math.atan(accelZ / Math.sqrt(accelX * accelX + accelY * accelY)) * 180 / Math.PI;
        List<Double> ret = new ArrayList<>();
        Ax = Math.round(Ax);
        Ay = Math.round(Ay);
        Az = Math.round(Az);
        ret.add(Ax);
        ret.add(Ay);
        ret.add(Az);
        return ret;
    } catch (IOException ex) {
        Logger.getLogger(MPU9150.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;

}

From source file:Main.java

static double distanceFromArc(double dA, double dB, double dAB) {
    // In spherical trinagle ABC
    // a is length of arc BC, that is dB
    // b is length of arc AC, that is dA
    // c is length of arc AB, that is dAB
    // We rename parameters so following formulas are more clear:
    double a = dB;
    double b = dA;
    double c = dAB;

    // First, we calculate angles alpha and beta in spherical triangle ABC
    // and based on them we decide how to calculate the distance:
    if (Math.sin(b) * Math.sin(c) == 0.0 || Math.sin(c) * Math.sin(a) == 0.0) {
        // It probably means that one of distance is n*pi, which gives around 20000km for n = 1,
        // unlikely for Denmark, so we should be fine.
        return -1.0;
    }/*from w  w  w.j  av  a2 s .  c  om*/

    double alpha = Math.acos((Math.cos(a) - Math.cos(b) * Math.cos(c)) / (Math.sin(b) * Math.sin(c)));
    double beta = Math.acos((Math.cos(b) - Math.cos(c) * Math.cos(a)) / (Math.sin(c) * Math.sin(a)));

    // It is possible that both sinuses are too small so we can get nan when dividing with them
    if (Double.isNaN(alpha) || Double.isNaN(beta)) {
        // double cosa = cos(a);
        // double cosbc = cos(b) * cos(c);
        // double minus1 = cosa - cosbc;
        // double sinbc = sin(b) * sin(c);
        // double div1 = minus1 / sinbc;
        //
        // double cosb = cos(b);
        // double cosca = cos(a) * cos(c);
        // double minus2 = cosb - cosca;
        // double sinca = sin(a) * sin(c);
        // double div2 = minus2 / sinca;

        return -1.0;
    }

    // If alpha or beta are zero or pi, it means that C is on the same circle as arc AB,
    // we just need to figure out if it is between AB:
    if (alpha == 0.0 || beta == 0.0) {
        return (dA + dB > dAB) ? Math.min(dA, dB) : 0.0;
    }

    // If alpha is obtuse and beta is acute angle, then
    // distance is equal to dA:
    if (alpha > Math.PI / 2 && beta < Math.PI / 2)
        return dA;

    // Analogously, if beta is obtuse and alpha is acute angle, then
    // distance is equal to dB:
    if (beta > Math.PI / 2 && alpha < Math.PI / 2)
        return dB;

    // If both alpha and beta are acute or both obtuse or one of them (or both) are right,
    // distance is the height of the spherical triangle ABC:

    // Again, unlikely, since it would render at least pi/2*EARTH_RADIUS_IN_METERS, which is too much.
    if (Math.cos(a) == 0.0)
        return -1;

    double x = Math.atan(-1.0 / Math.tan(c) + (Math.cos(b) / (Math.cos(a) * Math.sin(c))));

    // Similar to previous edge cases...
    if (Math.cos(x) == 0.0)
        return -1.0;

    return Math.acos(Math.cos(a) / Math.cos(x));
}

From source file:org.esa.beam.util.math.FastMathTest.java

@Test
public void testMathATan() {
    for (double i = 0; i < numItr; ++i) {
        double val = Math.atan(i);
    }//from  w  w w.j ava 2  s. c  o m
}

From source file:Satellite.java

public static double[] Convert_To_Lat_Long(Vector3D posVec) {
    double Xcomp = posVec.getX();
    double Ycomp = posVec.getY();
    double Zcomp = posVec.getZ();

    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  ww .ja  va 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 EER = Constants.WGS84_EARTH_EQUATORIAL_RADIUS; //Earth Equator Radius in meters
    double EPR = EER - EER * Constants.WGS84_EARTH_FLATTENING; //Earth Polar 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:com.wwidesigner.geometry.calculation.DefaultFippleMouthpieceCalculator.java

protected double calcKDeltaL(Mouthpiece mouthpiece, double omega, double z0) {
    double result = Math.atan(1.0 / (z0 * (calcJYE(mouthpiece, omega) + calcJYC(mouthpiece, omega))));

    return result;
}

From source file:contactangle.ImageControl.java

@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g);

    if (img != null)
        g.drawImage(img, 0, 0, this);
    else/* ww w .j a  v  a2  s  . co  m*/
        g.drawString("NO IMAGE", 0, 15);

    g.setColor(Color.RED);

    if (x1 < x2 && y1 < y2)
        g.drawRect(x1, y1, x2 - x1, y2 - y1);
    else if (x1 >= x2 && y1 < y2)
        g.drawRect(x2, y1, x1 - x2, y2 - y1);
    else if (x1 < x2 && y1 >= y2)
        g.drawRect(x1, y2, x2 - x1, y1 - y2);
    else
        g.drawRect(x2, y2, x1 - x2, y1 - y2);

    if (valid && img != null) {

        if (x1 >= x2) {
            int temp = x1;
            x1 = x2;
            x2 = temp;
        }
        if (y1 >= y2) {
            int temp = y1;
            y1 = y2;
            y2 = temp;
        }

        choosenPoints = new ArrayList<Point>();
        for (int y = y1; y < y2; y++) {
            for (int x = x1; x < x2; x++) {
                int pixelData = img.getRGB(x, y);
                if (pixelData == -1)
                    choosenPoints.add(new Point(x, y));
            }
        }

        SimpleRegression reg = new SimpleRegression();
        for (Point p : choosenPoints) {
            reg.addData(p.x, p.y);
        }

        int firstX = choosenPoints.get(0).x;
        int firstY = choosenPoints.get(0).y;
        double slope = reg.getSlope();
        g.setColor(Color.GREEN);
        g.drawLine(firstX, firstY, firstX + (70), firstY + (int) (slope * (70)));
        g.drawLine(firstX, firstY, firstX - (70), firstY - (int) (slope * (70)));

        double contactDegrees = (Math.atan(reg.getSlope()) / (2 * Math.PI)) * 360.0;

        DecimalFormat d = new DecimalFormat("##.###");

        g.drawString("Contact Angle = ", 25, 25);
        g.drawString(d.format(contactDegrees) + " degrees", 25, 38);
    }

}

From source file:org.phenotips.data.internal.OmimInformationContentPatientScorer.java

@Override
public double getScore(Patient patient) {
    Pair<Double, Integer> symptomsScore = process(patient, true);
    Pair<Double, Integer> negativeSymptomsScore = process(patient, false);
    double score = 0;

    if (symptomsScore.getRight() + negativeSymptomsScore.getRight() > 0) {
        score = 2 * Math.atan(symptomsScore.getLeft() / 10 + negativeSymptomsScore.getLeft() / 20) / Math.PI;
    }/*from  w  ww. j  a v a 2  s.  c o m*/
    return score;
}

From source file:org.apache.pdfbox.util.operator.pagedrawer.BeginInlineImage.java

/**
 * process : BI : begin inline image./*w ww  .  j  a v  a 2  s . c  o m*/
 * @param operator The operator that is being executed.
 * @param arguments List
 * @throws IOException If there is an error displaying the inline image.
 */
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    PageDrawer drawer = (PageDrawer) context;
    PDPage page = drawer.getPage();
    //begin inline image object
    ImageParameters params = operator.getImageParameters();
    PDInlinedImage image = new PDInlinedImage();
    image.setImageParameters(params);
    image.setImageData(operator.getImageData());
    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 = drawer.getPageSize().getHeight();

    Matrix ctm = drawer.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));
    drawer.drawImage(awtImage, at);
}

From source file:edu.umass.cs.iesl.pdf2meta.cli.extract.pdfbox.pagedrawer.BeginInlineImage.java

/**
 * process : BI : begin inline image.// w  ww . j  a  v a 2 s. co m
 * @param operator The operator that is being executed.
 * @param arguments List
 * @throws java.io.IOException If there is an error displaying the inline image.
 */
public void process(PDFOperator operator, List<COSBase> arguments) throws IOException {
    GraphicsAwarePDFStreamEngine drawer = (GraphicsAwarePDFStreamEngine) context;

    PDPage page = drawer.getPage();
    //begin inline image object
    ImageParameters params = operator.getImageParameters();
    PDInlinedImage image = new PDInlinedImage();
    image.setImageParameters(params);
    image.setImageData(operator.getImageData());
    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 = drawer.getPageSize().getHeight();

    Matrix ctm = drawer.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));
    drawer.drawImage(awtImage, at);
}

From source file:org.apache.flink.table.runtime.functions.SqlFunctionUtils.java

public static double atan(Decimal a) {
    return Math.atan(a.doubleValue());
}