Example usage for java.lang Math sqrt

List of usage examples for java.lang Math sqrt

Introduction

In this page you can find the example usage for java.lang Math sqrt.

Prototype

@HotSpotIntrinsicCandidate
public static double sqrt(double a) 

Source Link

Document

Returns the correctly rounded positive square root of a double value.

Usage

From source file:Main.java

/**
 * Computes the length of a vector./* w  w w  .j av  a2 s.  c o  m*/
 *
 * @param x x coordinate of a vector
 * @param y y coordinate of a vector
 * @param z z coordinate of a vector
 * @return the length of a vector
 */
public static float length(float x, float y, float z) {
    return (float) Math.sqrt(x * x + y * y + z * z);
}

From source file:Main.java

/**
 * Get the radian between current line(determined by point A and B) and horizontal line.
 *
 * @param A point A/*w w w.  j ava  2  s  .  co  m*/
 * @param B point B
 * @return the radian
 */
public static float getRadian(Point A, Point B) {
    float lenA = B.x - A.x;
    float lenB = B.y - A.y;
    float lenC = (float) Math.sqrt(lenA * lenA + lenB * lenB);
    float radian = (float) Math.acos(lenA / lenC);
    radian = radian * (B.y < A.y ? -1 : 1);
    return radian;
}

From source file:com.freevariable.lancer.stat.Probability.java

public static double normal(double mean, double variance, double a) {
    // XXX: sure would be smarter to memoize these
    return (new NormalDistribution(mean, Math.sqrt(variance))).cumulativeProbability(a);
}

From source file:Main.java

public static final double[] realSymetricMatrix2x2(final double ixx, final double iyy, final double ixy) {
    // Matrix: [ Ixx Ixy ; Ixy Iyy ];

    final double term = Math.sqrt((ixx - iyy) * (ixx - iyy) + 4 * ixy * ixy);

    final double mu_1 = 0.5 * (ixx + iyy + term);
    final double mu_2 = 0.5 * (ixx + iyy - term);

    if (Math.abs(iyy) > Float.MIN_VALUE) {

        final double cos = 2 * ixy;
        final double sin = iyy - ixx + term;
        final double norm = Math.sqrt(cos * cos + sin * sin);
        if (norm > Float.MIN_VALUE) {
            return new double[] { mu_1, mu_2, cos / norm, sin / norm };
        }/*ww  w .  ja  v a2s  .co m*/

    }

    // Edge case logic

    // NB BDZ - cosAlpha and sinAlpha edge cases determined by comparing
    // Float.MIN_VALUE cases to values near it to see trend lines.

    double cosAlpha;
    double sinAlpha;

    // default cosAlpha and sinAlpha

    if (ixx < 0) {
        cosAlpha = 0;
        sinAlpha = 1;
    } else if (iyy >= 0) {
        if (ixy >= 0) {
            cosAlpha = 1;
            sinAlpha = 0;
        } else { // ixy < 0
            cosAlpha = -1;
            sinAlpha = 0;
        }
    } else { // iyy < 0
        if (ixy >= 0) {
            cosAlpha = 1;
            sinAlpha = 0;
        } else { // ixy < 0
            cosAlpha = -1;
            sinAlpha = 0;
        }
    }

    return new double[] { mu_1, mu_2, cosAlpha, sinAlpha };

}

From source file:Main.java

public static Bitmap getResizedBitmap(File file, int targetWidth, int targetHeight, float degrees) {
    Bitmap ret = null;//from ww  w  .j  av a  2  s  .  c  om

    if (file == null) {
    } else {
        BitmapFactory.Options option = new BitmapFactory.Options();
        Bitmap src = null;
        int sampleSize = 0;

        option.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(file.getAbsolutePath(), option);
        // more than 1MP
        if ((option.outWidth * option.outHeight) > 1048576) {
            double out_area = (double) (option.outWidth * option.outHeight) / 1048576.0;
            sampleSize = (int) (Math.sqrt(out_area) + 1);
        } else {
            sampleSize = 1;
        }

        option.inJustDecodeBounds = false;
        option.inSampleSize = sampleSize;
        src = BitmapFactory.decodeFile(file.getAbsolutePath(), option);
        if (src == null) {
        } else {
            ret = getResizedBitmap(src, targetWidth, targetHeight, degrees);
        }
    }

    return ret;
}

From source file:Main.java

private static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength,
        int maxNumOfPixels) {
    double w = options.outWidth;
    double h = options.outHeight;

    int lowerBound = (maxNumOfPixels == -1) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels));
    int upperBound = (minSideLength == -1) ? 128
            : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength));

    if (upperBound < lowerBound) {
        // return the larger one when there is no overlapping zone.
        return lowerBound;
    }//from   www. j av a 2 s . c o  m

    if ((maxNumOfPixels == -1) && (minSideLength == -1)) {
        return 1;
    } else if (minSideLength == -1) {
        return lowerBound;
    } else {
        return upperBound;
    }
}

From source file:edu.emory.mathcs.nlp.common.util.MathUtils.java

static public double stdev(double... array) {
    return Math.sqrt(variance(array));
}

From source file:com.opengamma.analytics.math.statistics.descriptive.LognormalSkewnessFromVolatilityCalculator.java

@Override
public Double evaluate(final Double sigma, final Double t) {
    Validate.notNull(sigma, "sigma");
    Validate.notNull(t, "t");
    final double y = Math.sqrt(Math.exp(sigma * sigma * t) - 1);
    return y * (3 + y * y);
}

From source file:Main.java

private static int computeInitialSampleSize(BitmapFactory.Options options, int minSideLength,
        int maxNumOfPixels) {
    double w = options.outWidth;
    double h = options.outHeight;

    final int UNCONSTRAINED = -1;
    int lowerBound = (maxNumOfPixels == UNCONSTRAINED) ? 1 : (int) Math.ceil(Math.sqrt(w * h / maxNumOfPixels));
    int upperBound = (minSideLength == UNCONSTRAINED) ? 128
            : (int) Math.min(Math.floor(w / minSideLength), Math.floor(h / minSideLength));

    if (upperBound < lowerBound) {
        // return the larger one when there is no overlapping zone.
        return lowerBound;
    }/* w w  w . j  ava 2s .c o m*/

    if ((maxNumOfPixels == UNCONSTRAINED) && (minSideLength == UNCONSTRAINED)) {
        return 1;
    } else if (minSideLength == UNCONSTRAINED) {
        return lowerBound;
    } else {
        return upperBound;
    }
}

From source file:com.opengamma.analytics.math.statistics.descriptive.LognormalFisherKurtosisFromVolatilityCalculator.java

@Override
public Double evaluate(final Double sigma, final Double t) {
    Validate.notNull(sigma, "sigma");
    Validate.notNull(t, "t");
    final double y = Math.sqrt(Math.exp(sigma * sigma * t) - 1);
    final double y2 = y * y;
    return y2 * (16 + y2 * (15 + y2 * (6 + y2)));
}