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.

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.
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.
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)
          Returns the distance squared between two CombatEntityAPIs.
static float getDistanceSquared(com.fs.starfarer.api.combat.CombatEntityAPI entity, org.lwjgl.util.vector.Vector2f vector)
          Returns the distance squared between a CombatEntityAPI and a Vector2f.
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 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 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.

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).

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.

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.

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.

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.

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).

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

getDistanceSquared

public static float getDistanceSquared(com.fs.starfarer.api.combat.CombatEntityAPI obj1,
                                       com.fs.starfarer.api.combat.CombatEntityAPI obj2)
Returns the distance squared between two CombatEntityAPIs.

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

getDistanceSquared

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

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.

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.

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.

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.

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.

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.

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.

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.
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.

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.
radius - The radius of the circle.
Returns:
A random point along the circumference of the given circle.
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.
radius - The radius of the circle.
Returns:
A random point inside of the given circle.

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.
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.

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.
radius - The radius of the circle.
Returns:
true if point is within the circle, false otherwise.

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.


LazyLib