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:IK.G.java

public static double tan(double in) {
    return Math.tan(in);
}

From source file:org.apache.hadoop.hive.ql.udf.UDFTan.java

/**
 * Take Tangent of a//from   w w w . j a va 2  s.  com
 */
public DoubleWritable evaluate(DoubleWritable a) {
    if (a == null) {
        return null;
    } else {
        result.set(Math.tan(a.get()));
        return result;
    }
}

From source file:uk.me.berndporr.iirj.BandStopTransform.java

public BandStopTransform(double fc, double fw, LayoutBase digital, LayoutBase analog) {
    digital.reset();//from w w w  . ja va2 s  . c o m

    double ww = 2 * Math.PI * fw;

    wc2 = 2 * Math.PI * fc - (ww / 2);
    wc = wc2 + ww;

    // this is crap
    if (wc2 < 1e-8)
        wc2 = 1e-8;
    if (wc > Math.PI - 1e-8)
        wc = Math.PI - 1e-8;

    a = Math.cos((wc + wc2) * .5) / Math.cos((wc - wc2) * .5);
    b = Math.tan((wc - wc2) * .5);
    a2 = a * a;
    b2 = b * b;

    int numPoles = analog.getNumPoles();
    int pairs = numPoles / 2;
    for (int i = 0; i < pairs; i++) {
        PoleZeroPair pair = analog.getPair(i);
        ComplexPair p = transform(pair.poles.first);
        ComplexPair z = transform(pair.zeros.first);
        digital.addPoleZeroConjugatePairs(p.first, z.first);
        digital.addPoleZeroConjugatePairs(p.second, z.second);
    }

    if ((numPoles & 1) == 1) {
        ComplexPair poles = transform(analog.getPair(pairs).poles.first);
        ComplexPair zeros = transform(analog.getPair(pairs).zeros.first);

        digital.add(poles, zeros);
    }

    if (fc < 0.25)
        digital.setNormal(Math.PI, analog.getNormalGain());
    else
        digital.setNormal(0, analog.getNormalGain());
}

From source file:uk.me.berndporr.iirj.BandPassTransform.java

public BandPassTransform(double fc, double fw, LayoutBase digital, LayoutBase analog) {

    digital.reset();/*from ww w .  java 2s .  c  o  m*/

    double ww = 2 * Math.PI * fw;

    // pre-calcs
    wc2 = 2 * Math.PI * fc - (ww / 2);
    wc = wc2 + ww;

    // what is this crap?
    if (wc2 < 1e-8)
        wc2 = 1e-8;
    if (wc > Math.PI - 1e-8)
        wc = Math.PI - 1e-8;

    a = Math.cos((wc + wc2) * 0.5) / Math.cos((wc - wc2) * 0.5);
    b = 1 / Math.tan((wc - wc2) * 0.5);
    a2 = a * a;
    b2 = b * b;
    ab = a * b;
    ab_2 = 2 * ab;

    int numPoles = analog.getNumPoles();
    int pairs = numPoles / 2;
    for (int i = 0; i < pairs; ++i) {
        PoleZeroPair pair = analog.getPair(i);
        ComplexPair p1 = transform(pair.poles.first);
        ComplexPair z1 = transform(pair.zeros.first);

        digital.addPoleZeroConjugatePairs(p1.first, z1.first);
        digital.addPoleZeroConjugatePairs(p1.second, z1.second);
    }

    if ((numPoles & 1) == 1) {
        ComplexPair poles = transform(analog.getPair(pairs).poles.first);
        ComplexPair zeros = transform(analog.getPair(pairs).zeros.first);

        digital.add(poles, zeros);
    }

    double wn = analog.getNormalW();
    digital.setNormal(2 * Math.atan(Math.sqrt(Math.tan((wc + wn) * 0.5) * Math.tan((wc2 + wn) * 0.5))),
            analog.getNormalGain());
}

From source file:net.nicoulaj.benchmarks.math.DoubleTan.java

@GenerateMicroBenchmark
public void math(BlackHole hole) {
    for (int i = 0; i < data.length - 1; i++)
        hole.consume(Math.tan(data[i]));
}

From source file:net.sf.dsp4j.octave.packages.signal_1_2_0.Cheb2Ord.java

private void calcCheb2Ord(double[] Wp, double[] Ws, double Rp, double Rs) {
    double T = 2;

    // returned frequency is the same as the input frequency
    Wc = Arrays.copyOf(Ws, Ws.length);

    // warp the target frequencies according to the bilinear transform
    for (int i = 0; i < Wp.length; i++) {
        Ws[i] = 2.0 / T * Math.tan(Math.PI * Ws[i] / T);
        Wp[i] = 2.0 / T * Math.tan(Math.PI * Wp[i] / T);
    }//from w w w .  java  2 s  .c om
    double Wa;

    if (Wp[0] < Ws[0]) {
        // low pass
        if (Wp.length == 1) {
            Wa = Wp[0] / Ws[0];
        } else {
            // band reject
            throw new RuntimeException("band reject is not implement yet.");
        }
    } else {
        // if high pass, reverse the sense of the test
        if (Wp.length == 1) {
            Wa = Ws[0] / Wp[0];
        } else {
            // band pass 
            Wa = Double.MAX_VALUE;
            for (int i = 0; i < Wp.length; i++) {
                Wa = Math.min(Wa, Math.abs((Math.pow(Wp[i], 2) - Ws[0] * Ws[1]) / (Wp[i] * (Ws[0] - Ws[1]))));
            }
        }
    }

    // compute minimum n which satisfies all band edge conditions
    final double stop_atten = Math.pow(10, Math.abs(Rs) / 10.0);
    final double pass_atten = Math.pow(10, Math.abs(Rp) / 10.0);
    n = (int) Math.ceil(
            FastMath.acosh(Math.sqrt((stop_atten - 1.0) / (pass_atten - 1.0))) / FastMath.acosh(1.0 / Wa));

}

From source file:net.sf.dsp4j.octave.packages.signal_1_2_0.Cheb1Ord.java

private void calcCheb1Ord(double[] Wp, double[] Ws, double Rp, double Rs) {

    double T = 2;

    // returned frequency is the same as the input frequency
    Wc = Arrays.copyOf(Wp, Wp.length);

    // warp the target frequencies according to the bilinear transform
    for (int i = 0; i < Wp.length; i++) {
        Ws[i] = 2.0 / T * Math.tan(Math.PI * Ws[i] / T);
        Wp[i] = 2.0 / T * Math.tan(Math.PI * Wp[i] / T);
    }//  ww  w  .  ja  va2 s.  c o  m
    double Wa;
    if (Wp[0] < Ws[0]) // low pass
    {
        if (Wp.length == 1) {
            Wa = Ws[0] / Wp[0];
        } else {
            // band reject
            throw new RuntimeException("band reject is not implement yet.");
        }
    } else {
        // if high pass, reverse the sense of the test
        if (Wp.length == 1) {
            Wa = Wp[0] / Ws[0];
        } else {
            // band pass
            Wa = Double.MAX_VALUE;
            for (int i = 0; i < Wp.length; i++) {
                Wa = Math.min(Wa, Math.abs((Math.pow(Ws[i], 2) - Wp[0] * Wp[1]) / (Ws[i] * (Wp[0] - Wp[1]))));
            }
        }
    }

    // compute minimum n which satisfies all band edge conditions
    final double stop_atten = Math.pow(10, Math.abs(Rs) / 10.0);
    final double pass_atten = Math.pow(10, Math.abs(Rp) / 10.0);
    n = (int) Math
            .ceil(FastMath.acosh(Math.sqrt((stop_atten - 1.0) / (pass_atten - 1.0))) / FastMath.acosh(Wa));

}

From source file:com.autodomum.daylight.algorithm.DaylightAlgorithm.java

/**
 * Calculate length of the day for a specific day
 * /* ww  w  .  j a v a 2s  .c  o  m*/
 * @param latitude
 *            the latitude
 * @param day
 *            the day
 * @return time in hours
 */
public double length(double latitude, int day) {

    final double p = Math
            .asin(.39795 * Math.cos(.2163108 + 2 * Math.atan(.9671396 * Math.tan(.00860 * (day - 186)))));

    return (24.0d - (24.0d / Math.PI) * Math
            .acos((Math.sin(0.8333d * Math.PI / 180d) + Math.sin(latitude * Math.PI / 180.0d) * Math.sin(p))
                    / (Math.cos(latitude * Math.PI / 180.0d) * Math.cos(p))));
}

From source file:org.elasticsoftware.elasticactors.geoevents.Coordinate.java

public double distance(final double latitude, final double longitude, LengthUnit unit) {
    double a = 6378137, b = 6356752.3142;
    // ellipsiod// w  w w. j av  a 2 s.c o m
    double L = (longitude - this.longitude) * degToRad;
    double U1 = Math.atan((1 - f) * Math.tan(this.latitude * degToRad));
    double U2 = Math.atan((1 - f) * Math.tan(latitude * degToRad));
    double sinU1 = Math.sin(U1), cosU1 = Math.cos(U1);
    double sinU2 = Math.sin(U2), cosU2 = Math.cos(U2);

    double cosSqAlpha, sinSigma, cos2SigmaM, cosSigma, sigma;

    double lambda = L, lambdaP, iterLimit = 20;
    do {
        double sinLambda = Math.sin(lambda), cosLambda = Math.cos(lambda);
        sinSigma = Math.sqrt((cosU2 * sinLambda) * (cosU2 * sinLambda)
                + (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda) * (cosU1 * sinU2 - sinU1 * cosU2 * cosLambda));
        if (sinSigma == 0)
            return 0; // co-incident points
        cosSigma = sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
        sigma = Math.atan2(sinSigma, cosSigma);
        double sinAlpha = cosU1 * cosU2 * sinLambda / sinSigma;
        cosSqAlpha = 1 - sinAlpha * sinAlpha;
        cos2SigmaM = cosSigma - 2 * sinU1 * sinU2 / cosSqAlpha;
        if (cos2SigmaM == Double.NaN)
            cos2SigmaM = 0; // equatorial line: cosSqAlpha=0 (?6)
        double C = f / 16 * cosSqAlpha * (4 + f * (4 - 3 * cosSqAlpha));
        lambdaP = lambda;
        lambda = L + (1 - C) * f * sinAlpha
                * (sigma + C * sinSigma * (cos2SigmaM + C * cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)));
    } while (Math.abs(lambda - lambdaP) > EPSILON && --iterLimit > 0);

    if (iterLimit == 0)
        return Double.NaN;
    double uSquared = cosSqAlpha * (a * a - b * b) / (b * b);
    double A = 1 + uSquared / 16384 * (4096 + uSquared * (-768 + uSquared * (320 - 175 * uSquared)));
    double B = uSquared / 1024 * (256 + uSquared * (-128 + uSquared * (74 - 47 * uSquared)));
    double deltaSigma = B * sinSigma * (cos2SigmaM + B / 4 * (cosSigma * (-1 + 2 * cos2SigmaM * cos2SigmaM)
            - B / 6 * cos2SigmaM * (-3 + 4 * sinSigma * sinSigma) * (-3 + 4 * cos2SigmaM * cos2SigmaM)));
    double s = b * A * (sigma - deltaSigma);

    return unit.convert(s, LengthUnit.METRES);
}

From source file:com.rks.musicx.misc.widgets.DiagonalLayout.java

private void calculateLayout() {
    if (settings == null) {
        return;//from w w w. ja v a  2s  .  c  om
    }
    height = getMeasuredHeight();
    width = getMeasuredWidth();
    if (width > 0 && height > 0) {

        final float perpendicularHeight = (float) (width * Math.tan(Math.toRadians(settings.getAngle())));

        clipPath = createClipPath(perpendicularHeight);
        outlinePath = createOutlinePath(perpendicularHeight);

        handleMargins(perpendicularHeight);

        ViewCompat.setElevation(this, settings.getElevation());

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setOutlineProvider(getOutlineProvider());
        }
    }
}