net.jinx.math
Class Vector

java.lang.Object
  extended by net.jinx.math.Vector

public class Vector
extends java.lang.Object

Vector is a set of three floats, as X/Y/Z coordinates. There are operations for regular math (that function on all three seperately), as well as operations that are Vector specific.

API Stability: Beta.


Field Summary
static Vector zero
           
 
Constructor Summary
Vector()
          Constructs a Vector with all zero components.
Vector(float[] vec)
          Constructs a new Vector with the given X/Y/Z coordinates.
Vector(float x, float y, float z)
          Constructs a new Vector with the given X/Y/Z coordinates.
Vector(java.lang.String s)
          Constructs a new Vector by parsing the given String.
 
Method Summary
 Vector abs()
          Returns a Vector whose components have had their sign removed.
 Vector add(float v)
          Returns the result of adding v to this Vector's components.
 Vector add(Vector v)
          Returns the result of adding v's components to this Vector's components.
 Vector cross(Vector v)
          Returns a Vector whose value is the cross product of this and v.
 Vector divide(float v)
          Returns the result of this Vector's components divided by v's components.
 Vector divide(Vector v)
          Returns the result of this Vector's compoenents divided by v's components.
 float dot(Vector v)
          Returns a float whose value is the dot product of this and v.
 boolean equals(java.lang.Object obj)
           
 void fillFloatArray(float[] fa)
          Fills a length 3 float array with the values for getX(), getY() and getZ().
 float getX()
          Provides the X coordinate.
 float getY()
          Provides the Y coordinate.
 float getZ()
          Provides the Z coordinate.
 int hashCode()
          Returns the hash code for this Vector.
 float magnitude()
          Returns the the following: sqrt(X*X + Y*Y + Z*Z).
 Vector multiply(float v)
          Returns the result of multiplying v with this Vector's components.
 Vector multiply(Vector v)
          Returns the result of multiplying v's components with this Vector's components.
 Vector negate()
          Negates each component of this Vector.
 Vector normalize()
          Divides this Vector by it's magnitude to produce a normalized version of it.
 Vector subtract(float v)
          Returns the result of subtracting v from this Vector's components.
 Vector subtract(Vector v)
          Returns the result of subtracting v's components from this Vector's components.
 float[] toFloatArray()
          Converts this Vector to a (new) float array.
 java.lang.String toString()
          Provides a String representation of this Vector.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

zero

public static final Vector zero
Constructor Detail

Vector

public Vector()
Constructs a Vector with all zero components.


Vector

public Vector(float x,
              float y,
              float z)
Constructs a new Vector with the given X/Y/Z coordinates.

Parameters:
x - the X coordinate.
y - the Y coordinate.
z - the Z coordinate.

Vector

public Vector(float[] vec)
Constructs a new Vector with the given X/Y/Z coordinates.

Parameters:
vec - the coordinates in an array.

Vector

public Vector(java.lang.String s)
Constructs a new Vector by parsing the given String.

Parameters:
s - the String to parse.
Method Detail

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

getX

public float getX()
Provides the X coordinate.

Returns:
the X coordinate.

getY

public float getY()
Provides the Y coordinate.

Returns:
the Y coordinate.

getZ

public float getZ()
Provides the Z coordinate.

Returns:
the Z coordinate.

abs

public Vector abs()
Returns a Vector whose components have had their sign removed.

Returns:
the Vector.

dot

public float dot(Vector v)
Returns a float whose value is the dot product of this and v.

Parameters:
v - the Vector to use.
Returns:
the float.

cross

public Vector cross(Vector v)
Returns a Vector whose value is the cross product of this and v. Remember, A x B is not equal to B x A, so order is important.

Parameters:
v - the Vector to use.
Returns:
the Vector.

add

public Vector add(Vector v)
Returns the result of adding v's components to this Vector's components.

Parameters:
v - the Vector to add.
Returns:
the Vector.

add

public Vector add(float v)
Returns the result of adding v to this Vector's components.

Parameters:
v - the float to add.
Returns:
the Vector.

subtract

public Vector subtract(Vector v)
Returns the result of subtracting v's components from this Vector's components.

Parameters:
v - the Vector to subtract.
Returns:
the Vector.

subtract

public Vector subtract(float v)
Returns the result of subtracting v from this Vector's components.

Parameters:
v - the float to subtract.
Returns:
the Vector.

multiply

public Vector multiply(Vector v)
Returns the result of multiplying v's components with this Vector's components.

Parameters:
v - the Vector to multiply.
Returns:
the Vector.

multiply

public Vector multiply(float v)
Returns the result of multiplying v with this Vector's components.

Parameters:
v - the float to multiply.
Returns:
the Vector.

divide

public Vector divide(Vector v)
Returns the result of this Vector's compoenents divided by v's components.

Parameters:
v - the Vector to divide by.
Returns:
the Vector.

divide

public Vector divide(float v)
Returns the result of this Vector's components divided by v's components.

Parameters:
v - the float to divide by.
Returns:
the Vector.

magnitude

public float magnitude()
Returns the the following: sqrt(X*X + Y*Y + Z*Z).

Returns:
the result.

negate

public Vector negate()
Negates each component of this Vector.

Returns:
the negated version of this Vector.

normalize

public Vector normalize()
Divides this Vector by it's magnitude to produce a normalized version of it.

Returns:
the normalized version of this Vector.

toFloatArray

public float[] toFloatArray()
Converts this Vector to a (new) float array.

Returns:
the float array.

fillFloatArray

public void fillFloatArray(float[] fa)
Fills a length 3 float array with the values for getX(), getY() and getZ().

Parameters:
fa - the float array to fill.
Throws:
java.lang.IllegalArgumentException - if fa is not length 3.

toString

public java.lang.String toString()
Provides a String representation of this Vector.

Overrides:
toString in class java.lang.Object
Returns:
the String.

hashCode

public int hashCode()
Returns the hash code for this Vector.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code of the magnitude as per Float.floatToIntBits(float).