Example usage for java.lang Math pow

List of usage examples for java.lang Math pow

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static double pow(double a, double b) 

Source Link

Document

Returns the value of the first argument raised to the power of the second argument.

Usage

From source file:Main.java

/**
 * Get the distance between two points.//from w  ww  .  j  av a 2s.  co m
 *
 * @param A Point A
 * @param B Point B
 * @return the distance between point A and point B.
 */
public static int getDistance(PointF A, PointF B) {
    return (int) Math.sqrt(Math.pow(A.x - B.x, 2) + Math.pow(A.y - B.y, 2));
}

From source file:Main.java

/**
 * Convert RGB to XYZ/* w w  w  .j a  va  2 s. c  o  m*/
 * 
 * Convert equation and source code is from ImageJ's plugin Color Space Converter
 * http://rsbweb.nih.gov/ij/plugins/download/Color_Space_Converter.java
 * 
 * @param R
 * @param G
 * @param B
 * @return XYZ in double array.
 */
public static double[] RGBtoXYZ(int R, int G, int B) {
    double[] result = new double[3];

    // convert 0..255 into 0..1
    double r = R / 255.0;
    double g = G / 255.0;
    double b = B / 255.0;

    // assume sRGB
    if (r <= 0.04045) {
        r = r / 12.92;
    } else {
        r = Math.pow(((r + 0.055) / 1.055), 2.4);
    }

    if (g <= 0.04045) {
        g = g / 12.92;
    } else {
        g = Math.pow(((g + 0.055) / 1.055), 2.4);
    }

    if (b <= 0.04045) {
        b = b / 12.92;
    } else {
        b = Math.pow(((b + 0.055) / 1.055), 2.4);
    }

    r *= 100.0;
    g *= 100.0;
    b *= 100.0;

    // [X Y Z] = [r g b][M]
    result[0] = (r * M[0][0]) + (g * M[0][1]) + (b * M[0][2]);
    result[1] = (r * M[1][0]) + (g * M[1][1]) + (b * M[1][2]);
    result[2] = (r * M[2][0]) + (g * M[2][1]) + (b * M[2][2]);

    return result;
}

From source file:de.mpc.pia.tools.PIATools.java

/**
 * Round a double value and keeping (at max) the given number of decimal
 * places./*  w w  w  . j  a v a2 s  .c  o  m*/
 *
 * @param value
 * @param dec
 * @return
 */
public static double round(double value, int dec) {
    double factor = Math.pow(10, dec);
    return Math.round(value * factor) / factor;
}

From source file:gedi.util.math.stat.distributions.LfcDistribution.java

public static double ltop(double l) {
    return Math.pow(2, l) / (1 + Math.pow(2, l));
}

From source file:Main.java

/**
 * Convert XYZ to RGB./* w  w  w.  j  a  va2s .  c om*/
 *
 * @param X
 * @param Y
 * @param Z
 * @return RGB in int array.
 */
public static int[] XYZtoRGB(double X, double Y, double Z) {
    int[] result = new int[3];

    double x = X / 100.0;
    double y = Y / 100.0;
    double z = Z / 100.0;

    // [r g b] = [X Y Z][Mi]
    double r = (x * Mi[0][0]) + (y * Mi[0][1]) + (z * Mi[0][2]);
    double g = (x * Mi[1][0]) + (y * Mi[1][1]) + (z * Mi[1][2]);
    double b = (x * Mi[2][0]) + (y * Mi[2][1]) + (z * Mi[2][2]);

    // assume sRGB
    if (r > 0.0031308) {
        r = ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055);
    } else {
        r = (r * 12.92);
    }
    if (g > 0.0031308) {
        g = ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055);
    } else {
        g = (g * 12.92);
    }
    if (b > 0.0031308) {
        b = ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055);
    } else {
        b = (b * 12.92);
    }

    r = (r < 0) ? 0 : r;
    g = (g < 0) ? 0 : g;
    b = (b < 0) ? 0 : b;

    // convert 0..1 into 0..255
    result[0] = (int) Math.round(r * 255);
    result[1] = (int) Math.round(g * 255);
    result[2] = (int) Math.round(b * 255);

    return result;
}

From source file:Main.java

public static int bitSet2Int(BitSet bs) {
    int total = 0;
    int b = bs.length() - 1;
    if (b > 0) {
        int value = (int) Math.pow(2, b);
        for (int i = 0; i <= b; i++) {
            if (bs.get(i))
                total += value;/*  w  w w . jav  a  2  s  . co  m*/
            value = value >> 1;
        }
    }

    return total;
}

From source file:Main.java

public static boolean isTablet(Context ctx) {
    try {/*from  w ww  .  j  a  v a  2s  .c o  m*/
        DisplayMetrics dm = ctx.getResources().getDisplayMetrics();
        float screenWidth = dm.widthPixels / dm.xdpi;
        float screenHeight = dm.heightPixels / dm.ydpi;
        double size = Math.sqrt(Math.pow(screenWidth, 2) + Math.pow(screenHeight, 2));
        return size >= 6;
    } catch (Throwable t) {
        return false;
    }
}

From source file:Main.java

public static int XYZToColor(double x, double y, double z) {
    double r = (x * 3.2406 + y * -1.5372 + z * -0.4986) / 100;
    double g = (x * -0.9689 + y * 1.8758 + z * 0.0415) / 100;
    double b = (x * 0.0557 + y * -0.2040 + z * 1.0570) / 100;

    r = r > 0.0031308 ? 1.055 * Math.pow(r, 1 / 2.4) - 0.055 : 12.92 * r;
    g = g > 0.0031308 ? 1.055 * Math.pow(g, 1 / 2.4) - 0.055 : 12.92 * g;
    b = b > 0.0031308 ? 1.055 * Math.pow(b, 1 / 2.4) - 0.055 : 12.92 * b;

    return Color.rgb(constrain((int) Math.round(r * 255), 0, 255), constrain((int) Math.round(g * 255), 0, 255),
            constrain((int) Math.round(b * 255), 0, 255));
}

From source file:Main.java

public static double getDistance(double lat1, double lng1, double lat2, double lng2) {
    double radLat1 = rad(lat1);
    double radLat2 = rad(lat2);
    double a = radLat1 - radLat2;
    double b = rad(lng1) - rad(lng2);
    double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
            + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
    s = s * EARTH_RADIUS;//from   www  .  ja  v a  2 s .c  o  m
    s = Math.round(s * 10000d) / 10000d;
    s = s * 1000;
    return s;
}

From source file:Main.java

public static double calculateDistance(int frequency, int level) {
    return Math.pow(10.0, (DISTANCE_MHZ_M - (20 * Math.log10(frequency)) + Math.abs(level)) / 20.0);
}