Class PhysicsMath

java.lang.Object
com.hypixel.hytale.server.core.modules.physics.util.PhysicsMath

public class PhysicsMath extends Object
Since:
02/05/2019
Version:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
     
    static final double
     
    static final double
     
    static final float
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    computeDragCoefficient(double terminalSpeed, double area, double mass, double gravity)
    Compute drag coefficient from terminal speed when falling in air.
    static double
    computeProjectedArea(double x, double y, double z, Box box)
    Compute area of projection of box onto plane with normal given by direction vector
    static double
    computeProjectedArea(org.joml.Vector3d direction, Box box)
    Compute area of projection of box onto plane with normal given by direction vector
    static double
    computeTerminalSpeed(double dragCoefficient, double area, double mass, double gravity)
    Compute terminal speed from drag coefficient when falling in air.
    static double
    getAcceleration(double speed, double terminalSpeed)
     
    static double
    getRelativeDensity(org.joml.Vector3d position, Box boundingBox)
     
    static double
    getTerminalVelocity(double mass, double density, double areaMillimetersSquared, double dragCoefficient)
     
    static float
    headingFromDirection(double x, double z)
    Get heading from x/z directional vector using game coordinate system.
    static float
    headingX(float heading)
    Compute x component of vector in direction heading.
    static float
    headingZ(float heading)
    Compute z component of vector in direction heading.
    static double
    lengthOfIntersection(double aMin, double aMax, double bMin, double bMax)
    Compute length of overlap of two intervals.
    static float
    normalizeAngle(float rad)
    Convert angle to [0..2*PI[
    static float
    normalizeTurnAngle(float rad)
    Convert angle to [-PI..PI[
    static float
    pitchFromDirection(double x, double y, double z)
    Return pitch from x/y/z direction vector using game coordinate system.
    static float
    pitchX(float pitch)
    Compute x component of vector with given pitch.
    static float
    pitchY(float pitch)
    Compute y component of vector with given pitch.
    static org.joml.Vector3d
    vectorFromAngles(float heading, float pitch, org.joml.Vector3d outDirection)
    Calculate a directional (not necessarily normalized) vector from heading and pitch.
    static double
    volumeOfIntersection(Box a, org.joml.Vector3dc posA, Box b, double posBX, double posBY, double posBZ)
    Compute volume of intersection between to boxes.
    static double
    volumeOfIntersection(Box a, org.joml.Vector3dc posA, Box b, org.joml.Vector3dc posB)
    Compute volume of intersection between to boxes.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • PhysicsMath

      public PhysicsMath()
  • Method Details

    • getAcceleration

      public static double getAcceleration(double speed, double terminalSpeed)
    • getTerminalVelocity

      public static double getTerminalVelocity(double mass, double density, double areaMillimetersSquared, double dragCoefficient)
    • getRelativeDensity

      public static double getRelativeDensity(org.joml.Vector3d position, Box boundingBox)
    • computeDragCoefficient

      public static double computeDragCoefficient(double terminalSpeed, double area, double mass, double gravity)
      Compute drag coefficient from terminal speed when falling in air.
      Parameters:
      terminalSpeed - Desired terminal speed when falling
      area - Area of projection of body along movement direction
      mass - Mass of body
      gravity - Gravity of world
      Returns:
      Drag value so that gravity force and drag force will be in balance when reaching terminal speed
    • computeTerminalSpeed

      public static double computeTerminalSpeed(double dragCoefficient, double area, double mass, double gravity)
      Compute terminal speed from drag coefficient when falling in air.
      Parameters:
      dragCoefficient - Drag coefficient
      area - Area of projection of body along movement direction
      mass - Mass of body
      gravity - Gravity of world
      Returns:
      Speed when gravity force and drag force are in balance
    • computeProjectedArea

      public static double computeProjectedArea(double x, double y, double z, @Nonnull Box box)
      Compute area of projection of box onto plane with normal given by direction vector
      Parameters:
      x - Projection direction x
      y - Projection direction y
      z - Projection direction z
      box - Box to be projected
      Returns:
      Area of projected cuboid onto plane with normal given by x/y/z. if x/y/z isn't normalized result must be divided by length of vector
    • computeProjectedArea

      public static double computeProjectedArea(@Nonnull org.joml.Vector3d direction, @Nonnull Box box)
      Compute area of projection of box onto plane with normal given by direction vector
      Parameters:
      direction - Projection direction
      box - Box to be projected
      Returns:
      Area of projected box onto plane with normal given by direction. if direction isn't normalized result must be divided by length of vector
    • volumeOfIntersection

      public static double volumeOfIntersection(@Nonnull Box a, @Nonnull org.joml.Vector3dc posA, @Nonnull Box b, @Nonnull org.joml.Vector3dc posB)
      Compute volume of intersection between to boxes.
      Parameters:
      a - Box
      posA - Position of box a
      b - Other box
      posB - Position of box b
      Returns:
      Volume of intersection of the two boxes or 0 if no intersection
    • volumeOfIntersection

      public static double volumeOfIntersection(@Nonnull Box a, @Nonnull org.joml.Vector3dc posA, @Nonnull Box b, double posBX, double posBY, double posBZ)
      Compute volume of intersection between to boxes.
      Parameters:
      a - Box
      posA - Position of box a
      b - Other box
      posBX - X coordinate of box b
      posBY - Y coordinate of box b
      posBZ - Z coordinate of box b
      Returns:
      Volume of intersection of the two boxes or 0 if no intersection
    • lengthOfIntersection

      public static double lengthOfIntersection(double aMin, double aMax, double bMin, double bMax)
      Compute length of overlap of two intervals.
      Parameters:
      aMin - Start of first interval
      aMax - End of first interval (must be greater equal start)
      bMin - Start of second interval
      bMax - End of second interval (must be greater equal start)
      Returns:
      Length of overlapping segment or 0 if no overlap
    • headingFromDirection

      public static float headingFromDirection(double x, double z)
      Get heading from x/z directional vector using game coordinate system.
      Parameters:
      x - x component of direction
      z - z component of direction
      Returns:
      heading in radians
    • normalizeAngle

      public static float normalizeAngle(float rad)
      Convert angle to [0..2*PI[
      Parameters:
      rad - angle in radian
      Returns:
      angle in range [0..2*PI[
    • normalizeTurnAngle

      public static float normalizeTurnAngle(float rad)
      Convert angle to [-PI..PI[
      Parameters:
      rad - angle in radian
      Returns:
      angle in range [-PI..PI[
    • pitchFromDirection

      public static float pitchFromDirection(double x, double y, double z)
      Return pitch from x/y/z direction vector using game coordinate system.
      Parameters:
      x - x component of direction
      y - y component of direction
      z - z component of direction
      Returns:
      pitch in radians
    • vectorFromAngles

      @Nonnull public static org.joml.Vector3d vectorFromAngles(float heading, float pitch, @Nonnull org.joml.Vector3d outDirection)
      Calculate a directional (not necessarily normalized) vector from heading and pitch.
      Parameters:
      heading - in radians (game angles)
      pitch - in radians (game angles)
      outDirection - vector to be filled in
      Returns:
      outDirection vector
    • pitchX

      public static float pitchX(float pitch)
      Compute x component of vector with given pitch.
      Parameters:
      pitch - Angle
      Returns:
      Equivalent of cos(pitch)
    • pitchY

      public static float pitchY(float pitch)
      Compute y component of vector with given pitch.
      Parameters:
      pitch - Angle
      Returns:
      Equivalent of sin(heading)
    • headingX

      public static float headingX(float heading)
      Compute x component of vector in direction heading.
      Parameters:
      heading - Angle
      Returns:
      Equivalent of cos(heading)
    • headingZ

      public static float headingZ(float heading)
      Compute z component of vector in direction heading.
      Parameters:
      heading - Angle
      Returns:
      Equivalent of sin(heading)