Example usage for java.lang Math tan

List of usage examples for java.lang Math tan

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double tan(double a) 

Source Link

Document

Returns the trigonometric tangent of an angle.

Usage

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

@Test
public void testMathTan() {
    for (double i = 0; i < numItr; ++i) {
        double val = Math.tan(i);
    }// w  ww  . j ava 2s.  co m
}

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

public static UTM convert(BigDecimal latitude, BigDecimal longitude, String datumName) {

    DatumEnum datumEnum = DatumEnum.valueOf(datumName);
    BigDecimal flattening3D = new BigDecimal(datumEnum.getFlattening3D());
    BigDecimal meridianRadius = new BigDecimal(datumEnum.getMeridianRadius());
    BigDecimal eccentricity = new BigDecimal(datumEnum.getEccentricity());

    BigDecimal latitudeRadians = latitude.abs().multiply(new BigDecimal(Math.PI)).divide(new BigDecimal(180.0),
            precision, RoundingMode.HALF_UP);

    //System.out.println("Latitude Radians: " + latitudeRadians);

    int zoneNumber = calcZoneNumber(longitude);

    BigDecimal zoneCentralMeridian = calcZoneCentralMeridian(zoneNumber);

    BigDecimal changeInLongitudeDegree = (longitude.subtract(zoneCentralMeridian)).abs().setScale(precision,
            RoundingMode.HALF_UP);
    //System.out.println("Change in Long Degree: " + changeInLongitudeDegree);

    BigDecimal changeInLongitudeRadians = (changeInLongitudeDegree.multiply(new BigDecimal(Math.PI)))
            .divide(new BigDecimal(180), precision, RoundingMode.HALF_UP);
    //System.out.println("Change In Longitude Radians: " + changeInLongitudeRadians);

    BigDecimal conformalLatitude = calcConformalLatitude(eccentricity, latitudeRadians).setScale(precision,
            RoundingMode.HALF_UP);
    //System.out.println("Conformal Latitude: " + conformalLatitude);

    BigDecimal tauPrime = (new BigDecimal(Math.tan(conformalLatitude.doubleValue()))).setScale(precision,
            RoundingMode.HALF_UP);
    //System.out.println("Tau Prime: " + tauPrime);

    BigDecimal xiPrimeNorth = calcXiPrimeNorth(changeInLongitudeRadians, tauPrime).setScale(precision,
            RoundingMode.HALF_UP);
    //System.out.println("xi Prime North: " + xiPrimeNorth);

    BigDecimal etaPrimeEast = calcEtaPrimeEast(changeInLongitudeRadians, tauPrime).setScale(precision,
            RoundingMode.HALF_UP);
    //System.out.println("Eta Prime East: " + etaPrimeEast);

    BigDecimal[] alphaSeries = { KrugerSeries.alpha1(flattening3D).setScale(precision, RoundingMode.HALF_UP),
            KrugerSeries.alpha2(flattening3D.setScale(precision, RoundingMode.HALF_UP)),
            KrugerSeries.alpha3(flattening3D).setScale(precision, RoundingMode.HALF_UP),
            KrugerSeries.alpha4(flattening3D).setScale(precision, RoundingMode.HALF_UP),
            KrugerSeries.alpha5(flattening3D).setScale(precision, RoundingMode.HALF_UP),
            KrugerSeries.alpha6(flattening3D).setScale(precision, RoundingMode.HALF_UP),
            KrugerSeries.alpha7(flattening3D).setScale(precision, RoundingMode.HALF_UP) };

    BigDecimal xiNorth = calcXiNorth(xiPrimeNorth, etaPrimeEast, alphaSeries).setScale(precision,
            RoundingMode.HALF_UP);
    //System.out.println("xi North: " + xiNorth);

    BigDecimal etaEast = calcEtaEast(xiPrimeNorth, etaPrimeEast, alphaSeries).setScale(precision,
            RoundingMode.HALF_UP);
    //System.out.println("Eta East: " + etaEast);

    BigDecimal easting = calcEasting(meridianRadius, etaEast, longitude, zoneCentralMeridian)
            .setScale(precision, RoundingMode.HALF_UP);
    BigDecimal northing = calcNorthing(meridianRadius, xiNorth, latitude).setScale(precision,
            RoundingMode.HALF_UP);

    char zoneLetter = calcZoneLetter(latitude);
    char hemisphere = calcHemisphere(latitude);

    return new UTM(easting, northing, hemisphere, zoneNumber, zoneLetter);

}

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

/**
 * Converts BigDecimal latitude longitude to UTM 
 * /*w w w .j  a  va 2 s .  c  om*/
 * @param latitude
 * @param longitude
 * @param datumName
 * @return UTM
 * @throws java.lang.Exception
 * 
 * 
 */
public static UTM convert(BigDecimal latitude, BigDecimal longitude, String datumName) throws Exception {

    Datum datum = Datum.valueOf(datumName);

    BigDecimal meridianRadius = new BigDecimal(datum.getMeridianRadius());
    BigDecimal eccentricity = new BigDecimal(datum.getEccentricity());

    BigDecimal latitudeRadians = latitude.abs().multiply(new BigDecimal(Math.PI)).divide(new BigDecimal(180.0),
            PRECISION, RoundingMode.HALF_UP);

    int zoneNumber = calcZoneNumber(longitude);

    BigDecimal zoneCentralMeridian = calcZoneCentralMeridian(zoneNumber);

    BigDecimal changeInLongitudeDegree = (longitude.subtract(zoneCentralMeridian)).abs().setScale(PRECISION,
            RoundingMode.HALF_UP);

    BigDecimal changeInLongitudeRadians = (changeInLongitudeDegree.multiply(new BigDecimal(Math.PI)))
            .divide(new BigDecimal(180), PRECISION, RoundingMode.HALF_UP);

    BigDecimal conformalLatitude = calcConformalLatitude(eccentricity, latitudeRadians).setScale(PRECISION,
            RoundingMode.HALF_UP);

    BigDecimal tauPrime = (new BigDecimal(Math.tan(conformalLatitude.doubleValue()))).setScale(PRECISION,
            RoundingMode.HALF_UP);

    BigDecimal xiPrimeNorth = calcXiPrimeNorth(changeInLongitudeRadians, tauPrime).setScale(PRECISION,
            RoundingMode.HALF_UP);

    BigDecimal etaPrimeEast = calcEtaPrimeEast(changeInLongitudeRadians, tauPrime).setScale(PRECISION,
            RoundingMode.HALF_UP);

    double[] alphaSeries = datum.getAlphaSeries();

    BigDecimal xiNorth = calcXiNorth(xiPrimeNorth, etaPrimeEast, alphaSeries).setScale(PRECISION,
            RoundingMode.HALF_UP);

    BigDecimal etaEast = calcEtaEast(xiPrimeNorth, etaPrimeEast, alphaSeries).setScale(PRECISION,
            RoundingMode.HALF_UP);

    BigDecimal easting = calcEasting(meridianRadius, etaEast, longitude, zoneCentralMeridian)
            .setScale(PRECISION, RoundingMode.HALF_UP);
    BigDecimal northing = calcNorthing(meridianRadius, xiNorth, latitude).setScale(PRECISION,
            RoundingMode.HALF_UP);

    char zoneLetter = calcZoneLetter(latitude);
    char hemisphere = calcHemisphere(latitude);

    if (easting.doubleValue() > UTM.MAX_EASTING)
        easting = new BigDecimal(UTM.MAX_EASTING);
    if (easting.doubleValue() < UTM.MIN_EASTING)
        easting = new BigDecimal(UTM.MIN_EASTING);

    if (northing.doubleValue() > UTM.MAX_NORTHING)
        northing = new BigDecimal(UTM.MAX_NORTHING);
    if (northing.doubleValue() < UTM.MIN_NORTHING)
        northing = new BigDecimal(UTM.MIN_NORTHING);

    UTM utm = new UTM(easting.setScale(SCALE, RoundingMode.HALF_UP),
            northing.setScale(SCALE, RoundingMode.HALF_UP), hemisphere, zoneNumber, zoneLetter);

    return utm;
}

From source file:com.wheelermarine.publicAccessSites.Updater.java

/**
 * Convert a UTM location to a latitude and longitude location.
 *
 * @param north the northing value./*  w  w  w. j  a va  2  s  . c o m*/
 * @param east  the easting value.
 * @param zone  the UTM zone.
 * @return a Location containing the latitude and longitude.
 */
public static Location fromUTM(double north, double east, double zone) {

    double d = 0.99960000000000004;
    double d1 = 6378137;
    double d2 = 0.0066943799999999998;
    double d4 = (1 - Math.sqrt(1 - d2)) / (1 + Math.sqrt(1 - d2));
    double d3 = d2 / (1 - d2);
    double d12 = (north / d) / (d1 * (1 - d2 / 4 - (3 * d2 * d2) / 64 - (5 * Math.pow(d2, 3)) / 256));
    double d14 = d12 + ((3 * d4) / 2 - (27 * Math.pow(d4, 3)) / 32) * Math.sin(2 * d12)
            + ((21 * d4 * d4) / 16 - (55 * Math.pow(d4, 4)) / 32) * Math.sin(4 * d12)
            + ((151 * Math.pow(d4, 3)) / 96) * Math.sin(6 * d12);
    double d5 = d1 / Math.sqrt(1 - d2 * Math.sin(d14) * Math.sin(d14));
    double d6 = Math.tan(d14) * Math.tan(d14);
    double d7 = d3 * Math.cos(d14) * Math.cos(d14);
    double d8 = (d1 * (1 - d2)) / Math.pow(1 - d2 * Math.sin(d14) * Math.sin(d14), 1.5);
    double d9 = (east - 500000) / (d5 * d);
    double lat = (d14 - ((d5 * Math.tan(d14)) / d8)
            * (((d9 * d9) / 2 - (((5 + 3 * d6 + 10 * d7) - 4 * d7 * d7 - 9 * d3) * Math.pow(d9, 4)) / 24)
                    + (((61 + 90 * d6 + 298 * d7 + 45 * d6 * d6) - 252 * d3 - 3 * d7 * d7) * Math.pow(d9, 6))
                            / 720))
            * 180 / Math.PI;
    double lon = (((zone - 1) * 6 - 180) + 3) + (((d9 - ((1 + 2 * d6 + d7) * Math.pow(d9, 3)) / 6)
            + (((((5 - 2 * d7) + 28 * d6) - 3 * d7 * d7) + 8 * d3 + 24 * d6 * d6) * Math.pow(d9, 5)) / 120)
            / Math.cos(d14)) * 180 / Math.PI;
    Location loc = new Location("MNDNR");
    loc.setLatitude(lat);
    loc.setLongitude(lon);
    return loc;
}

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  a v  a2s  . com*/

    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:com.v2soft.misto.Providers.MapnikProvider.java

@Override
public TileInfo getTileInfoByLocation(Location location, int zoom) {
    TileInfo res = new TileInfo();
    res.setHeight(TILE_SIZE);/*from w w  w. j  a v a  2s .  c  om*/
    res.setWidth(TILE_SIZE);
    res.setZoom(zoom);
    res.setLatitude((int) Math.floor((1 - Math.log(Math.tan(location.getLatitude() * Math.PI / 180)
            + 1 / Math.cos(location.getLatitude() * Math.PI / 180)) / Math.PI) / 2 * (1 << zoom)));
    double longitude = Math.floor((location.getLongitude() + 180) * worldTilesCount(zoom) / 360);
    res.setLongitude((int) longitude);
    return res;
}

From source file:edu.indiana.d2i.datacatalog.dashboard.api.USStates.java

public static String getStates(String statesFilePath)
        throws ParserConfigurationException, IOException, SAXException {
    JSONObject statesFeatureCollection = new JSONObject();
    statesFeatureCollection.put("type", "FeatureCollection");
    JSONArray features = new JSONArray();

    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    try {//from   w  w w  .ja  va2  s.  c o m
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document dom = documentBuilder.parse(new FileInputStream(new File(statesFilePath)));
        Element docElement = dom.getDocumentElement();
        NodeList states = docElement.getElementsByTagName("state");
        for (int i = 0; i < states.getLength(); i++) {
            Node state = states.item(i);
            JSONObject stateObj = new JSONObject();
            stateObj.put("type", "Feature");
            JSONObject geometry = new JSONObject();
            geometry.put("type", "Polygon");
            JSONArray coordinates = new JSONArray();
            JSONArray coordinateSub = new JSONArray();
            NodeList points = ((Element) state).getElementsByTagName("point");
            for (int j = 0; j < points.getLength(); j++) {
                Node point = points.item(j);
                JSONArray pointObj = new JSONArray();
                float lat = Float.parseFloat(((Element) point).getAttribute("lat"));
                float lng = Float.parseFloat(((Element) point).getAttribute("lng"));
                double trLng = lng * 20037508.34 / 180;
                double trLat = Math.log(Math.tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180);
                pointObj.add(lng);
                pointObj.add(lat);
                coordinateSub.add(pointObj);
            }
            geometry.put("coordinates", coordinates);
            coordinates.add(coordinateSub);
            stateObj.put("geometry", geometry);
            JSONObject name = new JSONObject();
            name.put("Name", ((Element) state).getAttribute("name"));
            name.put("colour", "#FFF901");
            stateObj.put("properties", name);
            features.add(stateObj);
        }
        statesFeatureCollection.put("features", features);
        return statesFeatureCollection.toJSONString();
    } catch (ParserConfigurationException e) {
        log.error("Error while processing states.xml.", e);
        throw e;
    } catch (FileNotFoundException e) {
        log.error("Error while processing states.xml.", e);
        throw e;
    } catch (SAXException e) {
        log.error("Error while processing states.xml.", e);
        throw e;
    } catch (IOException e) {
        log.error("Error while processing states.xml.", e);
        throw e;
    }
}

From source file:cpcc.ros.sim.osm.Camera.java

/**
 * @param position the position to capture an image.
 * @return the captured image.// w w w. j  a  v  a2 s  .  c o m
 * @throws IOException thrown in case of errors.
 */
public byte[] getImage(PolarCoordinate position) throws IOException {
    if (position == null) {
        return ArrayUtils.EMPTY_BYTE_ARRAY;
    }

    PolarCoordinate pos = new PolarCoordinate(position);

    if (pos.getAltitude() > 200) {
        pos.setAltitude(200);
    }

    if (cfg.getOriginPosition() != null) {
        pos = cfg.getGeodeticSystem().walk(cfg.getOriginPosition(), -pos.getLatitude(), pos.getLongitude(),
                pos.getAltitude());
    }

    double dx = pos.getAltitude() * Math.tan(cfg.getCameraApertureAngle() / 2.0);
    double dy = dx * cfg.getCameraHeight() / cfg.getCameraWidth();

    PolarCoordinate topLeftPosition = cfg.getGeodeticSystem().walk(pos, -dy, -dx, 0);
    PolarCoordinate bottomRightPosition = cfg.getGeodeticSystem().walk(pos, dy, dx, 0);

    MercatorProjection newTopLeftTile = new MercatorProjection(cfg.getZoomLevel(),
            topLeftPosition.getLatitude(), topLeftPosition.getLongitude());

    MercatorProjection newBottomRightTile = new MercatorProjection(cfg.getZoomLevel(),
            bottomRightPosition.getLatitude(), bottomRightPosition.getLongitude());

    boolean reloadTiles = topLeftTile == null || !topLeftTile.equalsTile(newTopLeftTile);
    topLeftTile = newTopLeftTile;
    bottomRightTile = newBottomRightTile;

    int newMapWidth = bottomRightTile.getxTile() - topLeftTile.getxTile() + 1;
    int newMapHeight = bottomRightTile.getyTile() - topLeftTile.getyTile() + 1;

    if (newMapWidth > mapWidth || newMapHeight > mapHeight) {
        mapWidth = newMapWidth;
        mapHeight = newMapHeight;
        initMap();
        reloadTiles = true;
    }

    if (reloadTiles) {
        loadTiles();
    }

    return extractImage();
}

From source file:org.streaminer.stream.entropy.EntropySketch.java

/**
 * Return a float from the maximally skewed stable distribution F(x;1,-1,math.Pi/2,0)
 * @param r/*from w  w  w  . j a v  a  2 s  .  c  o m*/
 * @return 
 */
private double maxSkew(RandomGenerator r) {
    double u1 = r.nextDouble();
    double u2 = r.nextDouble();

    double w1 = Math.PI * (u1 * 0.5);
    double w2 = -(Math.log(u2) / Math.log(2));

    double halfPiW1 = Math.PI / 2 - w1;

    return Math.tan(w1) * (halfPiW1) + (Math.log(w2 * (Math.cos(w1) / halfPiW1)) / Math.log(2));
}

From source file:Main.java

public static double eval(final String str) {
    return new Object() {
        private int pos = -1, ch;

        void nextChar() {
            ch = (++pos < str.length()) ? str.charAt(pos) : -1;
        }//from   ww  w . j  a v  a2  s  .  c o  m

        boolean eat(int charToEat) {
            while (ch == ' ') {
                nextChar();
            }
            if (ch == charToEat) {
                nextChar();
                return true;
            }
            return false;
        }

        double parse() {
            nextChar();
            double x = parseExpression();
            if (pos < str.length()) {
                throw new IllegalArgumentException("Unexpected: " + (char) ch);
            }
            return x;
        }

        // Grammar:
        // expression = term | expression `+` term | expression `-` term
        // term = factor | term `*` factor | term `/` factor
        // factor = `+` factor | `-` factor | `(` expression `)`
        //        | number | functionName factor | factor `^` factor

        double parseExpression() {
            double x = parseTerm();
            for (;;) {
                if (eat('+')) {
                    x += parseTerm(); // addition
                } else {
                    if (eat('-')) {
                        x -= parseTerm(); // subtraction
                    } else {
                        return x;
                    }
                }
            }
        }

        double parseTerm() {
            double x = parseFactor();
            for (;;) {
                if (eat('*')) {
                    x *= parseFactor(); // multiplication
                } else {
                    if (eat('/')) {
                        x /= parseFactor(); // division
                    } else {
                        return x;
                    }
                }
            }
        }

        double parseFactor() {
            if (eat('+')) {
                return parseFactor(); // unary plus
            }
            if (eat('-')) {
                return -parseFactor(); // unary minus
            }

            double x;
            int startPos = this.pos;
            if (eat('(')) { // parentheses
                x = parseExpression();
                eat(')');
            } else if ((ch >= '0' && ch <= '9') || ch == '.') { // numbers
                while ((ch >= '0' && ch <= '9') || ch == '.') {
                    nextChar();
                }
                x = Double.parseDouble(str.substring(startPos, this.pos));
            } else if (ch >= 'a' && ch <= 'z') { // functions
                while (ch >= 'a' && ch <= 'z') {
                    nextChar();
                }
                String func = str.substring(startPos, this.pos);
                x = parseFactor();
                switch (func) {
                case "sqrt":
                    x = Math.sqrt(x);
                    break;
                case "sin":
                    x = Math.sin(Math.toRadians(x));
                    break;
                case "cos":
                    x = Math.cos(Math.toRadians(x));
                    break;
                case "tan":
                    x = Math.tan(Math.toRadians(x));
                    break;
                default:
                    throw new IllegalArgumentException("Unknown function: " + func);
                }
            } else {
                throw new IllegalArgumentException("Unexpected: " + (char) ch);
            }

            if (eat('^')) {
                x = Math.pow(x, parseFactor()); // exponentiation
            }

            return x;
        }
    }.parse();
}