Class Vectors

java.lang.Object
civitas.celestis.math.vector.Vectors

public final class Vectors extends Object
A static utility class which contains methods related to vectors.
See Also:
  • Method Details

    • random2

      @Nonnull public static Vector2 random2()
      Returns a random unit vector. (a vector with a Euclidean norm of 1)
      Returns:
      A random unit vector
    • random3

      @Nonnull public static Vector3 random3()
      Returns a random unit vector. (a vector with a Euclidean norm of 1)
      Returns:
      A random unit vector
    • random4

      @Nonnull public static Vector4 random4()
      Returns a random unit vector. (a vector with a Euclidean norm of 1)
      Returns:
      A random unit vector
    • isInRange

      public static <V extends Vector<V>> boolean isInRange(@Nonnull V val, @Nonnull V min, @Nonnull V max)
      Checks if the provided value val is within the range of [min, max].
      Type Parameters:
      V - The type of vector to use for this operation
      Parameters:
      val - The value to compare
      min - The minimum allowed value
      max - The maximum allowed value
      Returns:
      true if the value is within the range of [min, max]
    • isInRange

      public static boolean isInRange(@Nonnull Vector2 val, @Nonnull Vector2 min, @Nonnull Vector2 max)
      Checks if the provided value val is within the range of [min, max].
      Parameters:
      val - The value to compare
      min - The minimum allowed value
      max - The maximum allowed value
      Returns:
      true if the value is within the range of [min, max]
    • isInRange

      public static boolean isInRange(@Nonnull Vector3 val, @Nonnull Vector3 min, @Nonnull Vector3 max)
      Checks if the provided value val is within the range of [min, max].
      Parameters:
      val - The value to compare
      min - The minimum allowed value
      max - The maximum allowed value
      Returns:
      true if the value is within the range of [min, max]
    • isInRange

      public static boolean isInRange(@Nonnull Vector4 val, @Nonnull Vector4 min, @Nonnull Vector4 max)
      Checks if the provided value val is within the range of [min, max].
      Parameters:
      val - The value to compare
      min - The minimum allowed value
      max - The maximum allowed value
      Returns:
      true if the value is within the range of [min, max]
    • sum

      @Nonnull public static Vector2 sum(@Nonnull Vector2 v1, @Nonnull Vector2 v2)
      Returns the sum of the two values.
      Parameters:
      v1 - The first value to add
      v2 - The second value to add
      Returns:
      The sum of the provided values
    • sum

      @Nonnull public static Vector2 sum(@Nonnull Vector2... values)
      Returns the sum of the provided values.
      Parameters:
      values - The values to sum
      Returns:
      The sum of the provided values
    • sum

      @Nonnull public static Vector3 sum(@Nonnull Vector3 v1, @Nonnull Vector3 v2)
      Returns the sum of the two values.
      Parameters:
      v1 - The first value to add
      v2 - The second value to add
      Returns:
      The sum of the provided values
    • sum

      @Nonnull public static Vector3 sum(@Nonnull Vector3... values)
      Returns the sum of the provided values.
      Parameters:
      values - The values to sum
      Returns:
      The sum of the provided values
    • sum

      @Nonnull public static Vector4 sum(@Nonnull Vector4 v1, @Nonnull Vector4 v2)
      Returns the sum of the two values.
      Parameters:
      v1 - The first value to add
      v2 - The second value to add
      Returns:
      The sum of the provided values
    • sum

      @Nonnull public static Vector4 sum(@Nonnull Vector4... values)
      Returns the sum of the provided values.
      Parameters:
      values - The values to sum
      Returns:
      The sum of the provided values
    • avg

      @Nonnull public static Vector2 avg(@Nonnull Vector2 v1, @Nonnull Vector2 v2)
      Returns the simple average of the two vectors. This is equivalent to the centroid in a geometric context.
      Parameters:
      v1 - The first vector to average
      v2 - The second vector to average
      Returns:
      The simple average of the two vectors
    • avg

      @Nonnull public static Vector2 avg(@Nonnull Vector2... values)
      Returns the simple average of the provided vectors. This is equivalent to the centroid in a geometric context.
      Parameters:
      values - The vectors to average
      Returns:
      The simple average of the provided vectors
    • avg

      @Nonnull public static Vector3 avg(@Nonnull Vector3 v1, @Nonnull Vector3 v2)
      Returns the simple average of the two vectors. This is equivalent to the centroid in a geometric context.
      Parameters:
      v1 - The first vector to average
      v2 - The second vector to average
      Returns:
      The simple average of the two vectors
    • avg

      @Nonnull public static Vector3 avg(@Nonnull Vector3... values)
      Returns the simple average of the provided vectors. This is equivalent to the centroid in a geometric context.
      Parameters:
      values - The vectors to average
      Returns:
      The simple average of the provided vectors
    • avg

      @Nonnull public static Vector4 avg(@Nonnull Vector4 v1, @Nonnull Vector4 v2)
      Returns the simple average of the two vectors. This is equivalent to the centroid in a geometric context.
      Parameters:
      v1 - The first vector to average
      v2 - The second vector to average
      Returns:
      The simple average of the two vectors
    • avg

      @Nonnull public static Vector4 avg(@Nonnull Vector4... values)
      Returns the simple average of the provided vectors. This is equivalent to the centroid in a geometric context.
      Parameters:
      values - The vectors to average
      Returns:
      The simple average of the provided vectors
    • lerp

      @Nonnull public static <V extends Vector<V>> V lerp(@Nonnull V s, @Nonnull V e, double t)
      Performs linear interpolation (LERP) between the starting value s and the ending value e.
      Type Parameters:
      V - The type of vector to use for this operation
      Parameters:
      s - The starting value
      e - The ending value
      t - The interpolation parameter ([0, 1])
      Returns:
      The interpolated value between the starting and ending values s and e
      Throws:
      IllegalArgumentException - When the starting vector and the ending vector have a different dimension count (arithmetic is impossible)
    • lerp

      @Nonnull public static Vector2 lerp(@Nonnull Vector2 s, @Nonnull Vector2 e, double t)
      Performs linear interpolation (LERP) between the starting value s and the ending value e.
      Parameters:
      s - The starting value
      e - The ending value
      t - The interpolation parameter ([0, 1])
      Returns:
      The interpolated value between the starting and ending values s and e
    • lerp

      @Nonnull public static Vector3 lerp(@Nonnull Vector3 s, @Nonnull Vector3 e, double t)
      Performs linear interpolation (LERP) between the starting value s and the ending value e.
      Parameters:
      s - The starting value
      e - The ending value
      t - The interpolation parameter ([0, 1])
      Returns:
      The interpolated value between the starting and ending values s and e
    • lerp

      @Nonnull public static Vector4 lerp(@Nonnull Vector4 s, @Nonnull Vector4 e, double t)
      Performs linear interpolation (LERP) between the starting value s and the ending value e.
      Parameters:
      s - The starting value
      e - The ending value
      t - The interpolation parameter ([0, 1])
      Returns:
      The interpolated value between the starting and ending values s and e
    • min

      @Nonnull public static Vector2 min(@Nonnull Vector2... values)
      Returns the collective minimum vector between the provided vectors.
      Parameters:
      values - The vectors of which to get the minimum vector of
      Returns:
      The minimum vector of the provided vectors
    • min

      @Nonnull public static Vector3 min(@Nonnull Vector3... values)
      Returns the collective minimum vector between the provided vectors.
      Parameters:
      values - The vectors of which to get the minimum vector of
      Returns:
      The minimum vector of the provided vectors
    • min

      @Nonnull public static Vector4 min(@Nonnull Vector4... values)
      Returns the collective minimum vector between the provided vectors.
      Parameters:
      values - The vectors of which to get the minimum vector of
      Returns:
      The minimum vector of the provided vectors
    • max

      @Nonnull public static Vector2 max(@Nonnull Vector2... values)
      Returns the collective maximum vector between the provided vectors.
      Parameters:
      values - The vectors of which to get the maximum vector of
      Returns:
      The maximum vector of the provided vectors
    • max

      @Nonnull public static Vector3 max(@Nonnull Vector3... values)
      Returns the collective maximum vector between the provided vectors.
      Parameters:
      values - The vectors of which to get the maximum vector of
      Returns:
      The maximum vector of the provided vectors
    • max

      @Nonnull public static Vector4 max(@Nonnull Vector4... values)
      Returns the collective maximum vector between the provided vectors.
      Parameters:
      values - The vectors of which to get the maximum vector of
      Returns:
      The maximum vector of the provided vectors