driver.ted.utilities
Class T_Vector

java.lang.Object
  extended by driver.ted.utilities.T_Vector
All Implemented Interfaces:
java.io.Serializable

public class T_Vector
extends java.lang.Object
implements java.io.Serializable

Title: T_Vector
Description: This class provides the scientific vector functionality. The precision variable is used for display purposes, the actual value used in calculations is the full value allowed by a double.
Copyright: (c) 2002 - 2006
Change History:

Version:
1.1
Author:
Ted Driver
See Also:
Serialized Form

Constructor Summary
T_Vector()
          Default Constructor.
T_Vector(double x, double y, double z)
          Constructor specifying three doubles with which to initialze a three-dimensional vector.
T_Vector(double x, double y, double z, int precision)
          Constructor specifying initial values and a precision for a vector.
T_Vector(int size)
          Constructor specifying an integer size.
T_Vector(int size, int precision)
          Constructor specifying an integer size and an integer precision.
 
Method Summary
 T_Vector cross(T_Vector v)
          Cross Product function for vectors Usage: v3 = v1xv2 is implemented as v3 = v1.cross(v2)
 double dot(T_Vector v)
          Dot Product function for vectors Usage: x = v1*v2 is implemented as x = v1.dot(v2)
 double getElement(int index)
          Accessor function to return an element at the specified index.
 int getPrecision()
          Accessor function to return the precision value for the vector.
 int getSize()
          Returns the size of the vector.
 double magnitude()
          Method to return the magnitude of the vector The magnitude is calculated as sqrt(x^2 + y^2 + z^2 + ...)
static void main(java.lang.String[] args)
          An executable function to test the Vector Library.
 T_Vector plus(T_Vector v)
          Addition function for vectors Usage: v3 = v1 + v2 is implemented as v3 = v1.plus(v2)
 void setElement(int index, double value)
          Method to set an individual element within the vector.
 java.lang.String toString()
          Method to display the vector in convienent notation.
 T_Vector unit()
          Method to return the unit vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

T_Vector

public T_Vector()
Default Constructor. The size of the Vector is set to 3, indexed from 0 to 2 [0,1,2] The precision of the vector is set to 3 decimal places.


T_Vector

public T_Vector(int size)
Constructor specifying an integer size. A Vector will be allocated of the specified size. Size must be greater than zero. The precision of the vector is set to 3 decimal places.

Parameters:
size - The size of the vector, otherwise known as the length. The returned vector will have n elements indexed from 0 to size-1.

T_Vector

public T_Vector(int size,
                int precision)
Constructor specifying an integer size and an integer precision. The returned vector will have the size specified by size. Size must be greater than zero. The returned vector will have a precision specified by precision and precision must be greater than 1 and less than or equal to 15.

Parameters:
size - The size of the vector, otherwise known as the length. The returned vector will have size elements indexed from 0 to size-1.
precision - The precision of the vector; the number of places to the right of the decimal point.

T_Vector

public T_Vector(double x,
                double y,
                double z)
Constructor specifying three doubles with which to initialze a three-dimensional vector. The returned vector will have a size of 3. The returned vector will have a precision of 3 decimal places.

Parameters:
x - The x value of the vector, indexed by 0.
y - The y value of the vector, indexed by 1.
z - The z value of the vector, indexed by 2.

T_Vector

public T_Vector(double x,
                double y,
                double z,
                int precision)
Constructor specifying initial values and a precision for a vector. The returned vector will have a size of 3. The returned vector will have a precision specified by precision and precision must be greater than 1 and less than or equal to 15.

Parameters:
x - The x value of the vector, indexed by 0.
y - The y value of the vector, indexed by 1.
z - The z value of the vector, indexed by 2.
precision - The number of decimal places required for this vector's elements.
Method Detail

getSize

public int getSize()
Returns the size of the vector. The returned int will indicate the number of elements in the vector, indexed from 0 to getSize() - 1

Returns:
int The size of the vector

getElement

public double getElement(int index)
Accessor function to return an element at the specified index. The returned double is the value stored at index

Parameters:
index - The index in the vector array for the element to be returned
Returns:
double The value at index index

getPrecision

public int getPrecision()
Accessor function to return the precision value for the vector. The returned int will be from 1 to 15 inclusive.

Returns:
int The precision value for this vector

setElement

public void setElement(int index,
                       double value)
                throws java.lang.ArrayIndexOutOfBoundsException
Method to set an individual element within the vector. The element specified by index will be set to the value specified by value

Parameters:
index - The index in the vector for which the value will be changed
value - The value to set at element index
Throws:
java.lang.ArrayIndexOutOfBoundsException - The index must be between 0 and getSize() - 1

toString

public java.lang.String toString()
Method to display the vector in convienent notation.

Overrides:
toString in class java.lang.Object
Returns:
The vector; [x,y,z,...]

plus

public T_Vector plus(T_Vector v)
              throws java.lang.ArrayIndexOutOfBoundsException
Addition function for vectors Usage: v3 = v1 + v2 is implemented as v3 = v1.plus(v2)

v3[0] = v1[0] + v2[0]

v3[1] = v1[1] + v2[1] etc.

Parameters:
v - The vector to add
Returns:
The resultant T_Vector
Throws:
java.lang.ArrayIndexOutOfBoundsException - If the vectors are not the same size

cross

public T_Vector cross(T_Vector v)
               throws java.lang.ArrayIndexOutOfBoundsException
Cross Product function for vectors Usage: v3 = v1xv2 is implemented as v3 = v1.cross(v2)

v3[0] = v1[1]*v2[2] - v2[1]*v1[2]

v3[1] = v1[0]*v2[2] - v2[0]*v1[2]

v3[2] = v1[0]*v2[1] - v2[0]*v1[1]

Parameters:
v - The vector to cross into
Returns:
The vector representing the cross product of v1 and v2.
Throws:
java.lang.ArrayIndexOutOfBoundsException - If the vectors are not the same size

dot

public double dot(T_Vector v)
           throws java.lang.ArrayIndexOutOfBoundsException
Dot Product function for vectors Usage: x = v1*v2 is implemented as x = v1.dot(v2)

x = v1[0]*v2[0] + v1[1]*v2[1] + ...

Parameters:
v - The vector to dot into
Returns:
The double value representing the dot product of v1 and v2, or the maximum value a double can attain, if an exception is thrown.
Throws:
java.lang.ArrayIndexOutOfBoundsException - If the vectors are not the same size, or if the vector size is not equal to 3.

unit

public T_Vector unit()
Method to return the unit vector. This method will ensure that the magnitude of the returned vector is 1. The returned vector is [x/magnitude(), y/magnitude(), ...], where x and y are the components of the vector and magnitude() is the magnitude of the vector

Returns:
The unitized vector

magnitude

public double magnitude()
Method to return the magnitude of the vector The magnitude is calculated as sqrt(x^2 + y^2 + z^2 + ...)

Returns:
A double representing the magnitude of the vector

main

public static void main(java.lang.String[] args)
An executable function to test the Vector Library. This will display a message box with Vector results displayed.

Parameters:
args - Argument string to the test program. (Not needed for this test program)