marf.math
Class Vector

java.lang.Object
  |
  +--marf.math.Matrix
        |
        +--marf.math.Vector
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class Vector
extends Matrix

Algebraic operations on vectors.

NOTE: this class has the same considerations as marf.math.Matrix.

$Id: Vector.java,v 1.12 2005/08/13 23:09:39 susan_fan Exp $

Since:
0.3.0
Version:
$Revision: 1.12 $
Author:
Serguei A. Mokhov
See Also:
Matrix, Serialized Form

Nested Class Summary
 
Nested classes inherited from class marf.math.Matrix
Matrix.Direction
 
Field Summary
static int DEFAULT_VECTOR_LENGTH
          Default vector's length is 3 elements.
 
Fields inherited from class marf.math.Matrix
adMatrix, DEFAULT_COLS, DEFAULT_ERROR_DELTA, DEFAULT_ROWS, iCols, iRows
 
Constructor Summary
Vector()
          Constructs a vector of default length of 3.
Vector(double[] padVectorData)
          Constructs a vector out of a raw array of doubles.
Vector(double[] pad1DMatrix, boolean pbTransposed)
          Allows having a transposed vector upon consuctrion.
Vector(int piVectorLength)
          Constructs a vector with the specified length.
Vector(marf.math.Matrix poMatrix)
          Constructs a vector out of a matrix and forces the rows dimension to 1 and "flattens" the matrix to have the number of columns as the same number of elements in the original matrix.
Vector(marf.math.Vector poVector)
          Constructs a vector from another vector; a-la copy conctructor.
 
Method Summary
 marf.math.Vector add(marf.math.Vector poVector)
          V1 = this + V.
static marf.math.Vector add(marf.math.Vector poLHSVector, marf.math.Vector poRHSVector)
          V3 = V1 + V2.
 java.lang.Object clone()
          Implements Clonable interface.
static marf.math.Vector getCrossProduct(marf.math.Vector poLHSVector, marf.math.Vector poRHSVector)
          Calculates the cross product of two vectors, V3 = V1 x V2.
static double getDotProduct(marf.math.Vector poLHSVector, marf.math.Vector poRHSVector)
          Calculates the dot product of two vectors, d = V1 * V2.
 double getElement(int piPosition)
          Allows getting the value of vector's element at specified position.
static marf.math.Vector getInnerProduct(marf.math.Vector poLHSVector, marf.math.Vector poRHSVector)
          Calculates an inner product of two vectors, V3 = V1 * V2.
 double getLength()
          Retrieves the mathematical length of the vector.
static java.lang.String getMARFSourceCodeRevision()
          Retrieves class' revision.
 marf.math.Vector getUnitVector()
          Returns a unit-vector representation of this vector.
static marf.math.Vector i()
          Creates a unit-vector "i".
 boolean isOrthogonal(marf.math.Vector poVector)
          Tells whether this and the parameter vectors are orthogonal or not.
static marf.math.Vector j()
          Creates a unit-vector "j".
static marf.math.Vector k()
          Creates a unit-vector "k".
 void normalize()
          Normalizes the vector's components by its length.
 void setElement(int piPosition, double pdValue)
          Allows setting the value of vector's element at specified position.
 
Methods inherited from class marf.math.Matrix
add, crop, cutColumn, cutRow, display, divide, divide, equals, equals, exhaustMatrix, extend, extend, getCols, getDeterminant, getElement, getElements, getMatrix2D, getMatrixArray, getRows, inverse, isIdentity, isNearlyIdentity, isNearlyIdentity, isReduced, loadRow, makeIdentity, minus, minus, minusUnary, multiply, multiply, multiply, multiply, multiply, multiply, multiply, rotate, rotate, rotate, rowOperation, rowOperation, rowReduce, scale, scale, scale, setAll, setAll, setAllRandom, setCols, setElement, setMatrix2D, setMatrixArray, setRows, shear, shear, shear, size, toString, translate, translate, translate, transpose
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_VECTOR_LENGTH

public static final int DEFAULT_VECTOR_LENGTH
Default vector's length is 3 elements.

See Also:
Constant Field Values
Constructor Detail

Vector

public Vector()
Constructs a vector of default length of 3.


Vector

public Vector(int piVectorLength)
Constructs a vector with the specified length.

Parameters:
piVectorLength - require vector length

Vector

public Vector(marf.math.Vector poVector)
Constructs a vector from another vector; a-la copy conctructor.

Parameters:
poVector - a vector to make a copy of

Vector

public Vector(marf.math.Matrix poMatrix)
Constructs a vector out of a matrix and forces the rows dimension to 1 and "flattens" the matrix to have the number of columns as the same number of elements in the original matrix.

Parameters:
poMatrix - base matrix to construct the vector from

Vector

public Vector(double[] padVectorData)
Constructs a vector out of a raw array of doubles.

Parameters:
padVectorData - source data for the vector

Vector

public Vector(double[] pad1DMatrix,
              boolean pbTransposed)
Allows having a transposed vector upon consuctrion. Useful for example before doing linear operations.

Parameters:
pad1DMatrix - vector data
pbTransposed - true if the transposed vector is desired
Since:
0.3.0.3
Method Detail

getElement

public final double getElement(int piPosition)
Allows getting the value of vector's element at specified position.

Parameters:
piPosition - index to get the element from
Returns:
vector element's value

setElement

public void setElement(int piPosition,
                       double pdValue)
Allows setting the value of vector's element at specified position.

Parameters:
piPosition - index to det the element at
pdValue - the element's value

getLength

public double getLength()
Retrieves the mathematical length of the vector.

Returns:
the length value

add

public marf.math.Vector add(marf.math.Vector poVector)
V1 = this + V.

Parameters:
poVector - V
Returns:
V1
Since:
0.3.0.3

add

public static marf.math.Vector add(marf.math.Vector poLHSVector,
                                   marf.math.Vector poRHSVector)
V3 = V1 + V2.

Parameters:
poLHSVector - V1
poRHSVector - V2
Returns:
V3
Since:
0.3.0.3

getUnitVector

public final marf.math.Vector getUnitVector()
Returns a unit-vector representation of this vector. This vector remains intact, instead a "unitized" copy is returned.

Returns:
corresponding unit vector

getInnerProduct

public static marf.math.Vector getInnerProduct(marf.math.Vector poLHSVector,
                                               marf.math.Vector poRHSVector)
Calculates an inner product of two vectors, V3 = V1 * V2.

Parameters:
poLHSVector - first vector, V1
poRHSVector - second vector, V2
Returns:
the inner product vector of the two, V3

getCrossProduct

public static marf.math.Vector getCrossProduct(marf.math.Vector poLHSVector,
                                               marf.math.Vector poRHSVector)
Calculates the cross product of two vectors, V3 = V1 x V2. TODO: complete all cases.

Parameters:
poLHSVector - first vector, V1
poRHSVector - second vector, V2
Returns:
the cross product, V3

getDotProduct

public static double getDotProduct(marf.math.Vector poLHSVector,
                                   marf.math.Vector poRHSVector)
Calculates the dot product of two vectors, d = V1 * V2.

Parameters:
poLHSVector - first vector, V1
poRHSVector - second vector, V2
Returns:
the dot product, d

isOrthogonal

public boolean isOrthogonal(marf.math.Vector poVector)
Tells whether this and the parameter vectors are orthogonal or not.

Parameters:
poVector - another vector to compare to
Returns:
true if the vectors are orthogonal

normalize

public void normalize()
Normalizes the vector's components by its length.


i

public static final marf.math.Vector i()
Creates a unit-vector "i".

Returns:
a new vector instante of {1, 0, 0}

j

public static final marf.math.Vector j()
Creates a unit-vector "j".

Returns:
a new vector instante of {0, 1, 0}

k

public static final marf.math.Vector k()
Creates a unit-vector "k".

Returns:
a new vector instante of {0, 0, 1}

clone

public java.lang.Object clone()
Implements Clonable interface. Creates a deep copy of the object by cloning the internal matrix array.

Overrides:
clone in class Matrix
Returns:
object copy of this vector
Since:
0.3.0.3
See Also:
Object.clone()

getMARFSourceCodeRevision

public static java.lang.String getMARFSourceCodeRevision()
Retrieves class' revision.

Returns:
revision string