FileDocCategorySizeDatePackage
MathUtils.javaAPI DocAndroid 5.1 API5148Thu Mar 12 22:22:10 GMT 2015android.util

MathUtils

public final class MathUtils extends Object
A class that contains utility methods related to numbers.
hide
Pending API council approval

Fields Summary
private static final Random
sRandom
private static final float
DEG_TO_RAD
private static final float
RAD_TO_DEG
Constructors Summary
private MathUtils()


      
    
Methods Summary
public static floatabs(float v)

        return v > 0 ? v : -v; 
    
public static floatacos(float value)

        return (float) Math.acos(value);
    
public static floatasin(float value)

        return (float) Math.asin(value);
    
public static floatatan(float value)

        return (float) Math.atan(value);
    
public static floatatan2(float a, float b)

        return (float) Math.atan2(a, b);
    
public static intconstrain(int amount, int low, int high)

        return amount < low ? low : (amount > high ? high : amount);
    
public static longconstrain(long amount, long low, long high)

        return amount < low ? low : (amount > high ? high : amount);
    
public static floatconstrain(float amount, float low, float high)

        return amount < low ? low : (amount > high ? high : amount);
    
public static floatdegrees(float radians)

        return radians * RAD_TO_DEG;
    
public static floatdist(float x1, float y1, float x2, float y2)

        final float x = (x2 - x1);
        final float y = (y2 - y1);
        return (float) Math.sqrt(x * x + y * y);
    
public static floatdist(float x1, float y1, float z1, float x2, float y2, float z2)

        final float x = (x2 - x1);
        final float y = (y2 - y1);
        final float z = (z2 - z1);
        return (float) Math.sqrt(x * x + y * y + z * z);
    
public static floatexp(float a)

        return (float) Math.exp(a);
    
public static floatlerp(float start, float stop, float amount)

        return start + (stop - start) * amount;
    
public static floatlog(float a)

        return (float) Math.log(a);
    
public static floatmag(float a, float b)

        return (float) Math.sqrt(a * a + b * b);
    
public static floatmag(float a, float b, float c)

        return (float) Math.sqrt(a * a + b * b + c * c);
    
public static floatmap(float minStart, float minStop, float maxStart, float maxStop, float value)

        return maxStart + (maxStart - maxStop) * ((value - minStart) / (minStop - minStart));
    
public static floatmax(int a, int b)

        return a > b ? a : b;
    
public static floatmax(float a, float b, float c)

        return a > b ? (a > c ? a : c) : (b > c ? b : c);
    
public static floatmax(int a, int b, int c)

        return a > b ? (a > c ? a : c) : (b > c ? b : c);
    
public static floatmax(float a, float b)

        return a > b ? a : b;
    
public static floatmin(float a, float b)

        return a < b ? a : b;
    
public static floatmin(int a, int b)

        return a < b ? a : b;
    
public static floatmin(float a, float b, float c)

        return a < b ? (a < c ? a : c) : (b < c ? b : c);
    
public static floatmin(int a, int b, int c)

        return a < b ? (a < c ? a : c) : (b < c ? b : c);
    
public static floatnorm(float start, float stop, float value)

        return (value - start) / (stop - start);
    
public static floatpow(float a, float b)

        return (float) Math.pow(a, b);
    
public static floatradians(float degrees)

        return degrees * DEG_TO_RAD;
    
public static intrandom(int howbig)

        return (int) (sRandom.nextFloat() * howbig);
    
public static intrandom(int howsmall, int howbig)

        if (howsmall >= howbig) return howsmall;
        return (int) (sRandom.nextFloat() * (howbig - howsmall) + howsmall);
    
public static floatrandom(float howbig)

        return sRandom.nextFloat() * howbig;
    
public static floatrandom(float howsmall, float howbig)

        if (howsmall >= howbig) return howsmall;
        return sRandom.nextFloat() * (howbig - howsmall) + howsmall;
    
public static voidrandomSeed(long seed)

        sRandom.setSeed(seed);
    
public static floatsq(float v)

        return v * v;
    
public static floattan(float angle)

        return (float) Math.tan(angle);