org.openmali.vecmath2
Class VectorNf

java.lang.Object
  extended by org.openmali.vecmath2.TupleNf<VectorNf>
      extended by org.openmali.vecmath2.VectorNf
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, TupleInterface<VectorNf>, VectorInterface<VectorNf,VectorNf>
Direct Known Subclasses:
Vector4f

public class VectorNf
extends TupleNf<VectorNf>
implements java.io.Externalizable, VectorInterface<VectorNf,VectorNf>

A float precision, general one dimensional vector class. Index numbering is zero-based. Inspired by Kenji Hiranabe's GVector implementation

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.openmali.vecmath2.TupleNf
isDirty, roTrick, values
 
Constructor Summary
protected VectorNf(boolean readOnly, float[] values, boolean[] isDirty, boolean copy)
          Constructs a new generalized mathematic Vector with zero elements; length reprents the number of elements in the vector. !!
protected VectorNf(boolean readOnly, float[] values, int start, int length)
          Constructs a new Vector by copying length elements from the array parameter.
protected VectorNf(boolean readOnly, int length)
          Constructs a new generalized mathematic Vector with zero elements; length reprents the number of elements in the vector.
protected VectorNf(boolean readOnly, TupleNf<?> vector)
          Constructs a new Vector and copies the initial values from the parameter vector.
  VectorNf(float[] values)
          Constructs a new generalized mathematic Vector with zero elements; length reprents the number of elements in the vector. !!
  VectorNf(float[] values, int start, int length)
          Constructs a new Vector by copying length elements from the array parameter.
  VectorNf(int length)
          Constructs a new generalized mathematic Vector with zero elements; length reprents the number of elements in the vector.
  VectorNf(TupleNf<?> vector)
          Constructs a new Vector and copies the initial values from the parameter vector.
 
Method Summary
 float angle(VectorNf v2)
          Returns the angle in radians between this vector and the vector parameter; the return value is constrained to the range [0,PI].
 VectorNf asReadOnly()
          
 java.lang.Object clone()
          
 VectorNf cross(VectorNf v1, VectorNf v2)
          Sets this vector to be the vector cross product of vectors v1 and v2.
 float dot(VectorNf v2)
          Computes the dot product of the this vector and vector v2.
 float getNorm()
          Returns the square root of the sum of the squares of this vector (its length in n-dimensional space).
 float getNormSquared()
          Returns the sum of the squares of this vector (its length sqaured in n-dimensional space).
 VectorNf getReadOnly()
          
 float length()
          
 float lengthSquared()
          
 void LUDBackSolve(MatrixMxNf lu, VectorNf b, VectorNf permutation)
          LU Decomposition Back Solve; this method takes the LU matrix and the permutation vector produced by the GMatrix method LUD and solves the equation (LU)*x = b by placing the solution vector x into this vector.
 void mul(MatrixMxNf m, VectorNf v)
           Multiplies matrix m1 times Vector v1 and places the result into this vector (this = m1 * v1).
 void mul(VectorNf v1, MatrixMxNf m)
           Multiplies the transpose of vector v1 (ie, v1 becomes a row vector with respect to the multiplication) times matrix m1 and places the result into this vector (this = transpose(v1)*m1).
static VectorNf newReadOnly(float[] values)
          Constructs a new generalized mathematic Vector with zero elements; length reprents the number of elements in the vector. !!
static VectorNf newReadOnly(float[] values, int start, int length)
          Constructs a new Vector by copying length elements from the array parameter.
static VectorNf newReadOnly(int length)
          Constructs a new generalized mathematic Vector with zero elements; length reprents the number of elements in the vector.
static VectorNf newReadOnly(TupleNf<?> vector)
          Constructs a new Vector and copies the initial values from the parameter vector.
 VectorNf normalize()
          Normalizes this vector in place.
 VectorNf normalize(VectorNf v)
          Sets the value of this vector to the normalization of vector v1.
 void SVDBackSolve(MatrixMxNf U, MatrixMxNf W, MatrixMxNf V, VectorNf b)
          Solves for x in Ax = b, where x is this vector (nx1), A is mxn, b is mx1, and A = U*W*transpose(V); U,W,V must be precomputed and can be found by taking the singular value decomposition (SVD) of A using the method SVD found in the GMatrix class.
 
Methods inherited from class org.openmali.vecmath2.TupleNf
absolute, absolute, add, add, addValue, clamp, clamp, clampMax, clampMax, clampMin, clampMin, deserialize, div, divValue, epsilonEquals, equals, equals, fill, get, get, get, getSerializationBufferSize, getSize, getValue, hashCode, interpolate, interpolate, isDirty, isReadOnly, mul, mulValue, negate, negate, readExternal, readFromBuffer, readFromBuffer, readFromBuffer, readFromBuffer, round, round, scale, scale, scaleAdd, scaleAdd, serialize, set, set, set, setClean, setValue, setZero, sub, sub, subValue, toString, writeExternal, writeToBuffer, writeToBuffer, writeToBuffer, writeToBuffer
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.io.Externalizable
readExternal, writeExternal
 
Methods inherited from interface org.openmali.vecmath2.TupleInterface
absolute, absolute, add, add, addValue, clamp, clamp, clampMax, clampMax, clampMin, clampMin, div, divValue, epsilonEquals, fill, get, get, get, getSize, getValue, interpolate, interpolate, isDirty, isReadOnly, mul, mulValue, negate, negate, round, round, scale, scale, scaleAdd, scaleAdd, set, set, set, setClean, setValue, setZero, sub, sub, subValue
 

Constructor Detail

VectorNf

protected VectorNf(boolean readOnly,
                   int length)
Constructs a new generalized mathematic Vector with zero elements; length reprents the number of elements in the vector.

Parameters:
readOnly -
length - number of elements in this vector.

VectorNf

protected VectorNf(boolean readOnly,
                   float[] values,
                   boolean[] isDirty,
                   boolean copy)
Constructs a new generalized mathematic Vector with zero elements; length reprents the number of elements in the vector. !! this comment is a bug in Sun's API !!

Parameters:
readOnly -
values - the values for the new vector.
isDirty -
copy -

VectorNf

protected VectorNf(boolean readOnly,
                   float[] values,
                   int start,
                   int length)
Constructs a new Vector by copying length elements from the array parameter. The parameter length must be less than or equal to vector.length.

Parameters:
readOnly -
values - The array from which the values will be copied.
start - the start index to begin copying at
length - The number of values copied from the array.

VectorNf

protected VectorNf(boolean readOnly,
                   TupleNf<?> vector)
Constructs a new Vector and copies the initial values from the parameter vector.

Parameters:
readOnly -
vector - the source for the new Vector's initial values

VectorNf

public VectorNf(int length)
Constructs a new generalized mathematic Vector with zero elements; length reprents the number of elements in the vector.

Parameters:
length - number of elements in this vector.

VectorNf

public VectorNf(float[] values)
Constructs a new generalized mathematic Vector with zero elements; length reprents the number of elements in the vector. !! this comment is a bug in Sun's API !!

Parameters:
values - the values for the new vector.

VectorNf

public VectorNf(float[] values,
                int start,
                int length)
Constructs a new Vector by copying length elements from the array parameter. The parameter length must be less than or equal to vector.length.

Parameters:
values - The array from which the values will be copied.
start - the start index to begin copying at
length - The number of values copied from the array.

VectorNf

public VectorNf(TupleNf<?> vector)
Constructs a new Vector and copies the initial values from the parameter vector.

Parameters:
vector - the source for the new Vector's initial values
Method Detail

getNormSquared

public final float getNormSquared()
Returns the sum of the squares of this vector (its length sqaured in n-dimensional space).

Returns:
length squared of this vector

getNorm

public final float getNorm()
Returns the square root of the sum of the squares of this vector (its length in n-dimensional space).

Returns:
length of this vector

normalize

public final VectorNf normalize()
Normalizes this vector in place.

Specified by:
normalize in interface VectorInterface<VectorNf,VectorNf>
Returns:
itself

normalize

public final VectorNf normalize(VectorNf v)
Sets the value of this vector to the normalization of vector v1.

Specified by:
normalize in interface VectorInterface<VectorNf,VectorNf>
Parameters:
v - the un-normalized vector
Returns:
itself

lengthSquared

public float lengthSquared()

Specified by:
lengthSquared in interface VectorInterface<VectorNf,VectorNf>
Returns:
the squared length of this vector

length

public float length()

Specified by:
length in interface VectorInterface<VectorNf,VectorNf>
Returns:
the length of this vector

mul

public void mul(MatrixMxNf m,
                VectorNf v)

Multiplies matrix m1 times Vector v1 and places the result into this vector (this = m1 * v1).

ATTENTION! This method is not alias-safe!

Parameters:
m - The matrix in the multiplication
v - The vector that is multiplied

mul

public void mul(VectorNf v1,
                MatrixMxNf m)

Multiplies the transpose of vector v1 (ie, v1 becomes a row vector with respect to the multiplication) times matrix m1 and places the result into this vector (this = transpose(v1)*m1). The result is technically a row vector, but the GVector class only knows about column vectors, and so the result is stored as a column vector.

ATTENTION! This method is not alias-safe!

Parameters:
v1 - The vector that is temporarily transposed
m - The matrix in the multiplication

cross

public final VectorNf cross(VectorNf v1,
                            VectorNf v2)
Sets this vector to be the vector cross product of vectors v1 and v2.

Specified by:
cross in interface VectorInterface<VectorNf,VectorNf>
Parameters:
v1 - the first vector
v2 - the second vector
Returns:
itself

dot

public final float dot(VectorNf v2)
Computes the dot product of the this vector and vector v2.

Specified by:
dot in interface VectorInterface<VectorNf,VectorNf>
Parameters:
v2 - the other vector

angle

public final float angle(VectorNf v2)
Returns the angle in radians between this vector and the vector parameter; the return value is constrained to the range [0,PI].

Specified by:
angle in interface VectorInterface<VectorNf,VectorNf>
Parameters:
v2 - the other vector
Returns:
the angle in radians in the range [0,PI]

SVDBackSolve

public void SVDBackSolve(MatrixMxNf U,
                         MatrixMxNf W,
                         MatrixMxNf V,
                         VectorNf b)
Solves for x in Ax = b, where x is this vector (nx1), A is mxn, b is mx1, and A = U*W*transpose(V); U,W,V must be precomputed and can be found by taking the singular value decomposition (SVD) of A using the method SVD found in the GMatrix class.

Parameters:
U - The U matrix produced by the GMatrix method SVD
W - The W matrix produced by the GMatrix method SVD
V - The V matrix produced by the GMatrix method SVD
b - The b vector in the linear equation Ax = b

LUDBackSolve

public void LUDBackSolve(MatrixMxNf lu,
                         VectorNf b,
                         VectorNf permutation)
LU Decomposition Back Solve; this method takes the LU matrix and the permutation vector produced by the GMatrix method LUD and solves the equation (LU)*x = b by placing the solution vector x into this vector. This vector should be the same length or longer than b.

Parameters:
lu - The matrix into which the lower and upper decompositions have been placed
b - The b vector in the equation (LU)*x = b
permutation - The row permuations that were necessary to produce the LU matrix parameter

asReadOnly

public VectorNf asReadOnly()

Specified by:
asReadOnly in class TupleNf<VectorNf>
Returns:
a new instance sharing the values array with this instance. The new instance is read-only. Changes to this instance will be reflected in the new read-only-instance.
See Also:
TupleNf.getReadOnly()

getReadOnly

public VectorNf getReadOnly()

Specified by:
getReadOnly in class TupleNf<VectorNf>
Returns:
a single instance sharing the values array with this instance (one unique instance per 'master-instance'). The instance is read-only. Changes to this instance will be reflected in the read-only-instance.
See Also:
TupleNf.asReadOnly()

clone

public java.lang.Object clone()

Overrides:
clone in class java.lang.Object

newReadOnly

public static VectorNf newReadOnly(int length)
Constructs a new generalized mathematic Vector with zero elements; length reprents the number of elements in the vector.

Parameters:
length - number of elements in this vector.

newReadOnly

public static VectorNf newReadOnly(float[] values)
Constructs a new generalized mathematic Vector with zero elements; length reprents the number of elements in the vector. !! this comment is a bug in Sun's API !!

Parameters:
values - the values for the new vector.

newReadOnly

public static VectorNf newReadOnly(float[] values,
                                   int start,
                                   int length)
Constructs a new Vector by copying length elements from the array parameter. The parameter length must be less than or equal to vector.length.

Parameters:
values - The array from which the values will be copied.
start - the start index to begin copying at
length - The number of values copied from the array.

newReadOnly

public static VectorNf newReadOnly(TupleNf<?> vector)
Constructs a new Vector and copies the initial values from the parameter vector.

Parameters:
vector - the source for the new Vector's initial values