org.openmali.vecmath2.util
Class VecMathUtils

java.lang.Object
  extended by org.openmali.vecmath2.util.VecMathUtils

public final class VecMathUtils
extends java.lang.Object

Utilities for vecmath classes.


Method Summary
 float angle(TupleNf<?> v1, TupleNf<?> v2)
          Returns the (n-space) angle in radians between this vector and the vector parameter; the return value is constrained to the range [0,PI].
static void cross(TupleNf<?> v1, TupleNf<?> v2, TupleNf<?> out)
          Sets this vector to be the vector cross product of vectors v1 and v2.
static float distance(TupleNf<?> p1, TupleNf<?> p2)
           
static float distanceSquared(TupleNf<?> p1, TupleNf<?> p2)
           
static float dot(TupleNf<?> v1, TupleNf<?> v2)
          Returns the dot product of vector v1 and vector v2.
static long doubleToLongBits(double d)
          Returns the representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout, after first mapping -0.0 to 0.0.
static boolean epsilonEquals(TupleNf<?> t1, TupleNf<?> t2, float 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.
static boolean equals(TupleNf<?> t1, TupleNf<?> t2)
          Returns true if all of the data members of GVector vector1 are equal to the corresponding data members in this GVector.
static int floatToIntBits(float f)
          Returns the representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout, after first mapping -0.0 to 0.0.
static float getNorm(TupleNf<?> vec)
          Returns the square root of the sum of the squares of this vector (its length in n-dimensional space).
static float getNormSquared(TupleNf<?> vec)
          Returns the sum of the squares of this vector (its length sqaured in n-dimensional space).
static VectorInterface<?,?> getVectorFromPool(int size)
           
static float length(TupleNf<?> vec)
          Computes the length of the (x,y,z)-component of this vector.
static float lengthSquared(TupleNf<?> vec)
          Computes the squared length of this vector.
static void normalize(TupleNf<?> v)
          Normalizes the given vector.
static void putVectorToPool(VectorInterface vector)
          Puts a vector back to its pool.
static
<M extends Matrix3f>
M
readMatrix3f(java.io.DataInput in, M m)
          Reads a Tuple3f from the InputStream.
static
<T extends Tuple3f>
T
readTuple3f(java.io.DataInput in, T t)
          Reads a Tuple3f from the InputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getVectorFromPool

public static final VectorInterface<?,?> getVectorFromPool(int size)
Parameters:
size -
Returns:
an instance from the appropriate pool, if size is 2, 3 or 4. Otherwise this returns a new instance.

putVectorToPool

public static final void putVectorToPool(VectorInterface vector)
Puts a vector back to its pool.
If the vector's size is not 2, 3, or 4, the vector is discarded.

Parameters:
vector -

distanceSquared

public static final float distanceSquared(TupleNf<?> p1,
                                          TupleNf<?> p2)
Returns:
the squared distance betweeen this point and the other one

distance

public static final float distance(TupleNf<?> p1,
                                   TupleNf<?> p2)
Returns:
the distance betweeen this point and the other one

getNormSquared

public static final float getNormSquared(TupleNf<?> vec)
Returns the sum of the squares of this vector (its length sqaured in n-dimensional space).

Parameters:
vec -
Returns:
length squared of this vector

getNorm

public static final float getNorm(TupleNf<?> vec)
Returns the square root of the sum of the squares of this vector (its length in n-dimensional space).

Parameters:
vec -
Returns:
length of this vector

normalize

public static final void normalize(TupleNf<?> v)
Normalizes the given vector.

Parameters:
v -

lengthSquared

public static final float lengthSquared(TupleNf<?> vec)
Computes the squared length of this vector.

Parameters:
vec -
Returns:
the squared length of this vector

length

public static final float length(TupleNf<?> vec)
Computes the length of the (x,y,z)-component of this vector. If you want to have also the w-component in the computation, please use #getNorm()

Parameters:
vec -
Returns:
the length of this vector, only cares about (x,y,z).

cross

public static final void cross(TupleNf<?> v1,
                               TupleNf<?> v2,
                               TupleNf<?> out)
Sets this vector to be the vector cross product of vectors v1 and v2.

Parameters:
v1 - the first vector
v2 - the second vector

dot

public static final float dot(TupleNf<?> v1,
                              TupleNf<?> v2)
Returns the dot product of vector v1 and vector v2.

Parameters:
v1 - the first vector
v2 - the second vector
Returns:
the dot product of v1 and v2

angle

public float angle(TupleNf<?> v1,
                   TupleNf<?> v2)
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 - The first vector
v2 - The second vector
Returns:
The angle in radians in the range [0,PI]

equals

public static boolean equals(TupleNf<?> t1,
                             TupleNf<?> t2)
Returns true if all of the data members of GVector vector1 are equal to the corresponding data members in this GVector.

Parameters:
t1 - the tuple with which the comparison is made.
t2 - the vector with which the comparison is made.
Returns:
true or false

epsilonEquals

public static final boolean epsilonEquals(TupleNf<?> t1,
                                          TupleNf<?> t2,
                                          float 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:
t1 - the tuple with which the comparison is made.
t2 - the vector with which the comparison is made.
epsilon - the threshold value

floatToIntBits

public static final int floatToIntBits(float f)
Returns the representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout, after first mapping -0.0 to 0.0. This method is identical to Float.floatToIntBits(float) except that an integer value of 0 is returned for a floating-point value of -0.0f. This is done for the purpose of computing a hash code that satisfies the contract of hashCode() and equals(). The equals() method in each vecmath class does a pair-wise "==" test on each floating-point field in the class (e.g., x, y, and z for a Tuple3f). Since 0.0f == -0.0f returns true, we must also return the same hash code for two objects, one of which has a field with a value of -0.0f and the other of which has a cooresponding field with a value of 0.0f.

Parameters:
f - an input floating-point number
Returns:
the integer bits representing that floating-point number, after first mapping -0.0f to 0.0f

doubleToLongBits

public static final long doubleToLongBits(double d)
Returns the representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout, after first mapping -0.0 to 0.0. This method is identical to Double.doubleToLongBits(double) except that an integer value of 0 is returned for a floating-point value of -0.0d. This is done for the purpose of computing a hash code that satisfies the contract of hashCode() and equals(). The equals() method in each vecmath class does a pair-wise "==" test on each floating-point field in the class (e.g., x, y, and z for a Tuple3d). Since 0.0d == -0.0d returns true, we must also return the same hash code for two objects, one of which has a field with a value of -0.0d and the other of which has a corresponding field with a value of 0.0d.

Parameters:
f - an input floating-point number
Returns:
the integer bits representing that floating-point number, after first mapping -0.0f to 0.0f

readTuple3f

public static final <T extends Tuple3f> T readTuple3f(java.io.DataInput in,
                                                      T t)
                                           throws java.io.IOException
Reads a Tuple3f from the InputStream.

Type Parameters:
T -
Parameters:
in -
t -
Returns:
the tuple t back again
Throws:
java.io.IOException

readMatrix3f

public static final <M extends Matrix3f> M readMatrix3f(java.io.DataInput in,
                                                        M m)
                                             throws java.io.IOException
Reads a Tuple3f from the InputStream.

Type Parameters:
T -
Parameters:
in -
t -
Returns:
the tuple t back again
Throws:
java.io.IOException