Class MathUtils
java.lang.Object
io.hymods.lib.utils.MathUtils
Utility class for mathematical and geometric operations
-
Method Summary
Modifier and TypeMethodDescriptionstatic doubleangleBetween(com.hypixel.hytale.math.vector.Vector3d a, com.hypixel.hytale.math.vector.Vector3d b) Calculates the angle between two vectors in radiansstatic doubleangleBetweenDegrees(com.hypixel.hytale.math.vector.Vector3d a, com.hypixel.hytale.math.vector.Vector3d b) Calculates the angle between two vectors in degreesstatic doubleclamp(double value, double min, double max) Clamps a value between min and maxstatic com.hypixel.hytale.math.vector.Vector3dclosestPointOnLine(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 pointstatic com.hypixel.hytale.math.vector.Vector3dcross(com.hypixel.hytale.math.vector.Vector3d a, com.hypixel.hytale.math.vector.Vector3d b) Calculates the cross product of two vectorsstatic com.hypixel.hytale.math.vector.Vector3fdirectionToEuler(com.hypixel.hytale.math.vector.Vector3d direction) Converts a direction vector to Euler anglesstatic doubledistance(com.hypixel.hytale.math.vector.Vector3d from, com.hypixel.hytale.math.vector.Vector3d to) Calculates the distance between two pointsstatic doubledistanceSquared(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 doubledot(com.hypixel.hytale.math.vector.Vector3d a, com.hypixel.hytale.math.vector.Vector3d b) Calculates the dot product of two vectorsstatic com.hypixel.hytale.math.vector.Vector3deulerToDirection(float yaw, float pitch) Converts Euler angles to a direction vectorstatic booleanisPointInBox(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 boxstatic booleanisPointInSphere(com.hypixel.hytale.math.vector.Vector3d point, com.hypixel.hytale.math.vector.Vector3d center, double radius) Checks if a point is inside a spherestatic doublelerp(double start, double end, double t) Lerps between two valuesstatic com.hypixel.hytale.math.vector.Vector3dlerp(com.hypixel.hytale.math.vector.Vector3d start, com.hypixel.hytale.math.vector.Vector3d end, double t) Lerps between two vectorsstatic com.hypixel.hytale.math.vector.Vector3dnormalize(com.hypixel.hytale.math.vector.Vector3d vector) Normalizes a vectorstatic com.hypixel.hytale.math.vector.Vector3dproject(com.hypixel.hytale.math.vector.Vector3d vector, com.hypixel.hytale.math.vector.Vector3d onto) Projects a vector onto another vectorstatic com.hypixel.hytale.math.vector.Vector3dreflect(com.hypixel.hytale.math.vector.Vector3d vector, com.hypixel.hytale.math.vector.Vector3d normal) Reflects a vector off a surfacestatic com.hypixel.hytale.math.vector.Vector3drotateAroundY(com.hypixel.hytale.math.vector.Vector3d vector, double angle) Rotates a vector around the Y axis
-
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 pointto- 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 pointto- 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 vectorb- 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 vectorb- 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 vectorb- 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 vectorb- 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 valueend- Ending valuet- 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 vectorend- Ending vectort- 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 clampmin- Minimum valuemax- 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 radianspitch- 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 checkboxMin- Minimum corner of the boxboxMax- 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 checkcenter- Center of the sphereradius- 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 projectonto- 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 vectornormal- 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 rotateangle- 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 pointlineStart- Start of the linelineEnd- End of the line- Returns:
- The closest point on the line
-