marf.math
Class Vector

java.lang.Object
  extended by marf.math.Matrix
      extended by marf.math.Vector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

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.14 2007/12/18 03:45:42 mokhov Exp $

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

Nested Class Summary
 
Nested classes/interfaces 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 construction.
Vector(int piVectorLength)
          Constructs a vector with the specified length.
Vector(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(Vector poVector)
          Constructs a vector from another vector; a-la copy conctructor.
 
Method Summary
 Vector add(Vector poVector)
          V1 = this + V.
static Vector add(Vector poLHSVector, Vector poRHSVector)
          V3 = V1 + V2.
 java.lang.Object clone()
          Implements Clonable interface.
static Vector getCrossProduct(Vector poLHSVector, Vector poRHSVector)
          Calculates the cross product of two vectors, V3 = V1 x V2.
static double getDotProduct(Vector poLHSVector, 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 Vector getInnerProduct(Vector poLHSVector, 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.
 Vector getUnitVector()
          Returns a unit-vector representation of this vector.
static Vector i()
          Creates a unit-vector "i".
 boolean isOrthogonal(Vector poVector)
          Tells whether this and the parameter vectors are orthogonal or not.
static Vector j()
          Creates a unit-vector "j".
static 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, add, add, applyAdd, applyMinus, applyMultiply, applyMultiply, crop, crop, cutColumn, cutFirstColumn, cutFirstRow, cutLastColumn, cutLastRow, cutRow, display, divide, divide, divide, equals, equals, equals, exhaustMatrix, extend, extend, extend, getCols, getColumn, getDeterminant, getElement, getElements, getMatrix2D, getMatrixArray, getNewMatrix, getNewMatrix, getRow, getRows, inverse, isIdentity, isNearlyIdentity, isNearlyIdentity, isReduced, loadColumn, loadRow, makeIdentity, minus, minus, minus, minus, minusUnary, multiply, multiply, multiply, multiply, multiply, multiply, multiply, pow, pow, 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
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(Vector poVector)
Constructs a vector from another vector; a-la copy conctructor.

Parameters:
poVector - a vector to make a copy of

Vector

public Vector(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 construction. 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 set 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 Vector add(Vector poVector)
V1 = this + V.

Parameters:
poVector - V
Returns:
V1
Since:
0.3.0.3

add

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

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

getUnitVector

public final 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 Vector getInnerProduct(Vector poLHSVector,
                                     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 Vector getCrossProduct(Vector poLHSVector,
                                     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(Vector poLHSVector,
                                   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(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 Vector i()
Creates a unit-vector "i".

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

j

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

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

k

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

Returns:
a new vector instance 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
Since:
0.3.0.2


SourceForge Logo