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:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.tree.NumberArithmetic.java

/**
 * Returns the trigonometric tangent of the number.
 * //from   ww  w .  jav a  2 s .  c o  m
 * @param a the number
 * @return the trigonometric tangent of the number
 * @see Math#tan(double)
 */
public static Number tan(Number a) {
    return Math.tan(a.doubleValue());
}

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

@Test
public void tanNull() {
    try {/* w ww  . j av a2s  .com*/
        getExpressionWithFunctionContext("tan(0)");
        Expression expression = getExpressionWithFunctionContext("tan(0)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.tan(0), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:com.ibm.bi.dml.runtime.functionobjects.Builtin.java

public double execute(double in) throws DMLRuntimeException {
    switch (bFunc) {
    case SIN://  w  ww.  j  av  a2  s . c  o  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:
        //if ( in <= 0 )
        //   throw new DMLRuntimeException("Builtin.execute(): logarithm can only be computed for non-negative numbers (input = " + in + ").");
        // for negative numbers, Math.log will return NaN
        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 SQRT:
        //if ( in < 0 )
        //   throw new DMLRuntimeException("Builtin.execute(): squareroot can only be computed for non-negative numbers (input = " + in + ").");
        return Math.sqrt(in); //faster in Math

    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 EXP:
        return FASTMATH ? FastMath.exp(in) : Math.exp(in);

    case ROUND:
        return Math.round(in); //no need for FastMath

    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:com.metinkale.prayerapp.compass.Main.java

private double getDirectionRad(double lat1, double lat2, double dLng) {
    return Math.atan2(Math.sin(dLng), (Math.cos(lat1) * Math.tan(lat2)) - (Math.sin(lat1) * Math.cos(dLng)));
}

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

@Test
public void tanNinety() {
    try {//from   w  ww  .  j  a  v a  2  s  .  co  m
        Expression expression = getExpressionWithFunctionContext("tan(90)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.tan(90), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

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

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

From source file:org.eclipse.smarthome.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:net.bither.fragment.hot.AddAddressHotHDMFragment.java

private int[] getCompactContainerSize() {
    int extraHeight = tvHot.getHeight();
    int width = llCold.getWidth() * 2;
    int height = (int) (width / 4 * Math.tan(Math.PI / 3)) + width / 2 + extraHeight * 2;
    return new int[] { width + flContainer.getPaddingLeft() + flContainer.getPaddingRight(),
            height + flContainer.getPaddingTop() + flContainer.getPaddingBottom() };
}

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

@Test
public void tanPiHalf() {
    try {//from w  ww.  ja  v a 2  s  .  co  m
        Expression expression = getExpressionWithFunctionContext("tan(pi/2)");
        assertEquals(ExpressionType.DOUBLE, expression.getExpressionType());
        assertEquals(Math.tan(Math.PI / 2), expression.evaluateNumerical(), 1e-15);
    } catch (ExpressionException e) {
        assertNotNull(e.getMessage());
    }
}

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

public static BufferedImage cylindricalMapping(BufferedImage img, double f) {
    if (img == null) {
        return null;
    }//  w w w  .  ja  va  2s .  c o m

    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 vmax = ((double) (h - y0)) / f;
    double vmin = (-(double) y0) / f;
    double vstep = (vmax - vmin) / ((double) h);

    double theta, tan, cos;
    int x, y;

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