Emini Physics Engine 1.3.5a API Documentation

at.emini.physics2D.util
Class FXVector

java.lang.Object
  extended by at.emini.physics2D.util.FXVector

public class FXVector
extends java.lang.Object

The FXVector class represents a 2D Vector. 2D Vector uses fixpoint-math.

Author:
Alexander Adensamer
See Also:
FXUtil

Field Summary
static FXVector M_UNITY
          Unity vector.
 float xFX
          X value of the Vector (FX)
 float yFX
          Y value of the Vector (FX)
 
Constructor Summary
FXVector()
          Empty Constructor.
FXVector(float xFx, float yFx)
          Constructor with x and y coordinates.
FXVector(FXVector other)
          Copy constructor.
 
Method Summary
 void add(FXVector other)
          Adds a vector.
 void add(FXVector vector, float scaleFX)
          Adds a vector after scaling it.
 void add2FX(FXVector other, float scale2FX)
          Adds a vector after scaling it (2FX).
 void addFX(float xFX, float yFX, float scaleFX)
          Adds a vector (given as two coordinates) after scaling it.
 void assign(FXVector other)
          Copies the values of another vector.
 void assignDiff(FXVector v1, FXVector v2)
          Assigns the difference vector between two points/vectors.
 void assignFX(float xFX, float yFX)
          Assign values to the vector.
 void assignScaledFX(FXVector other, float scaleFX)
          Copies and scaled the values of another vector.
 float crossFX(FXVector other)
          Computes the cross product of two vectors.
 void crossScalar2FX(float val2FX)
          Computes cross product with a scalar (2FX).
 void crossScalarFX(float valFX)
          Computes cross product with a scalar (FX).
 float distanceFX(FXVector a, FXVector b)
          Calculates the distance to a line.
 float distanceFX(FXVector a, FXVector b, FXVector n, float abDistFX)
          Calculates the distance to a line (supplying normal and distance).
 float distFX(FXVector other)
          Distance to another vector.
 void divideBy(int val)
          Divides the vector.
 void divideByFX(float valFX)
          Divides the vector (FX).
 FXVector dividedByFX(float valFX)
          Creates a copy divided by a factor (FX).
 float dotFX(FXVector other)
          Computes the dot product of two vectors.
 boolean equals(java.lang.Object other)
          Equals operator for vectors.
 float fastLengthFX()
          Calculates the length of the vector (fast).
static float fastLengthFX(float xFX, float yFX)
          Calculates the length of a vector, supplied as x and y coordinates (fast).
static boolean intersect(FXVector a1, FXVector b1, FXVector a2, FXVector b2, FXVector x)
          Intersects two lines.
 boolean isInRect(FXVector ul, FXVector lr)
          Checks if vector is within a rectangle.
 boolean leftOf(FXVector a, FXVector b)
          Determines the hemisphere of a point with respect to a line.
 float lengthFX()
          Calculates the length of the vector.
 int lengthSquare()
          Calculates the square of the length of the vector.
 float lengthSquareFX()
          Calculates the square of the length of the vector (FX).
 void max(FXVector vector)
          Maximizes the vector to a reference vector.
 void maxFX(float cFX)
          Maximizes both x and y component.
 void min(FXVector vector)
          Minimizes the vector to a reference vector.
 void minFX(float cFX)
          Minimizes both x and y component.
 void mult(int val)
          Scales the vector.
 void multFX(float valFX)
          Scales the vector (FX).
static FXVector newVector(int x, int y)
          Creates a new vector.
 void normalize()
          Normalizes the vector.
 void normalizeFast()
          Normalizes the vector (fast).
 void normalizePrecise()
          Normalizes the vector.
 float preciseLengthFX()
          Calculates the length of the vector.
 void subtract(FXVector vector)
          Subtract a vector.
 FXVector times(int val)
          Creates a copy multiplied by a factor.
 FXVector timesFX(float valFX)
          Creates a copy multiplied by a factor (FX).
 void transpose()
          Transposes the vector.
 void turnRight()
          Turns the vector to the right by 90 degrees.
 int xAsInt()
          Gets the x coordinate as int.
 int yAsInt()
          Gets the y coordinate as int.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xFX

public float xFX
X value of the Vector (FX)


yFX

public float yFX
Y value of the Vector (FX)


M_UNITY

public static final FXVector M_UNITY
Unity vector.

Constructor Detail

FXVector

public FXVector()
Empty Constructor.


FXVector

public FXVector(float xFx,
                float yFx)
Constructor with x and y coordinates.

Parameters:
xFx - x Value of the vector (FX).
yFx - y Value of the vector (FX).

FXVector

public FXVector(FXVector other)
Copy constructor.

Parameters:
other - vector
Method Detail

newVector

public static FXVector newVector(int x,
                                 int y)
Creates a new vector. The parameters are supplied as non-FX values.

Parameters:
x - x Value of the vector.
y - y Value of the vector.
Returns:
newly created vector.

assign

public final void assign(FXVector other)
Copies the values of another vector.

Parameters:
other - source vector

assignFX

public final void assignFX(float xFX,
                           float yFX)
Assign values to the vector.

Parameters:
xFX - x Value of the vector (FX).
yFX - y Value of the vector (FX).

assignDiff

public final void assignDiff(FXVector v1,
                             FXVector v2)
Assigns the difference vector between two points/vectors. Calculates: v1 - v2.

Parameters:
v1 - end point of the vector.
v2 - start point of the vector.

assignScaledFX

public final void assignScaledFX(FXVector other,
                                 float scaleFX)
Copies and scaled the values of another vector.

Parameters:
other - source vector
scaleFX - the scale factor

equals

public boolean equals(java.lang.Object other)
Equals operator for vectors.

Overrides:
equals in class java.lang.Object
Returns:
true if the vectors are euqal.

add

public final void add(FXVector other)
Adds a vector.

Parameters:
other - vector to add.

add

public final void add(FXVector vector,
                      float scaleFX)
Adds a vector after scaling it.

Parameters:
vector - vector to add.
scaleFX - scaling factor of the add Vector (FX).

addFX

public final void addFX(float xFX,
                        float yFX,
                        float scaleFX)
Adds a vector (given as two coordinates) after scaling it.

Parameters:
xFX - x coordinate (FX) to add.
yFX - y coordinate (FX) to add.
scaleFX - scaling factor of the add Vector.

add2FX

public final void add2FX(FXVector other,
                         float scale2FX)
Adds a vector after scaling it (2FX). The scaling factor is supplied as double precision FX int.

Parameters:
other - vector to add.
scale2FX - scaling factor (2FX) of the add Vector.

subtract

public final void subtract(FXVector vector)
Subtract a vector.

Parameters:
vector - vector to subtract

multFX

public final void multFX(float valFX)
Scales the vector (FX).

Parameters:
valFX - scale factor (FX).

mult

public final void mult(int val)
Scales the vector.

Parameters:
val - scale factor.

timesFX

public final FXVector timesFX(float valFX)
Creates a copy multiplied by a factor (FX).

Parameters:
valFX - scale factor (FX).

times

public final FXVector times(int val)
Creates a copy multiplied by a factor.

Parameters:
val - scale factor

dividedByFX

public final FXVector dividedByFX(float valFX)
Creates a copy divided by a factor (FX).

Parameters:
valFX - divide factor (FX)

divideByFX

public final void divideByFX(float valFX)
Divides the vector (FX).

Parameters:
valFX - divide factor (FX).

divideBy

public final void divideBy(int val)
Divides the vector.

Parameters:
val - scale factor.

transpose

public final void transpose()
Transposes the vector.


turnRight

public final void turnRight()
Turns the vector to the right by 90 degrees.


lengthSquare

public final int lengthSquare()
Calculates the square of the length of the vector.

Returns:
the square of the length.

lengthSquareFX

public final float lengthSquareFX()
Calculates the square of the length of the vector (FX).

Returns:
the square of the length (FX).

lengthFX

public final float lengthFX()
Calculates the length of the vector. This method is more precise, but slower than the fastLengthFX().

Returns:
the length of the vector(FX).

preciseLengthFX

public final float preciseLengthFX()
Calculates the length of the vector. This method is more precise, but slower than the fastLengthFX().

Returns:
the length of the vector(FX).

fastLengthFX

public static final float fastLengthFX(float xFX,
                                       float yFX)
Calculates the length of a vector, supplied as x and y coordinates (fast). Convenience method to avoid creating a vector.

Parameters:
xFX - the x coordinate (FX).
yFX - the y coordinate (FX).
Returns:
the length of the vector(FX).

fastLengthFX

public final float fastLengthFX()
Calculates the length of the vector (fast). Convenience method to avoid creating a vector. This method is faster but less precise than the lengthFX().

Returns:
the length of the vector(FX).

distFX

public final float distFX(FXVector other)
Distance to another vector.

Parameters:
other - other vector.
Returns:
the distance (FX).

normalize

public final void normalize()
Normalizes the vector. The vector is scaled so that its length becomes 1.


normalizePrecise

public final void normalizePrecise()
Normalizes the vector. The vector is scaled so that its length becomes 1.


normalizeFast

public final void normalizeFast()
Normalizes the vector (fast). This uses the fast length method (fastLengthFX()).


dotFX

public final float dotFX(FXVector other)
Computes the dot product of two vectors.

Parameters:
other - vector to compute the dot product with.
Returns:
the dot product (FX).

crossFX

public final float crossFX(FXVector other)
Computes the cross product of two vectors.
Note: The 2D cross product returns the z coordinate of the 3D vector (0,0,z).

Parameters:
other - vector to compute the cross product with.
Returns:
the cross product (FX).

crossScalarFX

public final void crossScalarFX(float valFX)
Computes cross product with a scalar (FX).

Parameters:
valFX - scale factor (FX) for the unit vector of the cross product.

crossScalar2FX

public final void crossScalar2FX(float val2FX)
Computes cross product with a scalar (2FX).

Parameters:
val2FX - scale factor (2FX) for the unit vector of the cross product.

distanceFX

public final float distanceFX(FXVector a,
                              FXVector b,
                              FXVector n,
                              float abDistFX)
Calculates the distance to a line (supplying normal and distance). This method is faster than distanceFX(FXVector, FXVector) if the normal and distance are available and do not have to be computed.

Parameters:
a - start point of the line.
b - end point of the line.
n - the normalized vector between a and b (b - a)/|b - a|.
abDistFX - distance between a and b.
Returns:
the distance of the point to the line if the projection lies between a and b, otherwise maxint.

distanceFX

public final float distanceFX(FXVector a,
                              FXVector b)
Calculates the distance to a line.

Parameters:
a - start point of the line.
b - end point of the line.
Returns:
the distance of the point to the line if the projection lies between a and b, otherwise maxint.

leftOf

public final boolean leftOf(FXVector a,
                            FXVector b)
Determines the hemisphere of a point with respect to a line.

Parameters:
a - start point of line segment.
b - end point of line segment.
Returns:
true if this point lies left of the line segment a-b.

intersect

public static boolean intersect(FXVector a1,
                                FXVector b1,
                                FXVector a2,
                                FXVector b2,
                                FXVector x)
Intersects two lines.

Parameters:
a1 - start of line 1.
b1 - end of line 1.
a2 - start of line 2.
b2 - end of line 2.
x - target vector for the intersection point.
Returns:
triue if two lines intersect.

maxFX

public final void maxFX(float cFX)
Maximizes both x and y component.

Parameters:
cFX - minimum value for each coordinate

minFX

public final void minFX(float cFX)
Minimizes both x and y component.

Parameters:
cFX - maximum value for each coordinate.

max

public final void max(FXVector vector)
Maximizes the vector to a reference vector. Each coordinate is treated separately.

Parameters:
vector - minimum value for each coordinate.

min

public final void min(FXVector vector)
Minimizes the vector to a reference vector. Each coordinate is treated separately.

Parameters:
vector - maximum value for each coordinate.

isInRect

public final boolean isInRect(FXVector ul,
                              FXVector lr)
Checks if vector is within a rectangle.

Parameters:
ul - the upper left corner of the rectangle.
lr - the lower right corner of the rectangle.
Returns:
true if the vector is within the rectangle.

xAsInt

public final int xAsInt()
Gets the x coordinate as int.

Returns:
the x coordinate as int.

yAsInt

public final int yAsInt()
Gets the y coordinate as int.

Returns:
the y coordinate as int.

Emini Physics Engine 1.3.5a API Documentation

Emini Physics Engine 1.3.5a API Documentation - Copyright 2014 Alexander Adensamer