Klasse Utils.MathUtils

java.lang.Object
net.risingworld.api.utils.Utils.MathUtils
Umschließende Klasse:
Utils

public abstract static class Utils.MathUtils extends Object
Contains useful math functions. Unlike the regular Java Math class, this class uses float values and an improved random number generator, resulting in better performance. Unless you really need double precision, it's highly recommendable to use this class.
Siehe auch:
  • Feldübersicht

    Felder
    Modifizierer und Typ
    Feld
    Beschreibung
    static final float
    Multiply with this factor to convert a degree value to radians
    static final float
    Half PI value as a float (90 degrees)
    static final float
    PI value as a float (180 degrees)
    static final float
    Quarter PI value as a float (45 degrees)
    static final float
    Multiply with this factor to convert a radian value to degrees
    static final float
    Two PI value as a float (360 degrees)
  • Konstruktorübersicht

    Konstruktoren
    Konstruktor
    Beschreibung
     
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    static float
    abs(float value)
    Gets the absolute value of a float value.
    static int
    absInt(int value)
    Gets the absolute value of an int value.
    static float
    clamp(float min, float max, float value)
    Clamps the value between min and max.
    static int
    clamp(int min, int max, int value)
    Clamps the value between min and max.
    static float
    degreeToRadian(float degree)
    Converts a degree value to radians.
    static float
    distance(float x1, float x2)
    Gets the distance between two values in 1d space (determined by x coordinate).
    static float
    distance(float x1, float y1, float x2, float y2)
    Gets the distance between two points in 2d space (determined by x and y coordinate).
    static float
    distance(float x1, float y1, float z1, float x2, float y2, float z2)
    Gets the distance between two points in 3d space (determined by x, y and z coordinate).
    static float
    distanceSqr(float x1, float y1, float z1, float x2, float y2, float z2)
     
    static float
    dot(float x1, float y1, float z1, float x2, float y2, float z2)
     
    static int
    getGCD(int... input)
    Gets the greatest common divisor of several int values.
    static int
    getGCD(int a, int b)
    Gets the greatest common divisor of two int values.
    static int
    getNextPowerOfTwo(int value)
    Gets the next power of two value (rounded up).
    static float
    length(float x, float y)
     
    static float
    length(float x, float y, float z)
     
    static float
    max(float x, float y)
     
    static float
    max(float x, float y, float z)
     
    static int
    max(int x, int y)
     
    static int
    max(int x, int y, int z)
     
    static float
    min(float x, float y)
    Returns the smallest value.
    static float
    min(float x, float y, float z)
    Returns the smallest value.
    static int
    min(int x, int y)
    Returns the smallest (integer) value.
    static int
    min(int x, int y, int z)
    Returns the smallest (integer) value.
    static float
    mod(float x, float y)
     
    static int
    mod(int x, int y)
     
    static boolean
    Gets a random boolean value (true or false).
    static float
    Gets a random float value between 0 and 1
    static int
    nextRandomInt(int min, int max)
    Gets a random int value between min (inclusive) and max (inclusive).
    static float
    radianToDegree(float radian)
    Converts a radian value to degree.
    static float
    round(float value, int digit)
    Rounds a float value to a given decimal place.
    static float
    saturate(float value)
    Clamps a value between 0 and 1.
    static float
    smoothstep(float min, float max, float x)
    Performs a smooth Hermite interpolation between 0 and 1.
    static float
    sqr(float value)
    Gets the value squared (value ^ 2).
    static float
    sqrt(float value)
    Gets the square root of a given value.
    static float
    step(float min, float x)
    If x is less than min, 0 is returned, else 1.

    Von Klasse geerbte Methoden java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Felddetails

    • PI

      public static final float PI
      PI value as a float (180 degrees)
      Siehe auch:
    • HALF_PI

      public static final float HALF_PI
      Half PI value as a float (90 degrees)
      Siehe auch:
    • QUARTER_PI

      public static final float QUARTER_PI
      Quarter PI value as a float (45 degrees)
      Siehe auch:
    • TWO_PI

      public static final float TWO_PI
      Two PI value as a float (360 degrees)
      Siehe auch:
    • DEG_TO_RAD

      public static final float DEG_TO_RAD
      Multiply with this factor to convert a degree value to radians
      Siehe auch:
    • RAD_TO_DEG

      public static final float RAD_TO_DEG
      Multiply with this factor to convert a radian value to degrees
      Siehe auch:
  • Konstruktordetails

    • MathUtils

      public MathUtils()
  • Methodendetails

    • abs

      public static float abs(float value)
      Gets the absolute value of a float value.
      Parameter:
      value - the argument whose absolute value is to be determined.
      Gibt zurück:
      the absolute value.
    • absInt

      public static int absInt(int value)
      Gets the absolute value of an int value.
      Parameter:
      value - the argument whose absolute value is to be determined.
      Gibt zurück:
      the absolute value.
    • mod

      public static int mod(int x, int y)
    • mod

      public static float mod(float x, float y)
    • min

      public static float min(float x, float y)
      Returns the smallest value.
      Parameter:
      x - the 1st value you want to compare with the other values.
      y - the 2nd value you want to compare with the other values.
      Gibt zurück:
      the smaller value (x or y).
    • min

      public static float min(float x, float y, float z)
      Returns the smallest value.
      Parameter:
      x - the 1st value you want to compare with the other values.
      y - the 2nd value you want to compare with the other values.
      z - the 3rd value you want to compare with the other values.
      Gibt zurück:
      the smaller value (x, y or z).
    • min

      public static int min(int x, int y)
      Returns the smallest (integer) value.
      Parameter:
      x - the 1st value you want to compare with the other values.
      y - the 2nd value you want to compare with the other values.
      Gibt zurück:
      the smaller value (x or y).
    • min

      public static int min(int x, int y, int z)
      Returns the smallest (integer) value.
      Parameter:
      x - the 1st value you want to compare with the other values.
      y - the 2nd value you want to compare with the other values.
      z - the 3rd value you want to compare with the other values.
      Gibt zurück:
      the smaller value (x, y or z).
    • max

      public static float max(float x, float y)
    • max

      public static float max(float x, float y, float z)
    • max

      public static int max(int x, int y)
    • max

      public static int max(int x, int y, int z)
    • sqr

      public static float sqr(float value)
      Gets the value squared (value ^ 2).
      Parameter:
      value - the value to square.
      Gibt zurück:
      the square value.
    • sqrt

      public static float sqrt(float value)
      Gets the square root of a given value.
      Parameter:
      value - the value you want to get the square root of.
      Gibt zurück:
      the square root value.
      Siehe auch:
    • degreeToRadian

      public static float degreeToRadian(float degree)
      Converts a degree value to radians.
      Parameter:
      degree - the degree value.
      Gibt zurück:
      the degree value in radians.
    • radianToDegree

      public static float radianToDegree(float radian)
      Converts a radian value to degree.
      Parameter:
      radian - the radian value.
      Gibt zurück:
      the radian value in degree.
    • clamp

      public static float clamp(float min, float max, float value)
      Clamps the value between min and max.
      Parameter:
      min - the min value.
      max - the max value.
      value - the value you want to clamp.
      Gibt zurück:
      the clamped value.
    • clamp

      public static int clamp(int min, int max, int value)
      Clamps the value between min and max.
      Parameter:
      min - the min value.
      max - the max value.
      value - the value you want to clamp.
      Gibt zurück:
      the clamped value.
    • saturate

      public static float saturate(float value)
      Clamps a value between 0 and 1.
      Parameter:
      value - the value you want to clamp.
      Gibt zurück:
      the value clamped between 0 and 1.
    • step

      public static float step(float min, float x)
      If x is less than min, 0 is returned, else 1.
      Parameter:
      min - min threshold.
      x - the value.
      Gibt zurück:
      0 if x is less than min, 1 if x is greater or equal to min.
    • smoothstep

      public static float smoothstep(float min, float max, float x)
      Performs a smooth Hermite interpolation between 0 and 1.
      Parameter:
      min - the lower edge value.
      max - the upper edge value.
      x - the source value for interpolation.
      Gibt zurück:
      the interpolated value between 0 and 1. If x is less than min, 0 will be returned. If x is greater than max, 1 will be returned. Otherwise a smooth interpolation between 0 and 1 is performed.
      Siehe auch:
    • distance

      public static float distance(float x1, float x2)
      Gets the distance between two values in 1d space (determined by x coordinate).
      Parameter:
      x1 - the first x coordinate.
      x2 - the second x coordinate.
      Gibt zurück:
      the distance between the two values.
    • distance

      public static float distance(float x1, float y1, float x2, float y2)
      Gets the distance between two points in 2d space (determined by x and y coordinate).
      Parameter:
      x1 - the x coordinate of the first point.
      y1 - the y coordinate of the first point.
      x2 - the x coordinate of the second point.
      y2 - the y coordinate of the second point.
      Gibt zurück:
      the distance between the two points.
    • distance

      public static float distance(float x1, float y1, float z1, float x2, float y2, float z2)
      Gets the distance between two points in 3d space (determined by x, y and z coordinate).
      Parameter:
      x1 - the x coordinate of the first point.
      y1 - the y coordinate of the first point.
      z1 - the z coordinate of the first point.
      x2 - the x coordinate of the second point.
      y2 - the y coordinate of the second point.
      z2 - the z coordinate of the second point.
      Gibt zurück:
      the distance between the two points.
    • distanceSqr

      public static float distanceSqr(float x1, float y1, float z1, float x2, float y2, float z2)
    • length

      public static float length(float x, float y)
    • length

      public static float length(float x, float y, float z)
    • dot

      public static float dot(float x1, float y1, float z1, float x2, float y2, float z2)
    • getNextPowerOfTwo

      public static int getNextPowerOfTwo(int value)
      Gets the next power of two value (rounded up). For example, 1 returns 1, 3 returns 4, 120 returns 128 etc.
      Parameter:
      value - your value.
      Gibt zurück:
      the next power of two value (rounded up).
    • getGCD

      public static int getGCD(int... input)
      Gets the greatest common divisor of several int values.
      Parameter:
      input - multiple int values you want to calculate the GCD of.
      Gibt zurück:
      the greatest common divisor.
    • getGCD

      public static int getGCD(int a, int b)
      Gets the greatest common divisor of two int values.
      Parameter:
      a - first int value.
      b - second int value.
      Gibt zurück:
      the greatest common divisor of the two values.
    • round

      public static float round(float value, int digit)
      Rounds a float value to a given decimal place.
      Parameter:
      value - the value you want to round.
      digit - the decimal places.
      Gibt zurück:
      the rounded value.
    • nextRandomFloat

      public static float nextRandomFloat()
      Gets a random float value between 0 and 1
      Gibt zurück:
      a pseudorandom float value.
    • nextRandomInt

      public static int nextRandomInt(int min, int max)
      Gets a random int value between min (inclusive) and max (inclusive).
      Parameter:
      min - the lower bound (inclusive)
      max - the upper bound (inclusive)
      Gibt zurück:
      a pseudorandom int value.
    • nextRandomBoolean

      public static boolean nextRandomBoolean()
      Gets a random boolean value (true or false).
      Gibt zurück:
      a pseudorandom boolean value.