Class MathUtils

java.lang.Object
io.hymods.lib.utils.MathUtils

public class MathUtils extends Object
Utility class for mathematical and geometric operations
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    angleBetween(com.hypixel.hytale.math.vector.Vector3d a, com.hypixel.hytale.math.vector.Vector3d b)
    Calculates the angle between two vectors in radians
    static double
    angleBetweenDegrees(com.hypixel.hytale.math.vector.Vector3d a, com.hypixel.hytale.math.vector.Vector3d b)
    Calculates the angle between two vectors in degrees
    static double
    clamp(double value, double min, double max)
    Clamps a value between min and max
    static com.hypixel.hytale.math.vector.Vector3d
    closestPointOnLine(com.hypixel.hytale.math.vector.Vector3d point, com.hypixel.hytale.math.vector.Vector3d lineStart, com.hypixel.hytale.math.vector.Vector3d lineEnd)
    Gets the closest point on a line to a given point
    static com.hypixel.hytale.math.vector.Vector3d
    cross(com.hypixel.hytale.math.vector.Vector3d a, com.hypixel.hytale.math.vector.Vector3d b)
    Calculates the cross product of two vectors
    static com.hypixel.hytale.math.vector.Vector3f
    directionToEuler(com.hypixel.hytale.math.vector.Vector3d direction)
    Converts a direction vector to Euler angles
    static double
    distance(com.hypixel.hytale.math.vector.Vector3d from, com.hypixel.hytale.math.vector.Vector3d to)
    Calculates the distance between two points
    static double
    distanceSquared(com.hypixel.hytale.math.vector.Vector3d from, com.hypixel.hytale.math.vector.Vector3d to)
    Calculates the squared distance between two points (faster than distance)
    static double
    dot(com.hypixel.hytale.math.vector.Vector3d a, com.hypixel.hytale.math.vector.Vector3d b)
    Calculates the dot product of two vectors
    static com.hypixel.hytale.math.vector.Vector3d
    eulerToDirection(float yaw, float pitch)
    Converts Euler angles to a direction vector
    static boolean
    isPointInBox(com.hypixel.hytale.math.vector.Vector3d point, com.hypixel.hytale.math.vector.Vector3d boxMin, com.hypixel.hytale.math.vector.Vector3d boxMax)
    Checks if a point is inside a box
    static boolean
    isPointInSphere(com.hypixel.hytale.math.vector.Vector3d point, com.hypixel.hytale.math.vector.Vector3d center, double radius)
    Checks if a point is inside a sphere
    static double
    lerp(double start, double end, double t)
    Lerps between two values
    static com.hypixel.hytale.math.vector.Vector3d
    lerp(com.hypixel.hytale.math.vector.Vector3d start, com.hypixel.hytale.math.vector.Vector3d end, double t)
    Lerps between two vectors
    static com.hypixel.hytale.math.vector.Vector3d
    normalize(com.hypixel.hytale.math.vector.Vector3d vector)
    Normalizes a vector
    static com.hypixel.hytale.math.vector.Vector3d
    project(com.hypixel.hytale.math.vector.Vector3d vector, com.hypixel.hytale.math.vector.Vector3d onto)
    Projects a vector onto another vector
    static com.hypixel.hytale.math.vector.Vector3d
    reflect(com.hypixel.hytale.math.vector.Vector3d vector, com.hypixel.hytale.math.vector.Vector3d normal)
    Reflects a vector off a surface
    static com.hypixel.hytale.math.vector.Vector3d
    rotateAroundY(com.hypixel.hytale.math.vector.Vector3d vector, double angle)
    Rotates a vector around the Y axis

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • distance

      public static double distance(com.hypixel.hytale.math.vector.Vector3d from, com.hypixel.hytale.math.vector.Vector3d to)
      Calculates the distance between two points
      Parameters:
      from - Starting point
      to - Ending point
      Returns:
      The distance
    • distanceSquared

      public static double distanceSquared(com.hypixel.hytale.math.vector.Vector3d from, com.hypixel.hytale.math.vector.Vector3d to)
      Calculates the squared distance between two points (faster than distance)
      Parameters:
      from - Starting point
      to - Ending point
      Returns:
      The squared distance
    • normalize

      public static com.hypixel.hytale.math.vector.Vector3d normalize(com.hypixel.hytale.math.vector.Vector3d vector)
      Normalizes a vector
      Parameters:
      vector - The vector to normalize
      Returns:
      A new normalized vector
    • dot

      public static double dot(com.hypixel.hytale.math.vector.Vector3d a, com.hypixel.hytale.math.vector.Vector3d b)
      Calculates the dot product of two vectors
      Parameters:
      a - First vector
      b - Second vector
      Returns:
      The dot product
    • cross

      public static com.hypixel.hytale.math.vector.Vector3d cross(com.hypixel.hytale.math.vector.Vector3d a, com.hypixel.hytale.math.vector.Vector3d b)
      Calculates the cross product of two vectors
      Parameters:
      a - First vector
      b - Second vector
      Returns:
      The cross product
    • angleBetween

      public static double angleBetween(com.hypixel.hytale.math.vector.Vector3d a, com.hypixel.hytale.math.vector.Vector3d b)
      Calculates the angle between two vectors in radians
      Parameters:
      a - First vector
      b - Second vector
      Returns:
      The angle in radians
    • angleBetweenDegrees

      public static double angleBetweenDegrees(com.hypixel.hytale.math.vector.Vector3d a, com.hypixel.hytale.math.vector.Vector3d b)
      Calculates the angle between two vectors in degrees
      Parameters:
      a - First vector
      b - Second vector
      Returns:
      The angle in degrees
    • lerp

      public static double lerp(double start, double end, double t)
      Lerps between two values
      Parameters:
      start - Starting value
      end - Ending value
      t - Interpolation factor (0-1)
      Returns:
      The interpolated value
    • lerp

      public static com.hypixel.hytale.math.vector.Vector3d lerp(com.hypixel.hytale.math.vector.Vector3d start, com.hypixel.hytale.math.vector.Vector3d end, double t)
      Lerps between two vectors
      Parameters:
      start - Starting vector
      end - Ending vector
      t - Interpolation factor (0-1)
      Returns:
      The interpolated vector
    • clamp

      public static double clamp(double value, double min, double max)
      Clamps a value between min and max
      Parameters:
      value - The value to clamp
      min - Minimum value
      max - Maximum value
      Returns:
      The clamped value
    • eulerToDirection

      public static com.hypixel.hytale.math.vector.Vector3d eulerToDirection(float yaw, float pitch)
      Converts Euler angles to a direction vector
      Parameters:
      yaw - Yaw in radians
      pitch - Pitch in radians
      Returns:
      Direction vector
    • directionToEuler

      public static com.hypixel.hytale.math.vector.Vector3f directionToEuler(com.hypixel.hytale.math.vector.Vector3d direction)
      Converts a direction vector to Euler angles
      Parameters:
      direction - The direction vector
      Returns:
      Vector3f containing yaw, pitch, and roll (roll is always 0)
    • isPointInBox

      public static boolean isPointInBox(com.hypixel.hytale.math.vector.Vector3d point, com.hypixel.hytale.math.vector.Vector3d boxMin, com.hypixel.hytale.math.vector.Vector3d boxMax)
      Checks if a point is inside a box
      Parameters:
      point - The point to check
      boxMin - Minimum corner of the box
      boxMax - Maximum corner of the box
      Returns:
      true if the point is inside the box
    • isPointInSphere

      public static boolean isPointInSphere(com.hypixel.hytale.math.vector.Vector3d point, com.hypixel.hytale.math.vector.Vector3d center, double radius)
      Checks if a point is inside a sphere
      Parameters:
      point - The point to check
      center - Center of the sphere
      radius - Radius of the sphere
      Returns:
      true if the point is inside the sphere
    • project

      public static com.hypixel.hytale.math.vector.Vector3d project(com.hypixel.hytale.math.vector.Vector3d vector, com.hypixel.hytale.math.vector.Vector3d onto)
      Projects a vector onto another vector
      Parameters:
      vector - The vector to project
      onto - The vector to project onto
      Returns:
      The projected vector
    • reflect

      public static com.hypixel.hytale.math.vector.Vector3d reflect(com.hypixel.hytale.math.vector.Vector3d vector, com.hypixel.hytale.math.vector.Vector3d normal)
      Reflects a vector off a surface
      Parameters:
      vector - The incident vector
      normal - The surface normal
      Returns:
      The reflected vector
    • rotateAroundY

      public static com.hypixel.hytale.math.vector.Vector3d rotateAroundY(com.hypixel.hytale.math.vector.Vector3d vector, double angle)
      Rotates a vector around the Y axis
      Parameters:
      vector - The vector to rotate
      angle - The angle in radians
      Returns:
      The rotated vector
    • closestPointOnLine

      public static com.hypixel.hytale.math.vector.Vector3d closestPointOnLine(com.hypixel.hytale.math.vector.Vector3d point, com.hypixel.hytale.math.vector.Vector3d lineStart, com.hypixel.hytale.math.vector.Vector3d lineEnd)
      Gets the closest point on a line to a given point
      Parameters:
      point - The point
      lineStart - Start of the line
      lineEnd - End of the line
      Returns:
      The closest point on the line