Package org.jbox2d.common
Class MathUtils
java.lang.Object
org.jbox2d.common.MathUtils
A few math methods that don't fit very well anywhere else.
- Author:
- Daniel Murphy
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatDegrees to radians conversion factorstatic final floatstatic final floatstatic final floatstatic final floatstatic final floatRadians to degrees conversion factorstatic final float[]static final floatstatic final float -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic floatabs(float x) static intabs(int x) static floatatan2(float y, float x) static intceil(float x) static intceilPowerOf2(int x) Rounds up the value to the nearest higher power^2 value.static floatclamp(float a, float low, float high) Returns the closest value to 'a' that is in between 'low' and 'high'static Vec2static voidclampToOut(Vec2 a, Vec2 low, Vec2 high, Vec2 dest) static floatcos(float x) static floatstatic floatdistanceSquared(Vec2 v1, Vec2 v2) static floatfastAbs(float x) static floatfastAtan2(float y, float x) static intfastCeil(float x) static intfastFloor(float x) static floatfastPow(float a, float b) static intfloor(float x) static booleanisPowerOfTwo(int x) static floatmap(float val, float fromMin, float fromMax, float toMin, float toMax) static floatmax(float a, float b) static intmax(int a, int b) static floatmin(float a, float b) static intmin(int a, int b) static intnextPowerOfTwo(int x) Next Largest Power of 2: Given a binary integer value x, the next largest power of 2 can be computed by a SWAR algorithm that recursively "folds" the upper bits into the lower bits.static floatpow(float a, float b) static floatrandomFloat(float argLow, float argHigh) static floatrandomFloat(Random r, float argLow, float argHigh) static floatreduceAngle(float theta) static intround(float x) static floatsin(float x) static floatsinLUT(float x) static floatsqrt(float x)
-
Field Details
-
PI
public static final float PI- See Also:
-
TWOPI
public static final float TWOPI- See Also:
-
INV_PI
public static final float INV_PI- See Also:
-
HALF_PI
public static final float HALF_PI- See Also:
-
QUARTER_PI
public static final float QUARTER_PI- See Also:
-
THREE_HALVES_PI
public static final float THREE_HALVES_PI- See Also:
-
DEG2RAD
public static final float DEG2RADDegrees to radians conversion factor- See Also:
-
RAD2DEG
public static final float RAD2DEGRadians to degrees conversion factor- See Also:
-
sinLUT
public static final float[] sinLUT
-
-
Constructor Details
-
MathUtils
public MathUtils()
-
-
Method Details
-
sin
public static float sin(float x) -
sinLUT
public static float sinLUT(float x) -
cos
public static float cos(float x) -
abs
public static float abs(float x) -
fastAbs
public static float fastAbs(float x) -
abs
public static int abs(int x) -
floor
public static int floor(float x) -
fastFloor
public static int fastFloor(float x) -
ceil
public static int ceil(float x) -
fastCeil
public static int fastCeil(float x) -
round
public static int round(float x) -
ceilPowerOf2
public static int ceilPowerOf2(int x) Rounds up the value to the nearest higher power^2 value.- Returns:
- power^2 value
-
max
public static float max(float a, float b) -
max
public static int max(int a, int b) -
min
public static float min(float a, float b) -
min
public static int min(int a, int b) -
map
public static float map(float val, float fromMin, float fromMax, float toMin, float toMax) -
clamp
public static float clamp(float a, float low, float high) Returns the closest value to 'a' that is in between 'low' and 'high' -
clamp
-
clampToOut
-
nextPowerOfTwo
public static int nextPowerOfTwo(int x) Next Largest Power of 2: Given a binary integer value x, the next largest power of 2 can be computed by a SWAR algorithm that recursively "folds" the upper bits into the lower bits. This process yields a bit vector with the same most significant 1 as x, but all 1's below it. Adding 1 to that value yields the next largest power of 2. -
isPowerOfTwo
public static boolean isPowerOfTwo(int x) -
pow
public static float pow(float a, float b) -
atan2
public static float atan2(float y, float x) -
fastAtan2
public static float fastAtan2(float y, float x) -
reduceAngle
public static float reduceAngle(float theta) -
randomFloat
public static float randomFloat(float argLow, float argHigh) -
randomFloat
-
sqrt
public static float sqrt(float x) -
distanceSquared
-
distance
-
fastPow
public static float fastPow(float a, float b)
-