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.eclipse.smarthome.binding.astro.internal.calc.SunCalc.java

private double getShadeLength(double elevation) {
    return 1 / Math.tan(elevation * DEG2RAD);
}

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

@Test
public void cotInt() {
    try {// w ww  .j  av a  2 s  .  com
        Expression expression = getExpressionWithFunctionContext("cot(16)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(1.0 / Math.tan(16), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:TexBug.java

public void init() {

    // initialize the code base
    try {/*from  ww w .j av  a2s .c o  m*/
        java.net.URL codeBase = getCodeBase();
        codeBaseString = codeBase.toString();
    } catch (Exception e) {
        // probably running as an application, try the application
        // code base
        codeBaseString = "file:./";
    }

    // set up a NumFormat object to print out float with only 3 fraction
    // digits
    nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(3);

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

    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 -2 -> 2 range
    double viewRadius = 2.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);
    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", guiPanel());
}

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

@Test
public void cotDouble() {
    try {//from   w  ww.jav a  2  s.c o m
        Expression expression = getExpressionWithFunctionContext("cot(33.3)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(1.0 / Math.tan(33.3), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

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

@Test
public void cotNegative() {
    try {//from   w ww  .  j  a va2s. c  o  m
        Expression expression = getExpressionWithFunctionContext("cot(-10)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(1.0 / Math.tan(-10), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:org.esa.nest.eo.GeoUtils.java

/**
 * // Given starting (GLON1,GLAT1) and end points (GLON2,GLAT2)
 * // calculate distance in meters and initial headings from start to
 * // end (return variable head1),//from   w w w  . j  a  v  a  2 s. c  o m
 * // and from end to start point (return variable head2)
 * <p/>
 * // Input:
 * // lon1:   longitude
 * // lat1:   latitude
 * // lon2:   longitude
 * // lat2:   latitude
 * <p/>
 * // Output:
 * // dist:   distance in m
 * // head1:   azimuth in degrees mesured in the direction North east south west
 * //         from (lon1,lat1) to (lon2, lat2)
 * // head2:   azimuth in degrees mesured in the direction North east south west
 * //         from (lon2,lat2) to (lon1, lat1)
 * @param lon1
 * @param lat1
 * @param lon2
 * @param lat2
 * @return
 */
public static DistanceHeading vincenty_inverse(double lon1, double lat1, double lon2, double lat2) {

    final DistanceHeading output = new DistanceHeading();

    if ((Math.abs(lon1 - lon2) < EPS5) && (Math.abs(lat1 - lat2) < EPS5)) {
        output.distance = 0;
        output.heading1 = -1;
        output.heading2 = -1;
        return output;
    }

    lat1 *= org.esa.beam.util.math.MathUtils.DTOR;
    lat2 *= org.esa.beam.util.math.MathUtils.DTOR;
    lon1 *= org.esa.beam.util.math.MathUtils.DTOR;
    lon2 *= org.esa.beam.util.math.MathUtils.DTOR;

    // Model WGS84:
    //    F=1/298.25722210;   // flattening
    final double F = 0.0; //defF;

    final double R = 1 - F;
    double TU1 = R * Math.tan(lat1);
    double TU2 = R * Math.tan(lat2);
    final double CU1 = 1.0 / Math.sqrt(TU1 * TU1 + 1.0);
    final double SU1 = CU1 * TU1;
    final double CU2 = 1.0 / Math.sqrt(TU2 * TU2 + 1.0);
    double S = CU1 * CU2;
    double BAZ = S * TU2;
    double FAZ = BAZ * TU1;
    double X = lon2 - lon1;

    double SX, CX, SY, CY, Y, SA, C2A, CZ, E, C, D;
    do {
        SX = Math.sin(X);
        CX = Math.cos(X);
        TU1 = CU2 * SX;
        TU2 = BAZ - SU1 * CU2 * CX;
        SY = Math.sqrt(TU1 * TU1 + TU2 * TU2);
        CY = S * CX + FAZ;
        Y = Math.atan2(SY, CY);
        SA = S * SX / SY;
        C2A = -SA * SA + 1.;
        CZ = FAZ + FAZ;
        if (C2A > 0.)
            CZ = -CZ / C2A + CY;
        E = CZ * CZ * 2. - 1.;
        C = ((-3. * C2A + 4.) * F + 4.) * C2A * F / 16.;
        D = X;
        X = ((E * CY * C + CZ) * SY * C + Y) * SA;
        X = (1. - C) * X * F + lon2 - lon1;
    } while (Math.abs(D - X) > (0.01));

    FAZ = Math.atan2(TU1, TU2);
    BAZ = Math.atan2(CU1 * SX, BAZ * CX - SU1 * CU2) + Math.PI;
    X = Math.sqrt((1. / R / R - 1.) * C2A + 1.) + 1.;
    X = (X - 2.) / X;
    C = 1. - X;
    C = (X * X / 4. + 1.) / C;
    D = (0.375 * X * X - 1.) * X;
    X = E * CY;
    S = 1. - E - E;
    S = ((((SY * SY * 4. - 3.) * S * CZ * D / 6. - X) * D / 4. + CZ) * SY * D + Y) * C * WGS84.a * R;

    output.distance = S;
    output.heading1 = FAZ * org.esa.beam.util.math.MathUtils.RTOD;
    output.heading2 = BAZ * org.esa.beam.util.math.MathUtils.RTOD;

    while (output.heading1 < 0)
        output.heading1 += 360;
    while (output.heading2 < 0)
        output.heading2 += 360;

    return output;
}

From source file:fr.amap.viewer3d.object.camera.TrackballCamera.java

public void translateV2(Vec3F translation) {

    forwardVec = getForwardVector();//from ww  w  .  ja va2 s.  co  m

    //slow down relatively from the length of the forward vector
    if (perspective) {
        translation = Vec3F.multiply(translation, (Vec3F.length(forwardVec) / (float) Math.tan(fovy)) * 0.001f);
    } else {
        translation = Vec3F.multiply(translation, Vec3F.length(forwardVec) * 0.0025f);
    }

    forwardVec = Vec3F.normalize(forwardVec);

    rightVec = getRightVector();
    upVec = getUpVector();

    Vec3F xTranslation = Vec3F.multiply(rightVec, -translation.x);
    Vec3F yTranslation = Vec3F.multiply(upVec, translation.y);

    Vec3F translationVec = Vec3F.add(xTranslation, yTranslation);

    location = Vec3F.add(translationVec, location);
    target = Vec3F.add(translationVec, target);

    updateViewMatrix();
}

From source file:org.mdc.chess.ChessBoard.java

private void drawMoveHints(Canvas canvas) {
    if ((moveHints == null) || blindMode) {
        return;//from  w w w  .  jav a2 s.  com
    }
    float h = (float) (sqSize / 2.0);
    float d = (float) (sqSize / 8.0);
    double v = 35 * Math.PI / 180;
    double cosv = Math.cos(v);
    double sinv = Math.sin(v);
    double tanv = Math.tan(v);
    int n = Math.min(moveMarkPaint.size(), moveHints.size());
    for (int i = 0; i < n; i++) {
        Move m = moveHints.get(i);
        if ((m == null) || (m.from == m.to)) {
            continue;
        }
        float x0 = getXCrd(Position.getX(m.from)) + h;
        float y0 = getYCrd(Position.getY(m.from)) + h;
        float x1 = getXCrd(Position.getX(m.to)) + h;
        float y1 = getYCrd(Position.getY(m.to)) + h;

        float x2 = (float) (Math.hypot(x1 - x0, y1 - y0) + d);
        float y2 = 0;
        float x3 = (float) (x2 - h * cosv);
        float y3 = (float) (y2 - h * sinv);
        float x4 = (float) (x3 - d * sinv);
        float y4 = (float) (y3 + d * cosv);
        float x5 = (float) (x4 + (-d / 2 - y4) / tanv);
        float y5 = -d / 2;
        float x6 = 0;
        float y6 = y5 / 2;
        Path path = new Path();
        path.moveTo(x2, y2);
        path.lineTo(x3, y3);
        //          path.lineTo(x4, y4);
        path.lineTo(x5, y5);
        path.lineTo(x6, y6);
        path.lineTo(x6, -y6);
        path.lineTo(x5, -y5);
        //          path.lineTo(x4, -y4);
        path.lineTo(x3, -y3);
        path.close();
        Matrix mtx = new Matrix();
        mtx.postRotate((float) (Math.atan2(y1 - y0, x1 - x0) * 180 / Math.PI));
        mtx.postTranslate(x0, y0);
        path.transform(mtx);
        Paint p = moveMarkPaint.get(i);
        canvas.drawPath(path, p);
    }
}

From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java

public static BufferedImage sphericalMapping(BufferedImage img, double f) {
    if (img == null) {
        return null;
    }//from w  ww  . jav  a2s  .com

    int w = img.getWidth();
    int h = img.getHeight();
    BufferedImage out = new BufferedImage(w, h, img.getType());
    //System.out.println("w:"+w+", h:"+h);

    int x0 = (int) Math.floor(w / 2) + 1;
    int y0 = (int) Math.floor(h / 2) + 1;

    double tmax = Math.atan2((double) (w - x0), f);
    double tmin = Math.atan2(-((double) x0), f);
    double tstep = (tmax - tmin) / ((double) w);

    double fimax = Math.atan2((double) (h - y0), Math.sqrt(f * f));
    double fimin = Math.atan2(-(double) y0, Math.sqrt(f * f));
    double fistep = (fimax - fimin) / ((double) h);
    //System.out.println("fimax:"+fimax+", fimin:"+fimin);

    double theta, tantheta, costheta, tanfi, phi;
    int x, y;

    for (int t = 0; t < w; t++) {
        theta = tmin + (double) t * tstep;
        tantheta = Math.tan(theta);
        x = (int) Math.round(f * tantheta) + x0;
        for (int fi = 0; fi < h; fi++) {
            //nearest neighbour---------------------------------------
            phi = fimin + (double) fi * fistep;
            tanfi = Math.tan(phi);
            //x = (int)Math.round(f*tantheta) + x0;
            y = (int) Math.round(Math.sqrt((x - x0) * (x - x0) + f * f) * tanfi) + y0;
            if (x >= 0 && y >= 0 && x < w && y < h) {
                //piksel nowy x,y = piksel stary xd,yd
                out.setRGB(t, fi, img.getRGB(x, y));
            }
            //---------------------------------------------------------
        }
    }
    return out;
}

From source file:com.larvalabs.svgandroid.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   ww  w  .  j av a  2  s .  co  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.i(TAG, "Invalid transform (" + s + ")");
    }
    return matrix;
}