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

private double getAzimuth(double th, double a, double phi, double d) {
    double H = th - a;
    return Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(phi) - Math.tan(d) * Math.cos(phi));
}

From source file:se.llbit.chunky.renderer.scene.Sun.java

private void updateSkylightValues() {
    double sunTheta = Math.PI / 2 - altitude;
    double cosTheta = FastMath.cos(sunTheta);
    double cos2Theta = cosTheta * cosTheta;
    double chi = (4.0 / 9.0 - turb / 120.0) * (Math.PI - 2 * sunTheta);
    zenith_Y = (4.0453 * turb - 4.9710) * Math.tan(chi) - 0.2155 * turb + 2.4192;
    zenith_Y = (zenith_Y < 0) ? -zenith_Y : zenith_Y;
    zenith_x = chroma(turb, turb2, sunTheta, xZenithChroma);
    zenith_y = chroma(turb, turb2, sunTheta, yZenithChroma);
    f0_x = 1 / perezF(1, sunTheta, cos2Theta, A.x, B.x, C.x, D.x, E.x);
    f0_y = 1 / perezF(1, sunTheta, cos2Theta, A.y, B.y, C.y, D.y, E.y);
    f0_Y = 1 / perezF(1, sunTheta, cos2Theta, A.z, B.z, C.z, D.z, E.z);
}

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

@Test
public void tanDouble() {
    try {/*from  ww  w .j av a 2 s.co m*/
        Expression expression = getExpressionWithFunctionContext("tan(33.3)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(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 tanNegative() {
    try {/* w  w w .  j a v  a2  s  . c o m*/
        Expression expression = getExpressionWithFunctionContext("tan(-10)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.tan(-10), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:ViewProj.java

public BranchGroup createVWorldViewSG() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();
    objRoot.setCapability(BranchGroup.ALLOW_DETACH);

    // setup a transform group to hold the scaled scene
    TransformGroup objTrans = new TransformGroup();
    objRoot.addChild(objTrans);/*from   ww  w.j  av a  2  s .  c o m*/

    // get the eye point, field of view and clip distances
    float fov = (float) view.getFieldOfView();

    // figure out the angle factors to find points along the edges
    // of the FOV
    // X = fovSpreadX * (Y - eyeVW.y) + eyeVW.x;
    float fovSpreadX = (float) Math.tan(fov / 2);
    // Z = fovSpreadZ * (X - eyeVW.x) + eyeVW.z;
    float fovSpreadZ = 1.0f / fovSpreadX;
    //System.out.println("fovSpreadX = " + fovSpreadX);
    //System.out.println("fovSpreadZ = " + fovSpreadZ);

    Transform3D vpTransform = new Transform3D();
    viewingPlatform.getViewPlatformTransform().getTransform(vpTransform);
    Vector3f vpTranslation = new Vector3f();
    vpTransform.get(vpTranslation);
    eyePtVW.set(vpTranslation);
    eyePtVW.negate();
    // get the eye point in our 2D coord system.
    Point3f eyePt = new Point3f(0.0f, eyePtVW.z, 0.1f);
    float frontClipDist = (float) view.getFrontClipDistance();
    float backClipDist = (float) view.getBackClipDistance();

    // set up the clip plane lines
    Point3f[] cpPoints = new Point3f[5];
    cpPoints[0] = new Point3f(frontClipDist * fovSpreadX, eyePtVW.z + frontClipDist, 0.1f);
    cpPoints[1] = new Point3f(cpPoints[0]);
    cpPoints[1].x *= -1;
    Point3f backLeft = new Point3f(-backClipDist * fovSpreadX, eyePtVW.z + backClipDist, 0.1f);
    cpPoints[2] = backLeft;
    Point3f backRight = new Point3f(backLeft);
    backRight.x *= -1;
    cpPoints[3] = backRight;
    cpPoints[4] = cpPoints[0];
    //for (int i = 0; i < 4; i++) {
    //    System.out.println("cpPoints[" + i + "] = " + cpPoints[i]);
    //}
    int[] cpLength = new int[1];
    cpLength[0] = 5;
    LineStripArray cpLines = new LineStripArray(5, LineArray.COORDINATES, cpLength);
    cpLines.setCoordinates(0, cpPoints);
    Appearance cpApp = new Appearance();
    ColoringAttributes cpCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT);
    cpApp.setColoringAttributes(cpCa);
    Shape3D cpShape = new Shape3D(cpLines, cpApp);
    objTrans.addChild(cpShape);

    // get the limits of the space
    float minY = eyePt.y;
    float maxY = backLeft.y;
    float minX = backLeft.x;
    float maxX = backRight.x;

    // figure out the X and Y extents and offsets
    float deltaX = maxX - minX;
    float deltaY = maxY - minY;
    float offsetX = -(maxX + minX) / 2.0f;
    float offsetY = -(maxY + minY) / 2.0f;
    float gridSize = Math.max(deltaX, deltaY);

    // scale the grid slightly to give a border around the edge
    gridSize *= 1.1f;

    //System.out.println("offsetX = " + offsetX);
    //System.out.println("offsetY = " + offsetY);

    // Scale the view to fit -1 to 1
    Transform3D trans = new Transform3D();
    trans.set(new Vector3f(offsetX, offsetY, 0.0f), 2.0f / gridSize);
    objTrans.setTransform(trans);

    // figure out a grid step that is a multiple of 10 which keeps the
    // number of steps less than 30.
    float gridStep = 1.0f;
    while ((gridSize / gridStep) > 30.0) {
        gridStep *= 10;
    }
    int gridNumSteps = (int) Math.ceil(gridSize / gridStep) + 1;

    // allocate the grid points array, four points for each step (x and y)
    // with a couple extra points for the extra grid points added
    // below
    int gridNumPoints = 4 * (gridNumSteps + 4);
    Point3f[] gridPts = new Point3f[gridNumPoints];
    for (int i = 0; i < gridNumPoints; i++) {
        gridPts[i] = new Point3f();
    }

    // find the grid limits. Add a step on each side to make sure
    // the grid is larger than the view
    float gridMinY = gridStepFloor(minY, gridStep) - gridStep;
    float gridMaxY = gridStepCeil(maxY, gridStep) + gridStep;
    float gridMinX = gridStepFloor(minX, gridStep) - gridStep;
    float gridMaxX = gridStepCeil(maxX, gridStep) + gridStep;
    //System.out.println("gridMinY = " + gridMinY);
    //System.out.println("gridMaxY = " + gridMaxY);
    //System.out.println("gridMinX = " + gridMinX);
    //System.out.println("gridMaxX = " + gridMaxX);

    // set up the background grid
    Appearance bgApp = new Appearance();
    ColoringAttributes bgCa = new ColoringAttributes();
    bgCa.setColor(grey);
    LineAttributes bgLa = new LineAttributes();
    bgApp.setColoringAttributes(bgCa);

    // clear out the clip grid point list
    numClipGridPts = 0;

    // set up the vertical lines
    int numPts = 0;
    for (float x = gridMinX; x <= gridMaxX; x += gridStep) {
        gridPts[numPts].x = x;
        gridPts[numPts].y = gridMinY;
        gridPts[numPts].z = -0.2f;
        gridPts[numPts + 1].x = x;
        gridPts[numPts + 1].y = gridMaxY;
        gridPts[numPts + 1].z = -0.2f;
        numPts += 2;

        // try to add a line to the clipped grid
        // find the intersection of the clipped line with the FOV sides
        // this is a distance relative to the eye
        float clipZ = fovSpreadZ * Math.abs(x - eyePtVW.x);
        if (clipZ < frontClipDist) { // clip to front clip plane
            clipZ = frontClipDist;
        }
        if (clipZ < backClipDist) { // clip to back clip plane
            // line is not clipped
            clipGridPtsVW[numClipGridPts].x = x;
            clipGridPtsVW[numClipGridPts].y = clipZ + eyePtVW.z;
            clipGridPtsVW[numClipGridPts].z = -0.1f;
            clipGridPtsVW[numClipGridPts + 1].x = x;
            clipGridPtsVW[numClipGridPts + 1].y = backClipDist + eyePtVW.z;
            clipGridPtsVW[numClipGridPts + 1].z = -0.1f;
            numClipGridPts += 2;
        }
    }
    LineArray vertLa = new LineArray(numPts, LineArray.COORDINATES);
    vertLa.setCoordinates(0, gridPts, 0, numPts);
    Shape3D vertShape = new Shape3D(vertLa, bgApp);
    objTrans.addChild(vertShape);

    // set up the horizontal lines
    numPts = 0;
    for (float y = gridMinY; y <= gridMaxY; y += gridStep) {
        gridPts[numPts].x = gridMinX;
        gridPts[numPts].y = y;
        gridPts[numPts++].z = -0.2f;
        gridPts[numPts].x = gridMaxX;
        gridPts[numPts].y = y;
        gridPts[numPts++].z = -0.2f;

        // try to add a line to the clipped grid
        // find the intersection of the clipped line with the FOV sides
        // this is a distance relative to the eye
        float clipDist = (y - eyePtVW.z);
        if ((clipDist > frontClipDist) && (clipDist < backClipDist)) {

            float clipX = fovSpreadX * clipDist;
            clipGridPtsVW[numClipGridPts].x = -clipX;
            clipGridPtsVW[numClipGridPts].y = y;
            clipGridPtsVW[numClipGridPts].z = -0.1f;
            clipGridPtsVW[numClipGridPts + 1].x = clipX;
            clipGridPtsVW[numClipGridPts + 1].y = y;
            clipGridPtsVW[numClipGridPts + 1].z = -0.1f;
            numClipGridPts += 2;
        }
    }
    LineArray horizLa = new LineArray(numPts, LineArray.COORDINATES);
    horizLa.setCoordinates(0, gridPts, 0, numPts);
    Shape3D horizShape = new Shape3D(horizLa, bgApp);
    objTrans.addChild(horizShape);

    // draw the clipped grid.
    if (numClipGridPts > 0) {
        LineArray clipLa = new LineArray(numClipGridPts, LineArray.COORDINATES);
        clipLa.setCoordinates(0, clipGridPtsVW, 0, numClipGridPts);
        Appearance clipGridApp = new Appearance();
        ColoringAttributes clipCa = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT);
        clipGridApp.setColoringAttributes(clipCa);
        LineAttributes clipGridLa = new LineAttributes();
        Shape3D clipShape = new Shape3D(clipLa, clipGridApp);
        objTrans.addChild(clipShape);
    }

    // set up the coordinate system
    Appearance coordSysApp = new Appearance();
    LineAttributes coordSysLa = new LineAttributes();
    coordSysLa.setLineWidth(3.0f);
    coordSysApp.setLineAttributes(coordSysLa);
    ColoringAttributes coordSysCa = new ColoringAttributes(grey, ColoringAttributes.SHADE_FLAT);
    coordSysApp.setColoringAttributes(coordSysCa);
    Point3f[] coordSysPts = new Point3f[4];
    coordSysPts[0] = new Point3f(gridMinX, 0, -0.5f);
    coordSysPts[1] = new Point3f(gridMaxX, 0, -0.5f);
    coordSysPts[2] = new Point3f(0, gridMinY, -0.5f);
    coordSysPts[3] = new Point3f(0, gridMaxY, -0.5f);
    LineArray coordSysLines = new LineArray(4, LineArray.COORDINATES);
    coordSysLines.setCoordinates(0, coordSysPts);
    Shape3D coordSysShape = new Shape3D(coordSysLines, coordSysApp);
    objTrans.addChild(coordSysShape);

    // set up the circle
    Appearance circleApp = new Appearance();
    ColoringAttributes circleCa = new ColoringAttributes();
    circleCa.setColor(red);
    circleApp.setColoringAttributes(circleCa);
    PolygonAttributes pa = new PolygonAttributes();
    pa.setCullFace(PolygonAttributes.CULL_NONE);
    circleApp.setPolygonAttributes(pa);
    int step = 360 / (numCirclePts - 1);
    for (int deg = 0; deg < 360; deg += step) {
        double angle = Math.toRadians(deg);
        circlePtsVW[deg / 10].x = sphereRadius * (float) Math.sin(angle);
        circlePtsVW[deg / 10].y = sphereRadius * (float) Math.cos(angle);
        circlePtsVW[deg / 10].z = -0.3f;
    }
    circlePtsVW[numCirclePts - 1].set(circlePtsVW[0]);
    int[] lineStripLength = new int[1];
    lineStripLength[0] = numCirclePts;
    //LineStripArray circleLineStrip = new LineStripArray(numCirclePts,
    //        LineArray.COORDINATES, lineStripLength);
    TriangleFanArray circleLineStrip = new TriangleFanArray(numCirclePts, LineArray.COORDINATES,
            lineStripLength);
    circleLineStrip.setCoordinates(0, circlePtsVW);
    Shape3D circleShape = new Shape3D(circleLineStrip, circleApp);
    objTrans.addChild(circleShape);

    return objRoot;
}

From source file:org.apache.sysml.runtime.functionobjects.Builtin.java

public double execute(double in) throws DMLRuntimeException {
    switch (bFunc) {
    case SIN:/*from  w  ww .  java 2s . co m*/
        return FASTMATH ? FastMath.sin(in) : Math.sin(in);
    case COS:
        return FASTMATH ? FastMath.cos(in) : Math.cos(in);
    case TAN:
        return FASTMATH ? FastMath.tan(in) : Math.tan(in);
    case ASIN:
        return FASTMATH ? FastMath.asin(in) : Math.asin(in);
    case ACOS:
        return FASTMATH ? FastMath.acos(in) : Math.acos(in);
    case ATAN:
        return Math.atan(in); //faster in Math
    case CEIL:
        return FASTMATH ? FastMath.ceil(in) : Math.ceil(in);
    case FLOOR:
        return FASTMATH ? FastMath.floor(in) : Math.floor(in);
    case LOG:
        return FASTMATH ? FastMath.log(in) : Math.log(in);
    case LOG_NZ:
        return (in == 0) ? 0 : FASTMATH ? FastMath.log(in) : Math.log(in);
    case ABS:
        return Math.abs(in); //no need for FastMath         
    case SIGN:
        return FASTMATH ? FastMath.signum(in) : Math.signum(in);
    case SQRT:
        return Math.sqrt(in); //faster in Math      
    case EXP:
        return FASTMATH ? FastMath.exp(in) : Math.exp(in);
    case ROUND:
        return Math.round(in); //no need for FastMath

    case PLOGP:
        if (in == 0.0)
            return 0.0;
        else if (in < 0)
            return Double.NaN;
        else
            return (in * (FASTMATH ? FastMath.log(in) : Math.log(in)));

    case SPROP:
        //sample proportion: P*(1-P)
        return in * (1 - in);

    case SIGMOID:
        //sigmoid: 1/(1+exp(-x))
        return FASTMATH ? 1 / (1 + FastMath.exp(-in)) : 1 / (1 + Math.exp(-in));

    case SELP:
        //select positive: x*(x>0)
        return (in > 0) ? in : 0;

    default:
        throw new DMLRuntimeException("Builtin.execute(): Unknown operation: " + bFunc);
    }
}

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

public void testTan() {
    System.gc();//  w  ww.  ja  v a 2s  .  c  o  m
    double x = 0;
    long time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        x += StrictMath.tan(i * F1);
    long strictTime = System.nanoTime() - time;

    System.gc();
    double y = 0;
    time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        y += FastMath.tan(i * F1);
    long fastTime = System.nanoTime() - time;

    System.gc();
    double z = 0;
    time = System.nanoTime();
    for (int i = 0; i < RUNS; i++)
        z += Math.tan(i * F1);
    long mathTime = System.nanoTime() - time;

    report("tan", x + y + z, strictTime, fastTime, mathTime);
}

From source file:com.googlecode.eyesfree.widget.RadialMenuView.java

/**
 * Re-draw cached wedge bitmaps.//from  w  w  w  .j  a  v  a 2  s  .co m
 */
private void invalidateCachedWedgeShapes() {
    final RadialMenu menu = mSubMenu != null ? mSubMenu : mRootMenu;
    final int menuSize = menu.size();
    if (menuSize <= 0) {
        return;
    }

    final float wedgeArc = (360.0f / menuSize);
    final float offsetArc = ((wedgeArc / 2.0f) + 90.0f);
    final float spacingArc = (float) Math.toDegrees(Math.tan(mSpacing / (double) mOuterRadius));
    final float spacingExtremeArc = (float) Math.toDegrees(Math.tan(mSpacing / (double) mExtremeRadius));
    final float left = (wedgeArc - spacingArc - offsetArc);
    final float leftExtreme = (wedgeArc - spacingExtremeArc - offsetArc);
    final float center = ((wedgeArc / 2.0f) - offsetArc);
    final float right = (spacingArc - offsetArc);
    final float rightExtreme = (spacingExtremeArc - offsetArc);

    // Outer wedge.
    mCachedOuterPath.rewind();
    mCachedOuterPath.arcTo(mCachedOuterBound, center, (left - center));
    mCachedOuterPath.arcTo(mCachedExtremeBound, left, (right - left));
    mCachedOuterPath.arcTo(mCachedOuterBound, right, (center - right));
    mCachedOuterPath.close();

    mCachedOuterPathWidth = arcLength((left - right), mExtremeRadius);

    // Outer wedge in reverse, for rendering text.
    mCachedOuterPathReverse.rewind();
    mCachedOuterPathReverse.arcTo(mCachedOuterBound, center, (right - center));
    mCachedOuterPathReverse.arcTo(mCachedExtremeBound, right, (left - right));
    mCachedOuterPathReverse.arcTo(mCachedOuterBound, left, (center - left));
    mCachedOuterPathReverse.close();
}

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

/**
 // Given starting point GLON1,GLAT1, head1 = initial heading,and distance
 // in meters, calculate destination GLON2,GLAT2, and head2=initial heading
 // from destination to starting point//from  ww  w. j a va  2  s. c  o m
        
 // Input:
 // lon1:   longitude
 // lat1:   latitude
 // dist:   distance in m
 // head1:   azimuth in degree measured in the diretion North east south west
        
 // Output:
 // GLON2:   longitude
 // GLAT2:   latitude
 // head2:   azimuth in degree measured in the direction North east south west
 //         from (GLON2,GLAT2) to (GLON1, GLAT1)
 * @param lon1
 * @param lat1
 * @param dist
 * @param head1
 * @return
 */
public static LatLonHeading vincenty_direct(double lon1, double lat1, final double dist, final double head1) {

    final LatLonHeading pos = new LatLonHeading();

    lat1 *= org.esa.beam.util.math.MathUtils.DTOR;
    lon1 *= org.esa.beam.util.math.MathUtils.DTOR;
    final double FAZ = head1 * org.esa.beam.util.math.MathUtils.DTOR;

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

    // equatorial radius
    final double R = 1.0 - F;
    double TU = R * Math.tan(lat1);
    final double SF = Math.sin(FAZ);
    final double CF = Math.cos(FAZ);
    double BAZ = 0.0;
    if (CF != 0.0)
        BAZ = Math.atan2(TU, CF) * 2.0;
    final double CU = 1.0 / Math.sqrt(TU * TU + 1.0);
    final double SU = TU * CU;
    final double SA = CU * SF;
    final double C2A = -SA * SA + 1.0;
    double X = Math.sqrt((1.0 / R / R - 1.0) * C2A + 1.0) + 1.0;
    X = (X - 2.0) / X;
    double C = 1.0 - X;
    C = (X * X / 4.0 + 1) / C;
    double D = (0.375 * X * X - 1.0) * X;
    TU = dist / R / WGS84.a / C;
    double Y = TU;

    double SY, CY, CZ, E;
    do {
        SY = Math.sin(Y);
        CY = Math.cos(Y);
        CZ = Math.cos(BAZ + Y);
        E = CZ * CZ * 2.0 - 1.0;
        C = Y;
        X = E * CY;
        Y = E + E - 1.0;
        Y = (((SY * SY * 4.0 - 3.0) * Y * CZ * D / 6.0 + X) * D / 4.0 - CZ) * SY * D + TU;
    } while (Math.abs(Y - C) > EPS);

    BAZ = CU * CY * CF - SU * SY;
    C = R * Math.sqrt(SA * SA + BAZ * BAZ);
    D = SU * CY + CU * SY * CF;
    pos.lat = Math.atan2(D, C);
    C = CU * CY - SU * SY * CF;
    X = Math.atan2(SY * SF, C);
    C = ((-3.0 * C2A + 4.0) * F + 4.0) * C2A * F / 16.0;
    D = ((E * CY * C + CZ) * SY * C + Y) * SA;
    pos.lon = lon1 + X - (1.0 - C) * D * F;
    BAZ = Math.atan2(SA, BAZ) + Math.PI;

    pos.lon *= org.esa.beam.util.math.MathUtils.RTOD;
    pos.lat *= org.esa.beam.util.math.MathUtils.RTOD;
    pos.heading = BAZ * org.esa.beam.util.math.MathUtils.RTOD;

    while (pos.heading < 0)
        pos.heading += 360;

    return pos;
}

From source file:com.android.screenspeak.contextmenu.RadialMenuView.java

/**
 * Re-draw cached wedge bitmaps./*from  w  w  w.j a v a  2 s.  c o m*/
 */
private void invalidateCachedWedgeShapes() {
    final RadialMenu menu = mSubMenu != null ? mSubMenu : mRootMenu;
    final int menuSize = menu.size();
    if (menuSize <= 0) {
        return;
    }

    final float wedgeArc = (360.0f / menuSize);
    final float offsetArc = ((wedgeArc / 2.0f) + 90.0f);
    final float spacingArc = (float) Math.toDegrees(Math.tan(mSpacing / (double) mOuterRadius));
    final float left = (wedgeArc - spacingArc - offsetArc);
    final float center = ((wedgeArc / 2.0f) - offsetArc);
    final float right = (spacingArc - offsetArc);

    // Outer wedge.
    mCachedOuterPath.rewind();
    mCachedOuterPath.arcTo(mCachedOuterBound, center, (left - center));
    mCachedOuterPath.arcTo(mCachedExtremeBound, left, (right - left));
    mCachedOuterPath.arcTo(mCachedOuterBound, right, (center - right));
    mCachedOuterPath.close();

    mCachedOuterPathWidth = arcLength((left - right), mExtremeRadius);

    // Outer wedge in reverse, for rendering text.
    mCachedOuterPathReverse.rewind();
    mCachedOuterPathReverse.arcTo(mCachedOuterBound, center, (right - center));
    mCachedOuterPathReverse.arcTo(mCachedExtremeBound, right, (left - right));
    mCachedOuterPathReverse.arcTo(mCachedOuterBound, left, (center - left));
    mCachedOuterPathReverse.close();
}