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.specvis.logic.Functions.java

/**
 * Calculate opposite of the angle.// w w  w.  j av  a  2s  .  c o  m
 * @param a: angle in degrees;
 * @param r:
 * @return: Opposite of the angle;
 */
public double calculateOppositeAngle(double a, double r) {
    /**
     *      Calculation note:
     *
     *      |\
     *      |a\
     *      |  \
     *     r|   \
     *      |    \
     *      |     \
     *      |______\
     *         x
     *
     *      In order to calculate "x" (opposite of the angle "a") one must do:
     *
     *      x = r / cot(a),
     *
     *      where "a" is in radians. Function "cot" can be also
     *      described as "1/tan".
     */

    double x;
    a = Math.toRadians(a);
    x = r / (1 / Math.tan(a));
    return x;
}

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

/**
 * Initializes from geographic coordinates. Note that reference ellipsoid
 * used by Lambert is the Clark ellipsoid.
 *
 * @param lat latitude in grad//from w  w  w.jav a 2s .c o  m
 * @param lon longitude in grad
 * @param Xs  false east (coordinate system origin) in meters
 * @param Ys  false north (coordinate system origin) in meters
 * @param c   projection constant
 * @param n   projection exponent
 * @return EastNorth projected coordinates in meter
 */
private EastNorth ConicProjection(double lat, double lon, double Xs, double Ys, double c, double n) {
    double eslt = Ellipsoid.clarke.e * Math.sin(lat);
    double l = Math.log(Math.tan(Math.PI / 4.0 + (lat / 2.0))
            * Math.pow((1.0 - eslt) / (1.0 + eslt), Ellipsoid.clarke.e / 2.0));
    double east = Xs + c * Math.exp(-n * l) * Math.sin(n * (lon - lg0));
    double north = Ys - c * Math.exp(-n * l) * Math.cos(n * (lon - lg0));
    return new EastNorth(east, north);
}

From source file:SoundBug.java

public void init() {

    // set up a NumFormat object to print out float with only 3 fraction
    // digits/*from w  ww .  j a  v a  2 s.co m*/
    nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(3);

    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    canvas = null;
    canvas = new Canvas3D(config);
    add("Center", canvas);

    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();
    u = new SimpleUniverse(canvas);

    // set up sound
    u.getViewer().createAudioDevice();

    // get the view
    view = u.getViewer().getView();

    // Get the viewing platform
    ViewingPlatform viewingPlatform = u.getViewingPlatform();

    // Move the viewing platform back to enclose the -4 -> 4 range
    double viewRadius = 4.0; // want to be able to see circle
    // of viewRadius size around origin
    // get the field of view
    double fov = u.getViewer().getView().getFieldOfView();

    // calc view distance to make circle view in fov
    float viewDistance = (float) (viewRadius / Math.tan(fov / 2.0));
    tmpVector.set(0.0f, 0.0f, viewDistance);// setup offset
    tmpTrans.set(tmpVector); // set trans to translate
    // move the view platform
    viewingPlatform.getViewPlatformTransform().setTransform(tmpTrans);

    // add an orbit behavior to move the viewing platform
    OrbitBehavior orbit = new OrbitBehavior(canvas, OrbitBehavior.STOP_ZOOM);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    orbit.setSchedulingBounds(bounds);
    viewingPlatform.setViewPlatformBehavior(orbit);

    u.addBranchGraph(scene);

    add("South", soundPanel());
}

From source file:gbt.ubt.tool.Orthorectifier.java

private static double[] calculateShift(double latitude, double terrainHeight, double[] azimuthElevation) {
    /* Note this method is taken from the AATSR data processing model for L1B (topographic corrections section 5.16)
    As the ESA CFI target is closed source, we use the azimuth elevation retrieved using the Orekit library with an orbit
    propagated using state vector contained in the L1b product
    *//*from   w  w  w  .jav  a  2s.  com*/
    double latitudeRadians = latitude * (Math.PI / 180.0);
    double a = Constants.WGS84_EARTH_EQUATORIAL_RADIUS; //semiMajorAxis
    double rf = Constants.WGS84_EARTH_FLATTENING;// reciprocal of flattening
    double b = a * (1 - rf); // semiMinorAxis
    double e1 = Math.pow((1 - (Math.pow(b, 2) / Math.pow(a, 2))), 0.5); //first eccentricity
    double e2sqr = (Math.pow(a, 2) / Math.pow(b, 2) - 1); // secondEccentricitySquared
    double C = 1000.0 * a / Math.pow((1 - Math.pow(e1, 2)), 0.5);
    double N = C / Math.pow((1 + (e2sqr * Math.pow(Math.cos(latitudeRadians), 2))), 0.5);
    double R = N / (1 + (e2sqr * Math.pow(Math.cos(latitudeRadians), 2)));
    double dY = terrainHeight * (1 / Math.tan(azimuthElevation[1])) * Math.cos(azimuthElevation[0]);
    double dX = terrainHeight * (1 / Math.tan(azimuthElevation[1])) * Math.sin(azimuthElevation[0]);
    double[] latLonCorr = new double[2];
    latLonCorr[0] = dY * (180.0 / Math.PI) / R;
    latLonCorr[1] = (dX / Math.cos(latitudeRadians)) * (180.0 / Math.PI) / N;
    return latLonCorr;
}

From source file:com.jiahuan.svgmapview.core.helper.map.SVGParser.java

private static Matrix parseTransformItem(String s, Matrix matrix) {
    if (s.startsWith("matrix(")) {
        NumberParse np = parseNumbers(s.substring("matrix(".length()));
        if (np.numbers.size() == 6) {
            Matrix mat = new Matrix();
            mat.setValues(new float[] {
                    // Row 1
                    np.numbers.get(0), np.numbers.get(2), np.numbers.get(4),
                    // Row 2
                    np.numbers.get(1), np.numbers.get(3), np.numbers.get(5),
                    // Row 3
                    0, 0, 1, });/*from w  w w  .j  a va  2  s.  c  o  m*/
            matrix.preConcat(mat);
        }
    } else if (s.startsWith("translate(")) {
        NumberParse np = parseNumbers(s.substring("translate(".length()));
        if (np.numbers.size() > 0) {
            float tx = np.numbers.get(0);
            float ty = 0;
            if (np.numbers.size() > 1) {
                ty = np.numbers.get(1);
            }
            matrix.preTranslate(tx, ty);
        }
    } else if (s.startsWith("scale(")) {
        NumberParse np = parseNumbers(s.substring("scale(".length()));
        if (np.numbers.size() > 0) {
            float sx = np.numbers.get(0);
            float sy = sx;
            if (np.numbers.size() > 1) {
                sy = np.numbers.get(1);
            }
            matrix.preScale(sx, sy);
        }
    } else if (s.startsWith("skewX(")) {
        NumberParse np = parseNumbers(s.substring("skewX(".length()));
        if (np.numbers.size() > 0) {
            float angle = np.numbers.get(0);
            matrix.preSkew((float) Math.tan(angle), 0);
        }
    } else if (s.startsWith("skewY(")) {
        NumberParse np = parseNumbers(s.substring("skewY(".length()));
        if (np.numbers.size() > 0) {
            float angle = np.numbers.get(0);
            matrix.preSkew(0, (float) Math.tan(angle));
        }
    } else if (s.startsWith("rotate(")) {
        NumberParse np = parseNumbers(s.substring("rotate(".length()));
        if (np.numbers.size() > 0) {
            float angle = np.numbers.get(0);
            float cx = 0;
            float cy = 0;
            if (np.numbers.size() > 2) {
                cx = np.numbers.get(1);
                cy = np.numbers.get(2);
            }
            matrix.preTranslate(-cx, -cy);
            matrix.preRotate(angle);
            matrix.preTranslate(cx, cy);
        }
    } else {
        Log.w(TAG, "Invalid transform (" + s + ")");
    }
    return matrix;
}

From source file:LightBug.java

public LightBug() {

    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    Canvas3D c = new Canvas3D(config);
    add("Center", c);

    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();
    u = new SimpleUniverse(c);

    // Get the viewing platform
    ViewingPlatform viewingPlatform = u.getViewingPlatform();

    // Move the viewing platform back to enclose the -4 -> 4 range
    double viewRadius = 4.0; // want to be able to see circle
    // of viewRadius size around origin
    // get the field of view
    double fov = u.getViewer().getView().getFieldOfView();

    // calc view distance to make circle view in fov
    float viewDistance = (float) (viewRadius / Math.tan(fov / 2.0));
    tmpVector.set(0.0f, 0.0f, viewDistance);// setup offset
    tmpTrans.set(tmpVector); // set trans to translate
    // move the view platform
    viewingPlatform.getViewPlatformTransform().setTransform(tmpTrans);

    // add an orbit behavior to move the viewing platform
    OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.STOP_ZOOM);
    orbit.setMinRadius(0.5);//from www .j a  v  a 2s .  co  m
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    orbit.setSchedulingBounds(bounds);
    viewingPlatform.setViewPlatformBehavior(orbit);

    u.addBranchGraph(scene);

    add("South", lightPanel());
}

From source file:org.netxilia.functions.MathFunctions.java

public double TAN(double number) {
    return Math.tan(number);
}

From source file:eu.hansolo.tilesfx.tools.Location.java

public double calcBearingInDegree(final double LAT_1, final double LON_1, final double LAT_2,
        final double LON_2) {
    double lat1 = Math.toRadians(LAT_1);
    double lon1 = Math.toRadians(LON_1);
    double lat2 = Math.toRadians(LAT_2);
    double lon2 = Math.toRadians(LON_2);
    double deltaLon = lon2 - lon1;
    double deltaPhi = Math.log(Math.tan(lat2 * 0.5 + Math.PI * 0.25) / Math.tan(lat1 * 0.5 + Math.PI * 0.25));
    if (Math.abs(deltaLon) > Math.PI) {
        if (deltaLon > 0) {
            deltaLon = -(2.0 * Math.PI - deltaLon);
        } else {// www . j a va  2 s.c o  m
            deltaLon = (2.0 * Math.PI + deltaLon);
        }
    }
    double bearing = (Math.toDegrees(Math.atan2(deltaLon, deltaPhi)) + 360.0) % 360.0;
    return bearing;
}

From source file:com.rapidminer.tools.expression.internal.function.AntlrParserTrigonometricTest.java

@Test
public void tanInt() {
    try {// ww  w  .j a  va2 s  . c  om
        Expression expression = getExpressionWithFunctionContext("tan(16)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.tan(16), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:ExDepthCue.java

public Shape3D buildSurface(double freqAlpha, double freqTheta, double radius, float red, float green,
        float blue) {
    int nAngles = 64;
    double amp = radius / 4.0;

    int nAlpha = nAngles / 2;
    double theta, alpha;
    double x, y, z, rprime, r;
    double deltaTheta, deltaAlpha;
    int i, j;//from   w  ww.ja  v a  2  s .c  o m
    int i1, i2, i3, i4;

    deltaTheta = 360.0 / (nAngles - 1.0);
    deltaAlpha = 180.0 / (nAlpha - 1.0);

    // Build an appearance
    Appearance app = new Appearance();

    LineAttributes latt = new LineAttributes();
    latt.setLineWidth(1.0f);
    app.setLineAttributes(latt);

    ColoringAttributes catt = new ColoringAttributes();
    catt.setColor(red, green, blue);
    app.setColoringAttributes(catt);

    PolygonAttributes patt = new PolygonAttributes();
    patt.setCullFace(PolygonAttributes.CULL_NONE);
    patt.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    app.setPolygonAttributes(patt);

    // Compute coordinates
    double[] coordinates = new double[nAlpha * nAngles * 3];
    alpha = 90.0;
    int n = 0;
    for (i = 0; i < nAlpha; i++) {
        theta = 0.0;
        for (j = 0; j < nAngles; j++) {
            r = radius + amp * Math.sin((freqAlpha * ((double) i / (double) (nAlpha - 1))
                    + freqTheta * ((double) j / (double) (nAngles - 1))) * 2.0 * Math.PI);
            y = r * Math.sin(alpha / 180.0 * Math.PI);
            rprime = y / Math.tan(alpha / 180.0 * Math.PI);
            x = rprime * Math.cos(theta / 180.0 * Math.PI);
            z = rprime * Math.sin(theta / 180.0 * Math.PI);

            coordinates[n + 0] = x;
            coordinates[n + 1] = y;
            coordinates[n + 2] = z;
            n += 3;
            theta += deltaTheta;
        }
        alpha -= deltaAlpha;
    }

    // Compute coordinate indexes
    int[] indexes = new int[(nAlpha - 1) * nAngles * 4];
    n = 0;
    for (i = 0; i < nAlpha - 1; i++) {
        for (j = 0; j < nAngles; j++) {
            i1 = i * nAngles + j;
            if (j == nAngles - 1) {
                i2 = i1 - j;
                i3 = (i + 1) * nAngles;
            } else {
                i2 = i1 + 1;
                i3 = (i + 1) * nAngles + j + 1;
            }
            i4 = (i + 1) * nAngles + j;

            indexes[n + 0] = i1;
            indexes[n + 1] = i2;
            indexes[n + 2] = i3;
            indexes[n + 3] = i4;
            n += 4;
        }
    }

    // Build the shape
    IndexedQuadArray lines = new IndexedQuadArray(coordinates.length / 3, // Number
            // of
            // coordinates
            GeometryArray.COORDINATES, // coordinates only
            indexes.length); // Number of indexes
    lines.setCoordinates(0, coordinates);
    lines.setCoordinateIndices(0, indexes);

    Shape3D shape = new Shape3D(lines, app);

    return shape;
}