Package org.jbox2d.common
Class MathUtils
- java.lang.Object
-
- org.jbox2d.common.PlatformMathUtils
-
- org.jbox2d.common.MathUtils
-
public class MathUtils extends PlatformMathUtils
A few math methods that don't fit very well anywhere else.
-
-
Field Summary
Fields Modifier and Type Field Description static floatDEG2RADDegrees to radians conversion factorstatic floatHALF_PIstatic floatINV_PIstatic floatPIstatic floatQUARTER_PIstatic floatRAD2DEGRadians to degrees conversion factorstatic float[]sinLUTstatic floatTHREE_HALVES_PIstatic floatTWOPI
-
Constructor Summary
Constructors Constructor Description MathUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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 Vec2clamp(Vec2 a, Vec2 low, Vec2 high)static voidclampToOut(Vec2 a, Vec2 low, Vec2 high, Vec2 dest)static floatcos(float x)static floatdistance(Vec2 v1, Vec2 v2)static floatdistanceSquared(Vec2 v1, Vec2 v2)static floatfastAtan2(float y, float x)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 floatrandomFloat(float argLow, float argHigh)static floatrandomFloat(java.util.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)-
Methods inherited from class org.jbox2d.common.PlatformMathUtils
fastPow
-
-
-
-
Field Detail
-
PI
public static final float PI
- See Also:
- Constant Field Values
-
TWOPI
public static final float TWOPI
- See Also:
- Constant Field Values
-
INV_PI
public static final float INV_PI
- See Also:
- Constant Field Values
-
HALF_PI
public static final float HALF_PI
- See Also:
- Constant Field Values
-
QUARTER_PI
public static final float QUARTER_PI
- See Also:
- Constant Field Values
-
THREE_HALVES_PI
public static final float THREE_HALVES_PI
- See Also:
- Constant Field Values
-
DEG2RAD
public static final float DEG2RAD
Degrees to radians conversion factor- See Also:
- Constant Field Values
-
RAD2DEG
public static final float RAD2DEG
Radians to degrees conversion factor- See Also:
- Constant Field Values
-
sinLUT
public static final float[] sinLUT
-
-
Method Detail
-
sin
public static final float sin(float x)
-
sinLUT
public static final float sinLUT(float x)
-
cos
public static final float cos(float x)
-
abs
public static final float abs(float x)
-
abs
public static final int abs(int x)
-
floor
public static final int floor(float x)
-
ceil
public static final int ceil(float x)
-
round
public static final int round(float x)
-
ceilPowerOf2
public static final int ceilPowerOf2(int x)
Rounds up the value to the nearest higher power^2 value.- Parameters:
x-- Returns:
- power^2 value
-
max
public static final float max(float a, float b)
-
max
public static final int max(int a, int b)
-
min
public static final float min(float a, float b)
-
min
public static final int min(int a, int b)
-
map
public static final float map(float val, float fromMin, float fromMax, float toMin, float toMax)
-
clamp
public static final float clamp(float a, float low, float high)Returns the closest value to 'a' that is in between 'low' and 'high'
-
nextPowerOfTwo
public static final 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 final boolean isPowerOfTwo(int x)
-
atan2
public static final float atan2(float y, float x)
-
fastAtan2
public static final float fastAtan2(float y, float x)
-
reduceAngle
public static final float reduceAngle(float theta)
-
randomFloat
public static final float randomFloat(float argLow, float argHigh)
-
randomFloat
public static final float randomFloat(java.util.Random r, float argLow, float argHigh)
-
sqrt
public static final float sqrt(float x)
-
-