Top Description Fields Constructors Methods
javax.vecmath

public Class GVector

extends Object
implements Serializable, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.io.Serializable
Imports
java.lang.Math

A double precision, general, dynamically-resizable, one-dimensional vector class. Index numbering begins with zero.

Field Summary

Modifier and TypeField and Description
private int
pack-priv static final long
pack-priv double[]

Constructor Summary

AccessConstructor and Description
public
GVector(int
the number of elements in this GVector.
length
)

Constructs a new GVector of the specified length with all vector elements initialized to 0.

public
GVector(double[]
the values for the new GVector.
vector
)

Constructs a new GVector from the specified array elements.

public
GVector(GVector
the source GVector for this new GVector.
vector
)

Constructs a new GVector from the specified vector.

public
GVector(Tuple2f
the source for the new GVector's initial values
tuple
)

Constructs a new GVector and copies the initial values from the specified tuple.

public
GVector(Tuple3f
the source for the new GVector's initial values
tuple
)

Constructs a new GVector and copies the initial values from the specified tuple.

public
GVector(Tuple3d
the source for the new GVector's initial values
tuple
)

Constructs a new GVector and copies the initial values from the specified tuple.

public
GVector(Tuple4f
the source for the new GVector's initial values
tuple
)

Constructs a new GVector and copies the initial values from the specified tuple.

public
GVector(Tuple4d
the source for the new GVector's initial values
tuple
)

Constructs a new GVector and copies the initial values from the specified tuple.

public
GVector(double[]
The array from which the values will be copied.
vector
,
int
The number of values copied from the array.
length
)

Constructs a new GVector of the specified length and initializes it by copying the specified number of elements from the specified array.

Method Summary

Modifier and TypeMethod and Description
public final void
add(GVector
the second vector
vector
)

Sets the value of this vector to sum of itself and the specified vector

public final void
add(GVector
the first vector
vector1
,
GVector
the second vector
vector2
)

Sets the value of this vector to the vector sum of vectors vector1 and vector2.

public final double

Returns:

The angle in radians in the range [0,PI]
angle
(GVector
The other vector
v1
)

Returns the (n-space) angle in radians between this vector and the vector parameter; the return value is constrained to the range [0,PI].

public Object

Returns:

a clone of this instance.
clone
()

Overrides java.lang.Object.clone.

Creates a new object of the same class as this object.
public final double

Returns:

the dot product of this and v1
dot
(GVector
the other vector
v1
)

Returns the dot product of this vector and vector v1.

public boolean
epsilonEquals(GVector
The vector to be compared to this vector
v1
,
double
the threshold value
epsilon
)

Returns true if the L-infinite distance between this vector and vector v1 is less than or equal to the epsilon parameter, otherwise returns false.

public boolean

Returns:

true or false
equals
(GVector
The vector with which the comparison is made.
vector1
)

Returns true if all of the data members of GVector vector1 are equal to the corresponding data members in this GVector.

public boolean

Returns:

true or false
equals
(Object
The object with which the comparison is made.
o1
)

Overrides java.lang.Object.equals.

Returns true if the Object o1 is of type GMatrix and all of the data members of o1 are equal to the corresponding data members in this GMatrix.
public final double

Returns:

the value at the indexed element
getElement
(int
the index of the element to retrieve (zero indexed)
index
)

Retrieves the value at the specified index value of this vector.

public final int

Returns:

number of elements in this vector
getSize
()

Returns the number of elements in this vector.

public int

Returns:

the integer hash code value
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code value based on the data values in this object.
public final void
interpolate(GVector v1, GVector v2, float alpha)

Deprecated Use interpolate(GVector, GVector, double) instead
public final void
interpolate(GVector v1, float alpha)

Deprecated Use interpolate(GVector, double) instead
public final void
interpolate(GVector
the first vector
v1
,
GVector
the second vector
v2
,
double
the alpha interpolation parameter
alpha
)

Linearly interpolates between vectors v1 and v2 and places the result into this tuple: this = (1-alpha)*v1 + alpha*v2.

public final void
interpolate(GVector
the first vector
v1
,
double
the alpha interpolation parameter
alpha
)

Linearly interpolates between this vector and vector v1 and places the result into this tuple: this = (1-alpha)*this + alpha*v1.

public final void
LUDBackSolve(GMatrix
The matrix into which the lower and upper decompostions have been placed
LU
,
GVector
The b vector in the equation (LU)*x = b
b
,
GVector
The row permuations that were necessary to produce the LU matrix parameter
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.

public final void
mul(GMatrix
The matrix in the multiplication
m1
,
GVector
The vector that is multiplied
v1
)

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

public final void
mul(GVector
The vector that is temporarily transposed
v1
,
GMatrix
The matrix in the multiplication
m1
)

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).

public final void
negate()

Negates the value of this vector: this = -this.

public final double

Returns:

length of this vector
norm
()

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

public final void
normalize(GVector
the un-normalized vector
v1
)

Sets the value of this vector to the normalization of vector v1.

public final void
normalize()

Normalizes this vector in place.

public final double

Returns:

length squared of this vector
normSquared
()

Returns the sum of the squares of this vector (its length squared in n-dimensional space).

public final void
scale(double
the scalar value
s
,
GVector
the source vector
v1
)

Sets the value of this vector to the scalar multiplication of the scale factor with the vector v1.

public final void
scale(double
the scalar value
s
)

Scales this vector by the scale factor s.

public final void
scaleAdd(double
the scalar value
s
,
GVector
the vector to be multiplied
v1
,
GVector
the vector to be added
v2
)

Sets the value of this vector to the scalar multiplication by s of vector v1 plus vector v2 (this = s*v1 + v2).

public final void
set(double[]
the source array
vector
)

Sets the value of this vector to the values found in the array parameter.

public final void
set(GVector
the source vector
vector
)

Sets the value of this vector to the values found in vector vector.

public final void
set(Tuple2f
the source for the new GVector's new values
tuple
)

Sets the value of this vector to the values in tuple

public final void
set(Tuple3f
the source for the new GVector's new values
tuple
)

Sets the value of this vector to the values in tuple

public final void
set(Tuple3d
the source for the new GVector's new values
tuple
)

Sets the value of this vector to the values in tuple

public final void
set(Tuple4f
the source for the new GVector's new values
tuple
)

Sets the value of this vector to the values in tuple

public final void
set(Tuple4d
the source for the new GVector's new values
tuple
)

Sets the value of this vector to the values in tuple

public final void
setElement(int
the index if the element to modify (zero indexed)
index
,
double
the new vector element value
value
)

Modifies the value at the specified index of this vector.

public final void
setSize(int
number of desired elements in this vector
length
)

Changes the size of this vector dynamically.

public final void
sub(GVector
the other vector
vector
)

Sets the value of this vector to the vector difference of itself and vector (this = this - vector).

public final void
sub(GVector
the first vector
vector1
,
GVector
the second vector
vector2
)

Sets the value of this vector to the vector difference of vectors vector1 and vector2 (this = vector1 - vector2).

public final void
SVDBackSolve(GMatrix
The U matrix produced by the GMatrix method SVD
U
,
GMatrix
The W matrix produced by the GMatrix method SVD
W
,
GMatrix
The V matrix produced by the GMatrix method SVD
V
,
GVector
The b vector in the linear equation Ax = b
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.

public String

Returns:

the String representation
toString
()

Overrides java.lang.Object.toString.

Returns a string that contains the values of this GVector.
public final void
zero()

Sets all the values in this vector to zero.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

lengthback to summary
private int length
serialVersionUIDback to summary
pack-priv static final long serialVersionUID
valuesback to summary
pack-priv double[] values

Constructor Detail

GVectorback to summary
public GVector(int length)

Constructs a new GVector of the specified length with all vector elements initialized to 0.

Parameters
length:int

the number of elements in this GVector.

GVectorback to summary
public GVector(double[] vector)

Constructs a new GVector from the specified array elements. The length of this GVector is set to the length of the specified array. The array elements are copied into this new GVector.

Parameters
vector:double[]

the values for the new GVector.

GVectorback to summary
public GVector(GVector vector)

Constructs a new GVector from the specified vector. The vector elements are copied into this new GVector.

Parameters
vector:GVector

the source GVector for this new GVector.

GVectorback to summary
public GVector(Tuple2f tuple)

Constructs a new GVector and copies the initial values from the specified tuple.

Parameters
tuple:Tuple2f

the source for the new GVector's initial values

GVectorback to summary
public GVector(Tuple3f tuple)

Constructs a new GVector and copies the initial values from the specified tuple.

Parameters
tuple:Tuple3f

the source for the new GVector's initial values

GVectorback to summary
public GVector(Tuple3d tuple)

Constructs a new GVector and copies the initial values from the specified tuple.

Parameters
tuple:Tuple3d

the source for the new GVector's initial values

GVectorback to summary
public GVector(Tuple4f tuple)

Constructs a new GVector and copies the initial values from the specified tuple.

Parameters
tuple:Tuple4f

the source for the new GVector's initial values

GVectorback to summary
public GVector(Tuple4d tuple)

Constructs a new GVector and copies the initial values from the specified tuple.

Parameters
tuple:Tuple4d

the source for the new GVector's initial values

GVectorback to summary
public GVector(double[] vector, int length)

Constructs a new GVector of the specified length and initializes it by copying the specified number of elements from the specified array. The array must contain at least length elements (i.e., vector.length >= length. The length of this new GVector is set to the specified length.

Parameters
vector:double[]

The array from which the values will be copied.

length:int

The number of values copied from the array.

Method Detail

addback to summary
public final void add(GVector vector)

Sets the value of this vector to sum of itself and the specified vector

Parameters
vector:GVector

the second vector

addback to summary
public final void add(GVector vector1, GVector vector2)

Sets the value of this vector to the vector sum of vectors vector1 and vector2.

Parameters
vector1:GVector

the first vector

vector2:GVector

the second vector

angleback to summary
public final double angle(GVector v1)

Returns the (n-space) angle in radians between this vector and the vector parameter; the return value is constrained to the range [0,PI].

Parameters
v1:GVector

The other vector

Returns:double

The angle in radians in the range [0,PI]

cloneback to summary
public Object clone()

Overrides java.lang.Object.clone.

Creates a new object of the same class as this object.

Returns:Object

a clone of this instance.

Exceptions
OutOfMemoryError:
if there is not enough memory.
Since
vecmath 1.3
See Also
java.lang.Cloneable
dotback to summary
public final double dot(GVector v1)

Returns the dot product of this vector and vector v1.

Parameters
v1:GVector

the other vector

Returns:double

the dot product of this and v1

epsilonEqualsback to summary
public boolean epsilonEquals(GVector v1, double epsilon)

Returns true if the L-infinite distance between this vector and vector v1 is less than or equal to the epsilon parameter, otherwise returns false. The L-infinite distance is equal to MAX[abs(x1-x2), abs(y1-y2), . . . ].

Parameters
v1:GVector

The vector to be compared to this vector

epsilon:double

the threshold value

equalsback to summary
public boolean equals(GVector vector1)

Returns true if all of the data members of GVector vector1 are equal to the corresponding data members in this GVector.

Parameters
vector1:GVector

The vector with which the comparison is made.

Returns:boolean

true or false

equalsback to summary
public boolean equals(Object o1)

Overrides java.lang.Object.equals.

Returns true if the Object o1 is of type GMatrix and all of the data members of o1 are equal to the corresponding data members in this GMatrix.

Parameters
o1:Object

The object with which the comparison is made.

Returns:boolean

true or false

getElementback to summary
public final double getElement(int index)

Retrieves the value at the specified index value of this vector.

Parameters
index:int

the index of the element to retrieve (zero indexed)

Returns:double

the value at the indexed element

getSizeback to summary
public final int getSize()

Returns the number of elements in this vector.

Returns:int

number of elements in this vector

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value based on the data values in this object. Two different GVector objects with identical data values (i.e., GVector.equals returns true) will return the same hash number. Two GVector objects with different data members may return the same hash value, although this is not likely.

Returns:int

the integer hash code value

interpolateback to summary
public final void interpolate(GVector v1, GVector v2, float alpha)

Deprecated

Use interpolate(GVector, GVector, double) instead

interpolateback to summary
public final void interpolate(GVector v1, float alpha)

Deprecated

Use interpolate(GVector, double) instead

interpolateback to summary
public final void interpolate(GVector v1, GVector v2, double alpha)

Linearly interpolates between vectors v1 and v2 and places the result into this tuple: this = (1-alpha)*v1 + alpha*v2.

Parameters
v1:GVector

the first vector

v2:GVector

the second vector

alpha:double

the alpha interpolation parameter

interpolateback to summary
public final void interpolate(GVector v1, double alpha)

Linearly interpolates between this vector and vector v1 and places the result into this tuple: this = (1-alpha)*this + alpha*v1.

Parameters
v1:GVector

the first vector

alpha:double

the alpha interpolation parameter

LUDBackSolveback to summary
public final void LUDBackSolve(GMatrix LU, GVector b, GVector 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:GMatrix

The matrix into which the lower and upper decompostions have been placed

b:GVector

The b vector in the equation (LU)*x = b

permutation:GVector

The row permuations that were necessary to produce the LU matrix parameter

mulback to summary
public final void mul(GMatrix m1, GVector v1)

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

Parameters
m1:GMatrix

The matrix in the multiplication

v1:GVector

The vector that is multiplied

mulback to summary
public final void mul(GVector v1, GMatrix m1)

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.

Parameters
v1:GVector

The vector that is temporarily transposed

m1:GMatrix

The matrix in the multiplication

negateback to summary
public final void negate()

Negates the value of this vector: this = -this.

normback to summary
public final double norm()

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

Returns:double

length of this vector

normalizeback to summary
public final void normalize(GVector v1)

Sets the value of this vector to the normalization of vector v1.

Parameters
v1:GVector

the un-normalized vector

normalizeback to summary
public final void normalize()

Normalizes this vector in place.

normSquaredback to summary
public final double normSquared()

Returns the sum of the squares of this vector (its length squared in n-dimensional space).

Returns:double

length squared of this vector

scaleback to summary
public final void scale(double s, GVector v1)

Sets the value of this vector to the scalar multiplication of the scale factor with the vector v1.

Parameters
s:double

the scalar value

v1:GVector

the source vector

scaleback to summary
public final void scale(double s)

Scales this vector by the scale factor s.

Parameters
s:double

the scalar value

scaleAddback to summary
public final void scaleAdd(double s, GVector v1, GVector v2)

Sets the value of this vector to the scalar multiplication by s of vector v1 plus vector v2 (this = s*v1 + v2).

Parameters
s:double

the scalar value

v1:GVector

the vector to be multiplied

v2:GVector

the vector to be added

setback to summary
public final void set(double[] vector)

Sets the value of this vector to the values found in the array parameter. The array should be at least equal in length to the number of elements in the vector.

Parameters
vector:double[]

the source array

setback to summary
public final void set(GVector vector)

Sets the value of this vector to the values found in vector vector.

Parameters
vector:GVector

the source vector

setback to summary
public final void set(Tuple2f tuple)

Sets the value of this vector to the values in tuple

Parameters
tuple:Tuple2f

the source for the new GVector's new values

setback to summary
public final void set(Tuple3f tuple)

Sets the value of this vector to the values in tuple

Parameters
tuple:Tuple3f

the source for the new GVector's new values

setback to summary
public final void set(Tuple3d tuple)

Sets the value of this vector to the values in tuple

Parameters
tuple:Tuple3d

the source for the new GVector's new values

setback to summary
public final void set(Tuple4f tuple)

Sets the value of this vector to the values in tuple

Parameters
tuple:Tuple4f

the source for the new GVector's new values

setback to summary
public final void set(Tuple4d tuple)

Sets the value of this vector to the values in tuple

Parameters
tuple:Tuple4d

the source for the new GVector's new values

setElementback to summary
public final void setElement(int index, double value)

Modifies the value at the specified index of this vector.

Parameters
index:int

the index if the element to modify (zero indexed)

value:double

the new vector element value

setSizeback to summary
public final void setSize(int length)

Changes the size of this vector dynamically. If the size is increased no data values will be lost. If the size is decreased, only those data values whose vector positions were eliminated will be lost.

Parameters
length:int

number of desired elements in this vector

subback to summary
public final void sub(GVector vector)

Sets the value of this vector to the vector difference of itself and vector (this = this - vector).

Parameters
vector:GVector

the other vector

subback to summary
public final void sub(GVector vector1, GVector vector2)

Sets the value of this vector to the vector difference of vectors vector1 and vector2 (this = vector1 - vector2).

Parameters
vector1:GVector

the first vector

vector2:GVector

the second vector

SVDBackSolveback to summary
public final void SVDBackSolve(GMatrix U, GMatrix W, GMatrix V, GVector 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:GMatrix

The U matrix produced by the GMatrix method SVD

W:GMatrix

The W matrix produced by the GMatrix method SVD

V:GMatrix

The V matrix produced by the GMatrix method SVD

b:GVector

The b vector in the linear equation Ax = b

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string that contains the values of this GVector.

Returns:String

the String representation

zeroback to summary
public final void zero()

Sets all the values in this vector to zero.