LazyLib

org.lazywizard.lazylib
Class MathUtils

java.lang.Object
  extended by org.lazywizard.lazylib.MathUtils

public class MathUtils
extends java.lang.Object

Contains methods for working with vectors, angles, distances, and circles.

Since:
1.0
Author:
LazyWizard

Method Summary
static float clampAngle(float angle)
          Clamps an angle within 360 degrees (ex: 400 degrees becomes 40 degrees).
static float getAngle(org.lwjgl.util.vector.Vector2f from, org.lwjgl.util.vector.Vector2f to)
          Returns the angle between two Vector2fs.
static org.lwjgl.util.vector.Vector2f getDirectionalVector(com.fs.starfarer.api.combat.CombatEntityAPI source, com.fs.starfarer.api.combat.CombatEntityAPI destination)
          Returns a normalized Vector2f pointing from source to destination.
static org.lwjgl.util.vector.Vector2f getDirectionalVector(com.fs.starfarer.api.combat.CombatEntityAPI source, org.lwjgl.util.vector.Vector2f destination)
          Returns a normalized Vector2f pointing from source to destination.
static org.lwjgl.util.vector.Vector2f getDirectionalVector(org.lwjgl.util.vector.Vector2f source, org.lwjgl.util.vector.Vector2f destination)
          Returns a normalized Vector2f pointing from source to destination.
static float getDistance(com.fs.starfarer.api.combat.CombatEntityAPI obj1, com.fs.starfarer.api.combat.CombatEntityAPI obj2)
          Returns the distance between two CombatEntityAPIs, including collision radius.
static float getDistance(com.fs.starfarer.api.combat.CombatEntityAPI entity, org.lwjgl.util.vector.Vector2f vector)
          Returns the distance between a CombatEntityAPI and a Vector2f (includes collision radius).
static float getDistance(com.fs.starfarer.api.campaign.SectorEntityToken token1, com.fs.starfarer.api.campaign.SectorEntityToken token2)
          Returns the distance between two SectorEntityTokens.
static float getDistance(com.fs.starfarer.api.campaign.SectorEntityToken token, org.lwjgl.util.vector.Vector2f vector)
          Returns the distance between a SectorEntityToken and a {@link Vector2f).
static float getDistance(org.lwjgl.util.vector.Vector2f vector1, org.lwjgl.util.vector.Vector2f vector2)
          Returns the distance between two Vector2fs.
static float getDistanceSquared(com.fs.starfarer.api.combat.CombatEntityAPI obj1, com.fs.starfarer.api.combat.CombatEntityAPI obj2)
          Deprecated. Use getDistance(com.fs.starfarer.api.combat.CombatEntityAPI, com.fs.starfarer.api.combat.CombatEntityAPI) instead. With the addition of collision radius checking, there's no way to avoid calculating the square root.
static float getDistanceSquared(com.fs.starfarer.api.combat.CombatEntityAPI entity, org.lwjgl.util.vector.Vector2f vector)
          Deprecated. Use getDistance(com.fs.starfarer.api.combat.CombatEntityAPI, org.lwjgl.util.vector.Vector2f) instead. With the addition of collision radius checking, there's no way to avoid calculating the square root.
static float getDistanceSquared(com.fs.starfarer.api.campaign.SectorEntityToken token1, com.fs.starfarer.api.campaign.SectorEntityToken token2)
          Returns the distance squared between two SectorEntityTokens.
static float getDistanceSquared(com.fs.starfarer.api.campaign.SectorEntityToken token, org.lwjgl.util.vector.Vector2f vector)
          Returns the distance squared between a SectorEntityToken and a {@link Vector2f).
static float getDistanceSquared(org.lwjgl.util.vector.Vector2f vector1, org.lwjgl.util.vector.Vector2f vector2)
          Returns the distance squared between two Vector2fs (avoids a costly sqrt()).
static java.util.List<org.lwjgl.util.vector.Vector2f> getEquidistantPointsInsideCircle(org.lwjgl.util.vector.Vector2f center, float radius, float spaceBetweenPoints)
          Returns a List of evenly spaced Vector2fs inside a circle.
static float getFacing(org.lwjgl.util.vector.Vector2f vector)
          Returns the facing of a Vector2f.
static org.lwjgl.util.vector.Vector2f getPointOnCircumference(org.lwjgl.util.vector.Vector2f center, float radius, float angle)
          Returns a point along the circumference of a circle at the given angle.
static java.util.List<org.lwjgl.util.vector.Vector2f> getPointsAlongCircumference(org.lwjgl.util.vector.Vector2f center, float radius, int numPoints, float angleOffset)
          Returns an evenly distributed List of points along a circle's circumference.
static float getRandomNumberInRange(float min, float max)
          Returns a random number within a given range.
static org.lwjgl.util.vector.Vector2f getRandomPointInCircle(org.lwjgl.util.vector.Vector2f center, float radius)
          Returns a random point inside of a circle with uniform distribution.
static org.lwjgl.util.vector.Vector2f getRandomPointOnCircumference(org.lwjgl.util.vector.Vector2f center, float radius)
          Returns a random point along the circumference of a circle.
static boolean isPointWithinBounds(org.lwjgl.util.vector.Vector2f point, com.fs.starfarer.api.combat.CombatEntityAPI entity)
          Deprecated. Use CollisionUtils.isPointWithinBounds(org.lwjgl.util.vector.Vector2f, com.fs.starfarer.api.combat.CombatEntityAPI) instead.
static boolean isPointWithinCircle(org.lwjgl.util.vector.Vector2f point, org.lwjgl.util.vector.Vector2f center, float radius)
          Returns whether a point is within the bounds of a circle or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDistance

public static float getDistance(com.fs.starfarer.api.campaign.SectorEntityToken token1,
                                com.fs.starfarer.api.campaign.SectorEntityToken token2)
Returns the distance between two SectorEntityTokens.

Since:
1.0
See Also:
getDistance(org.lwjgl.util.vector.Vector2f, org.lwjgl.util.vector.Vector2f)

getDistance

public static float getDistance(com.fs.starfarer.api.campaign.SectorEntityToken token,
                                org.lwjgl.util.vector.Vector2f vector)
Returns the distance between a SectorEntityToken and a {@link Vector2f).

Since:
1.1
See Also:
getDistance(org.lwjgl.util.vector.Vector2f, org.lwjgl.util.vector.Vector2f)

getDistance

public static float getDistance(com.fs.starfarer.api.combat.CombatEntityAPI obj1,
                                com.fs.starfarer.api.combat.CombatEntityAPI obj2)
Returns the distance between two CombatEntityAPIs, including collision radius.

Since:
1.0
See Also:
getDistance(org.lwjgl.util.vector.Vector2f, org.lwjgl.util.vector.Vector2f)

getDistance

public static float getDistance(com.fs.starfarer.api.combat.CombatEntityAPI entity,
                                org.lwjgl.util.vector.Vector2f vector)
Returns the distance between a CombatEntityAPI and a Vector2f (includes collision radius).

Since:
1.0
See Also:
getDistance(org.lwjgl.util.vector.Vector2f, org.lwjgl.util.vector.Vector2f)

getDistance

public static float getDistance(org.lwjgl.util.vector.Vector2f vector1,
                                org.lwjgl.util.vector.Vector2f vector2)
Returns the distance between two Vector2fs. For comparing distances, it is vastly more efficient to use getDistanceSquared(org.lwjgl.util.vector.Vector2f, org.lwjgl.util.vector.Vector2f).

Returns:
The distance between the two vectors.
Since:
1.0

getDistanceSquared

public static float getDistanceSquared(com.fs.starfarer.api.campaign.SectorEntityToken token1,
                                       com.fs.starfarer.api.campaign.SectorEntityToken token2)
Returns the distance squared between two SectorEntityTokens.

Since:
1.0
See Also:
getDistanceSquared(org.lwjgl.util.vector.Vector2f, org.lwjgl.util.vector.Vector2f)

getDistanceSquared

public static float getDistanceSquared(com.fs.starfarer.api.campaign.SectorEntityToken token,
                                       org.lwjgl.util.vector.Vector2f vector)
Returns the distance squared between a SectorEntityToken and a {@link Vector2f).

Since:
1.1
See Also:
getDistanceSquared(org.lwjgl.util.vector.Vector2f, org.lwjgl.util.vector.Vector2f)

getDistanceSquared

@Deprecated
public static float getDistanceSquared(com.fs.starfarer.api.combat.CombatEntityAPI obj1,
                                                  com.fs.starfarer.api.combat.CombatEntityAPI obj2)
Deprecated. Use getDistance(com.fs.starfarer.api.combat.CombatEntityAPI, com.fs.starfarer.api.combat.CombatEntityAPI) instead. With the addition of collision radius checking, there's no way to avoid calculating the square root.

Returns the distance squared between two CombatEntityAPIs (includes collision radii).

Since:
1.0
See Also:
getDistanceSquared(org.lwjgl.util.vector.Vector2f, org.lwjgl.util.vector.Vector2f)

getDistanceSquared

@Deprecated
public static float getDistanceSquared(com.fs.starfarer.api.combat.CombatEntityAPI entity,
                                                  org.lwjgl.util.vector.Vector2f vector)
Deprecated. Use getDistance(com.fs.starfarer.api.combat.CombatEntityAPI, org.lwjgl.util.vector.Vector2f) instead. With the addition of collision radius checking, there's no way to avoid calculating the square root.

Returns the distance squared between a CombatEntityAPI and a Vector2f (includes collision radius).

Since:
1.0
See Also:
getDistanceSquared(org.lwjgl.util.vector.Vector2f, org.lwjgl.util.vector.Vector2f)

getDistanceSquared

public static float getDistanceSquared(org.lwjgl.util.vector.Vector2f vector1,
                                       org.lwjgl.util.vector.Vector2f vector2)
Returns the distance squared between two Vector2fs (avoids a costly sqrt()). When comparing distances, use this function instead of getDistance(org.lwjgl.util.vector.Vector2f, org.lwjgl.util.vector.Vector2f).

Returns:
The distance squared between the two vectors.
Since:
1.0

getDirectionalVector

public static org.lwjgl.util.vector.Vector2f getDirectionalVector(org.lwjgl.util.vector.Vector2f source,
                                                                  org.lwjgl.util.vector.Vector2f destination)
Returns a normalized Vector2f pointing from source to destination.

Parameters:
source - The origin of the vector.
destination - The location to point at.
Returns:
A normalized Vector2f pointing at destination.
Since:
1.0

getDirectionalVector

public static org.lwjgl.util.vector.Vector2f getDirectionalVector(com.fs.starfarer.api.combat.CombatEntityAPI source,
                                                                  org.lwjgl.util.vector.Vector2f destination)
Returns a normalized Vector2f pointing from source to destination.

Since:
1.0
See Also:
getDirectionalVector(org.lwjgl.util.vector.Vector2f, org.lwjgl.util.vector.Vector2f)

getDirectionalVector

public static org.lwjgl.util.vector.Vector2f getDirectionalVector(com.fs.starfarer.api.combat.CombatEntityAPI source,
                                                                  com.fs.starfarer.api.combat.CombatEntityAPI destination)
Returns a normalized Vector2f pointing from source to destination.

Since:
1.0
See Also:
getDirectionalVector(org.lwjgl.util.vector.Vector2f, org.lwjgl.util.vector.Vector2f)

clampAngle

public static float clampAngle(float angle)
Clamps an angle within 360 degrees (ex: 400 degrees becomes 40 degrees).

Parameters:
angle - The angle to be clamped.
Returns:
A value between 0 and 360 degrees.
Since:
1.2

getFacing

public static float getFacing(org.lwjgl.util.vector.Vector2f vector)
Returns the facing of a Vector2f.

Parameters:
vector - The vector to get the facing of.
Returns:
The facing (angle) of vector.
Since:
1.0

getAngle

public static float getAngle(org.lwjgl.util.vector.Vector2f from,
                             org.lwjgl.util.vector.Vector2f to)
Returns the angle between two Vector2fs.

Parameters:
from - The source Vector2f.
to - The Vector2f to get the angle to.
Returns:
The angle from from to to.
Since:
1.0

getPointOnCircumference

public static org.lwjgl.util.vector.Vector2f getPointOnCircumference(org.lwjgl.util.vector.Vector2f center,
                                                                     float radius,
                                                                     float angle)
Returns a point along the circumference of a circle at the given angle.

Parameters:
center - The center point of the circle (can be null for a 0, 0 origin).
radius - The radius of the circle.
angle - The angle, in degrees, to get the point at.
Returns:
A Vector2f at [@code angle} degrees along the circumference of the given circle.
Since:
1.0

getRandomPointOnCircumference

public static org.lwjgl.util.vector.Vector2f getRandomPointOnCircumference(org.lwjgl.util.vector.Vector2f center,
                                                                           float radius)
Returns a random point along the circumference of a circle.

Parameters:
center - The center point of the circle (can be null for a 0, 0 origin).
radius - The radius of the circle.
Returns:
A random point along the circumference of the given circle.
Since:
1.0
See Also:
getPointOnCircumference(org.lwjgl.util.vector.Vector2f, float, float)

getRandomPointInCircle

public static org.lwjgl.util.vector.Vector2f getRandomPointInCircle(org.lwjgl.util.vector.Vector2f center,
                                                                    float radius)
Returns a random point inside of a circle with uniform distribution.

Parameters:
center - The center point of the circle (can be null for a 0, 0 origin).
radius - The radius of the circle.
Returns:
A random point inside of the given circle.
Since:
1.0

getPointsAlongCircumference

public static java.util.List<org.lwjgl.util.vector.Vector2f> getPointsAlongCircumference(org.lwjgl.util.vector.Vector2f center,
                                                                                         float radius,
                                                                                         int numPoints,
                                                                                         float angleOffset)
Returns an evenly distributed List of points along a circle's circumference.

Parameters:
center - The center point of the circle (can be null for a 0, 0 origin).
radius - The radius of the circle.
numPoints - How many points to generate.
angleOffset - The offset angle of the initial point.
Returns:
A List of Vector2fs that are evenly distributed along the circle's circumference.
Since:
1.0

isPointWithinCircle

public static boolean isPointWithinCircle(org.lwjgl.util.vector.Vector2f point,
                                          org.lwjgl.util.vector.Vector2f center,
                                          float radius)
Returns whether a point is within the bounds of a circle or not.

Parameters:
point - The Vector2f to check.
center - The center point of the circle (can be null for a 0, 0 origin).
radius - The radius of the circle.
Returns:
true if point is within the circle, false otherwise.
Since:
1.0

getEquidistantPointsInsideCircle

public static java.util.List<org.lwjgl.util.vector.Vector2f> getEquidistantPointsInsideCircle(org.lwjgl.util.vector.Vector2f center,
                                                                                              float radius,
                                                                                              float spaceBetweenPoints)
Returns a List of evenly spaced Vector2fs inside a circle. WARNING: be VERY conservative using this method - a radius of 250 and a spacing of 5 will result in 10,000 circle checks and 7,825 Vector2fs created!

Parameters:
center - The center point of the circle (can be null for a 0, 0 origin).
radius - The radius of the circle.
spaceBetweenPoints - How much space should be between each point.
Returns:
A List of evenly spaced Vector2fs inside a circle.
Since:
1.4

getRandomNumberInRange

public static float getRandomNumberInRange(float min,
                                           float max)
Returns a random number within a given range.

Parameters:
min - The minimum value to select.
max - The maximum value to select.
Returns:
A random Float between min and max.
Since:
1.4

isPointWithinBounds

@Deprecated
public static boolean isPointWithinBounds(org.lwjgl.util.vector.Vector2f point,
                                                     com.fs.starfarer.api.combat.CombatEntityAPI entity)
Deprecated. Use CollisionUtils.isPointWithinBounds(org.lwjgl.util.vector.Vector2f, com.fs.starfarer.api.combat.CombatEntityAPI) instead.

Since:
1.0

LazyLib