net.jinx.slowmath
Class Vector

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

public class Vector
extends java.lang.Object

Vector is a set of three Real objects, 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.

Vector is completely type neutral.

API Stability: Beta.


Constructor Summary
Vector()
           
Vector(Real[] vec)
          Constructs a new Vector with the given X/Y/Z coordinates.
Vector(Real x, Real y, Real 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(Real v)
          Returns the result of adding v to this Vector.
 Vector add(Vector v)
          Returns the result of adding v to this Vector.
 Vector cross(Vector v)
          Returns a Vector whose value is the cross product of this and v.
 Vector divide(Real v)
          Returns the result of this Vector divided by v.
 Vector divide(Vector v)
          Returns the result of this Vector divided by v.
 Real dot(Vector v)
          Returns a Vector whose value is the dot product of this and v.
 Real getX()
          Provides the X coordinate.
 Real getY()
          Provides the Y coordinate.
 Real getZ()
          Provides the Z coordinate.
 Real magnitude()
          Returns the the following: sqrt(X*X + Y*Y + Z*Z).
 Vector multiply(Real v)
          Returns the result of multiplying v with this Vector.
 Vector multiply(Vector v)
          Returns the result of multiplying v with this Vector.
 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(Real v)
          Returns the result of subtracting v from this Vector.
 Vector subtract(Vector v)
          Returns the result of subtracting v from this Vector.
 double[] toDoubleArray()
          Converts this Vector to a double array.
 float[] toFloatArray()
          Converts this Vector to a float array.
 java.lang.String toString()
          Provides a String representation of this Vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vector

public Vector()

Vector

public Vector(Real x,
              Real y,
              Real 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(Real[] 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. This uses the MathUtil class to parse Real objects for the coordinates in a type-neutral manner.

Parameters:
s - the String to parse.
Method Detail

getX

public Real getX()
Provides the X coordinate.

Returns:
the X coordinate.

getY

public Real getY()
Provides the Y coordinate.

Returns:
the Y coordinate.

getZ

public Real 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 Real dot(Vector v)
Returns a Vector whose value is the dot product of this and v.

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

cross

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

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

add

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

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

add

public Vector add(Real v)
Returns the result of adding v to this Vector.

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

subtract

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

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

subtract

public Vector subtract(Real v)
Returns the result of subtracting v from this Vector.

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

multiply

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

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

multiply

public Vector multiply(Real v)
Returns the result of multiplying v with this Vector.

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

divide

public Vector divide(Vector v)
Returns the result of this Vector divided by v.

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

divide

public Vector divide(Real v)
Returns the result of this Vector divided by v.

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

magnitude

public Real 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 float array.

Returns:
the float array.

toDoubleArray

public double[] toDoubleArray()
Converts this Vector to a double array.

Returns:
the double array.

toString

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

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