hmi.math
Class Vec3f

java.lang.Object
  extended by hmi.math.Vec3f

public final class Vec3f
extends Object

A collection of methods for vectors of length 3, represented by float arrays. Vectors can be stored within arrays of length three, or they can be stored inside a larger float array a, together with an integer offset "index" into that array. This represents a vector with components (a[index], a[index+1], a[index+2]). The methods from this class never allocate new arrays; rather, they assume that results are to be stored into some existing "destination" array.

Author:
Job Zwiers, Herwin van Welbergen

Field Summary
private static int BUFSIZE
           
static int VEC3F_SIZE
          Length of Vec3f arrays is 3
static int X
          Offset values for Vec4 vectors.
static int Y
           
static int Z
           
 
Constructor Summary
private Vec3f()
           
 
Method Summary
static void add(float[] dst, float[] a)
          Adds vector b to vector a.
static void add(float[] dst, float[] a, float[] b)
          Adds vector a and b, puts result in dest.
static void add(float[] dst, float ax, float ay, float az)
          Adds 3 floats to dst
static void add(float[] dst, int dstIndex, float[] a, int aIndex)
          Adds vector b to vector a.
static void add(float[] dst, int dstIndex, float[] a, int aIndex, float[] b, int bIndex)
          Sets vector dst to sum of a and b.
static void cross(float[] dst, float[] a, float[] b)
          Calculates the cross product of two (3D) vectors defined by array "a", with index "aIndex", and array "b", with offset "bIndex", and stores the reult vector in array "c", with offset "cIndex".
static void cross(float[] dst, int dstIndex, float[] a, int aIndex, float[] b, int bIndex)
          Calculates the cross product of two (3D) vectors defined by array "a", with index "aIndex", and array "b", with offset "bIndex", and stores the reult vector in array "c", with offset "cIndex".
static float dot(float[] a, float[] b)
          Calculates the dot product for two vectors of length 3
static float dot(float[] a, int aIndex, float[] b, int bIndex)
          Calculates the dot product for two vectors of length 3
static boolean epsilonEquals(float[] a, float[] b, float epsilon)
          Tests for equality of vectror components within epsilon.
static boolean epsilonEquals(float[] b, float ax, float ay, float az, float epsilon)
          Tests for equality of vectror components within epsilon.
static boolean epsilonEquals(float[] a, int aIndex, float[] b, int bIndex, float epsilon)
          Tests for equality of vector components within epsilon.
static boolean equals(float[] a, float[] b)
          Tests for equality of two vectors
static boolean equals(float[] a, float bx, float by, float bz)
          Tests for equality of one vectors and 3 floats
static boolean equals(float[] a, int aIndex, float[] b, int bIndex)
          Tests for equality of two vectors
static float[] getUnitX()
          Returns a new unit vector in the x-direction
static float[] getUnitY()
          Returns a new unit vector in the y-direction
static float[] getUnitZ()
          Returns a new unit vector in the x-direction
static float[] getVec3f()
          Returns a new float[3] array with zero components
static float[] getVec3f(float[] vec3f)
          Rturns a new float[3] array with initialized components
static float[] getVec3f(float x, float y, float z)
          Returns a new float[3] array with initialized components
static float[] getZero()
          Returns a new float[3] array with zero components
static void interpolate(float[] dst, float[] a, float[] b, float alpha)
          Linear interpolates between vector a and b, and puts the result in vector dst: dst = (1-alpha)*a + alpha*b
static void interpolate(float[] dst, int dstIndex, float[] a, int aIndex, float[] b, int bIndex, float alpha)
          Linear interpolates between vector a and b, and puts the result in vector dst: dst = (1-alpha)*a + alpha*b
static void interpolateArrays(float[] dst, float[] a, float[] b, float alpha)
          Linear interpolates between a sequence of vectors a and b, and puts the result in vector dst: dst = (1-alpha)*a + alpha*b.
static void invert(float[] dst)
          Replaces dst[i] by 1.0f/dst[i]
static float length(float[] a)
          returns the vector length
static float length(float[] a, int aIndex)
          returns the vector length
static float lengthSq(float[] a)
          returns the square of the vector length
static float lengthSq(float[] a, int aIndex)
          returns the square of the vector length
static void negate(float[] dst)
          Negates a vector
static void negate(float[] dst, float[] src)
          Sets vector dst to the negated version of vector src
static void negate(float[] dst, int dstIndex)
          Negates a vector
static void negate(float[] dst, int dstIndex, float[] src, int srcIndex)
          Sets vector dst to the negated version of vector src
static void normalize(float[] a)
          Normalizes a, that is, a = a/|a|
static void normalize(float[] dst, float[] a)
          Normalizes a, that is, dst = a/|a|
static void normalize(float[] a, int aIndex)
          Normalizes a, that is, a = a/|a|
static void normalize(float[] dst, int dstIndex, float[] a, int aIndex)
          Normalizes a, that is, a = a/|a|
static void pmul(float[] u, float[] v)
          Performs pointwise multiplication of two vectors: u[i] = u[i]*v[i];
static void scale(float scale, float[] dst)
          Scales a vector
static void scale(float scale, float[] dst, float[] src)
          Scales a vector dst = scale * src
static void scale(float scale, float[] dst, int dstIndex)
          Scales a vector
static void scale(float scale, float[] dst, int dstIndex, float[] src, int srcIndex)
          Scales a vector dst = scale * src
static void scaleAdd(float[] dst, float scale, float[] a)
          First scales vector a, then and a to dst dst = dst + s*a
static void scaleAdd(float[] dst, float scale, float[] a, float[] b)
          Sets vector dst to scaled version of vector a, then adds vector b dst = s*a + b
static void scaleAdd(float[] dst, int dstIndex, float scale, float[] a, int aIndex)
          First scales vector a, then and a to dst dst = dst + s*a
static void scaleAdd(float[] dst, int dstIndex, float scale, float[] a, int aIndex, float[] b, int bIndex)
          Sets vector a to scaled version of vector b, then adds vector c dst = s*a + b
static void scaleAdd(float scale, float[] dst, float[] a)
          First scales vector dst, then and adds vector a.
static void scaleAdd(float scale, float[] dst, int dstIndex, float[] a, int aIndex)
          First scales vector dst, then and adds vector a.
static void set(float[] dst, float[] src)
          Copies vector src to vector dst.
static void set(float[] dst, float x, float y, float z)
          Sets vector components tp specified float values.
static void set(float[] dst, int dstIndex, float[] src, int srcIndex)
          Copies vector src to vector dst.
static void set(float[] dst, int dstIndex, float x, float y, float z)
          Sets vector components to specified float values.
static void setZero(float[] dst)
          Resets the Vec3f to (0, 0, 0)
static void setZero(float[] dst, int dstIndex)
          Resets the Vec3f to (0, 0, 0)
static void sub(float[] dst, float[] a)
          Subtracts vector a from vector dst.
static void sub(float[] dst, float[] a, float[] b)
          Subtracts vector b from vector a.
static void sub(float[] dst, float ax, float ay, float az)
          Substracts 3 floats from dst
static void sub(float[] dst, int dstIndex, float[] a, int aIndex)
          Subtracts vector a from vector dst.
static void sub(float[] dst, int dstIndex, float[] a, int aIndex, float[] b, int bIndex)
          Sets vector dst to a minus b
static String toString(float[] a)
          Returns a String of the form (x, y, z), representing the Vec3f value.
static String toString(float[] a, int index)
          Returns a String of the form (x, y, z), representing the Vec3f value.
static String toString(float[] a, int fieldwidth, int precision)
          Returns a String of the form (x, y, z), representing the Vec3f value.
static String toString(float[] a, String fmt)
          Returns a String of the form (x, y, z), representing the Vec3f value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VEC3F_SIZE

public static final int VEC3F_SIZE
Length of Vec3f arrays is 3

See Also:
Constant Field Values

X

public static final int X
Offset values for Vec4 vectors.

See Also:
Constant Field Values

Y

public static final int Y
See Also:
Constant Field Values

Z

public static final int Z
See Also:
Constant Field Values

BUFSIZE

private static final int BUFSIZE
See Also:
Constant Field Values
Constructor Detail

Vec3f

private Vec3f()
Method Detail

getVec3f

public static float[] getVec3f()
Returns a new float[3] array with zero components


getVec3f

public static float[] getVec3f(float x,
                               float y,
                               float z)
Returns a new float[3] array with initialized components


getVec3f

public static float[] getVec3f(float[] vec3f)
Rturns a new float[3] array with initialized components


getZero

public static float[] getZero()
Returns a new float[3] array with zero components


getUnitX

public static float[] getUnitX()
Returns a new unit vector in the x-direction


getUnitY

public static float[] getUnitY()
Returns a new unit vector in the y-direction


getUnitZ

public static float[] getUnitZ()
Returns a new unit vector in the x-direction


equals

public static boolean equals(float[] a,
                             int aIndex,
                             float[] b,
                             int bIndex)
Tests for equality of two vectors


equals

public static boolean equals(float[] a,
                             float bx,
                             float by,
                             float bz)
Tests for equality of one vectors and 3 floats


equals

public static boolean equals(float[] a,
                             float[] b)
Tests for equality of two vectors


epsilonEquals

public static boolean epsilonEquals(float[] a,
                                    int aIndex,
                                    float[] b,
                                    int bIndex,
                                    float epsilon)
Tests for equality of vector components within epsilon.


epsilonEquals

public static boolean epsilonEquals(float[] a,
                                    float[] b,
                                    float epsilon)
Tests for equality of vectror components within epsilon.


epsilonEquals

public static boolean epsilonEquals(float[] b,
                                    float ax,
                                    float ay,
                                    float az,
                                    float epsilon)
Tests for equality of vectror components within epsilon.


toString

public static String toString(float[] a,
                              int index)
Returns a String of the form (x, y, z), representing the Vec3f value.


toString

public static String toString(float[] a)
Returns a String of the form (x, y, z), representing the Vec3f value.


toString

public static String toString(float[] a,
                              int fieldwidth,
                              int precision)
Returns a String of the form (x, y, z), representing the Vec3f value.


toString

public static String toString(float[] a,
                              String fmt)
Returns a String of the form (x, y, z), representing the Vec3f value.


setZero

public static void setZero(float[] dst)
Resets the Vec3f to (0, 0, 0)


setZero

public static void setZero(float[] dst,
                           int dstIndex)
Resets the Vec3f to (0, 0, 0)


set

public static void set(float[] dst,
                       int dstIndex,
                       float[] src,
                       int srcIndex)
Copies vector src to vector dst. The src and dst array elements should not be aliased.


set

public static void set(float[] dst,
                       float[] src)
Copies vector src to vector dst.


set

public static void set(float[] dst,
                       int dstIndex,
                       float x,
                       float y,
                       float z)
Sets vector components to specified float values.


set

public static void set(float[] dst,
                       float x,
                       float y,
                       float z)
Sets vector components tp specified float values.


add

public static void add(float[] dst,
                       int dstIndex,
                       float[] a,
                       int aIndex,
                       float[] b,
                       int bIndex)
Sets vector dst to sum of a and b.


add

public static void add(float[] dst,
                       int dstIndex,
                       float[] a,
                       int aIndex)
Adds vector b to vector a.


add

public static void add(float[] dst,
                       float[] a,
                       float[] b)
Adds vector a and b, puts result in dest.


add

public static void add(float[] dst,
                       float[] a)
Adds vector b to vector a.


add

public static void add(float[] dst,
                       float ax,
                       float ay,
                       float az)
Adds 3 floats to dst


sub

public static void sub(float[] dst,
                       int dstIndex,
                       float[] a,
                       int aIndex,
                       float[] b,
                       int bIndex)
Sets vector dst to a minus b


sub

public static void sub(float[] dst,
                       int dstIndex,
                       float[] a,
                       int aIndex)
Subtracts vector a from vector dst.


sub

public static void sub(float[] dst,
                       float[] a,
                       float[] b)
Subtracts vector b from vector a.


sub

public static void sub(float[] dst,
                       float[] a)
Subtracts vector a from vector dst.


sub

public static void sub(float[] dst,
                       float ax,
                       float ay,
                       float az)
Substracts 3 floats from dst


scale

public static void scale(float scale,
                         float[] dst,
                         float[] src)
Scales a vector dst = scale * src


scale

public static void scale(float scale,
                         float[] dst,
                         int dstIndex,
                         float[] src,
                         int srcIndex)
Scales a vector dst = scale * src


scale

public static void scale(float scale,
                         float[] dst,
                         int dstIndex)
Scales a vector


scale

public static void scale(float scale,
                         float[] dst)
Scales a vector


invert

public static void invert(float[] dst)
Replaces dst[i] by 1.0f/dst[i]


scaleAdd

public static void scaleAdd(float[] dst,
                            int dstIndex,
                            float scale,
                            float[] a,
                            int aIndex,
                            float[] b,
                            int bIndex)
Sets vector a to scaled version of vector b, then adds vector c dst = s*a + b


scaleAdd

public static void scaleAdd(float[] dst,
                            float scale,
                            float[] a,
                            float[] b)
Sets vector dst to scaled version of vector a, then adds vector b dst = s*a + b


scaleAdd

public static void scaleAdd(float scale,
                            float[] dst,
                            int dstIndex,
                            float[] a,
                            int aIndex)
First scales vector dst, then and adds vector a. dst = s*dst + a


scaleAdd

public static void scaleAdd(float[] dst,
                            int dstIndex,
                            float scale,
                            float[] a,
                            int aIndex)
First scales vector a, then and a to dst dst = dst + s*a


scaleAdd

public static void scaleAdd(float[] dst,
                            float scale,
                            float[] a)
First scales vector a, then and a to dst dst = dst + s*a


scaleAdd

public static void scaleAdd(float scale,
                            float[] dst,
                            float[] a)
First scales vector dst, then and adds vector a. dst = s*dst + a


negate

public static void negate(float[] dst,
                          int dstIndex,
                          float[] src,
                          int srcIndex)
Sets vector dst to the negated version of vector src


negate

public static void negate(float[] dst,
                          float[] src)
Sets vector dst to the negated version of vector src


negate

public static void negate(float[] dst,
                          int dstIndex)
Negates a vector


negate

public static void negate(float[] dst)
Negates a vector


cross

public static void cross(float[] dst,
                         float[] a,
                         float[] b)
Calculates the cross product of two (3D) vectors defined by array "a", with index "aIndex", and array "b", with offset "bIndex", and stores the reult vector in array "c", with offset "cIndex". Indices are zero-based. The arrays arrays a, b, and dst can be the same; however, the offsets should ensure that the dst elements are not aliased with the a or b elements. dst-vector = a-vector X b-vector


cross

public static void cross(float[] dst,
                         int dstIndex,
                         float[] a,
                         int aIndex,
                         float[] b,
                         int bIndex)
Calculates the cross product of two (3D) vectors defined by array "a", with index "aIndex", and array "b", with offset "bIndex", and stores the reult vector in array "c", with offset "cIndex". Indices are zero-based. The arrays arrays a, b, and dst can be the same; however, the offsets should ensure that the dst elements are not aliased with the a or b elements. dst-vector = a-vector X b-vector


dot

public static float dot(float[] a,
                        float[] b)
Calculates the dot product for two vectors of length 3


dot

public static float dot(float[] a,
                        int aIndex,
                        float[] b,
                        int bIndex)
Calculates the dot product for two vectors of length 3


lengthSq

public static float lengthSq(float[] a,
                             int aIndex)
returns the square of the vector length


lengthSq

public static float lengthSq(float[] a)
returns the square of the vector length


length

public static float length(float[] a,
                           int aIndex)
returns the vector length


length

public static float length(float[] a)
returns the vector length


interpolateArrays

public static void interpolateArrays(float[] dst,
                                     float[] a,
                                     float[] b,
                                     float alpha)
Linear interpolates between a sequence of vectors a and b, and puts the result in vector dst: dst = (1-alpha)*a + alpha*b. The arrays a, b, and dst are assumed to have equals length.


interpolate

public static void interpolate(float[] dst,
                               int dstIndex,
                               float[] a,
                               int aIndex,
                               float[] b,
                               int bIndex,
                               float alpha)
Linear interpolates between vector a and b, and puts the result in vector dst: dst = (1-alpha)*a + alpha*b


interpolate

public static void interpolate(float[] dst,
                               float[] a,
                               float[] b,
                               float alpha)
Linear interpolates between vector a and b, and puts the result in vector dst: dst = (1-alpha)*a + alpha*b


normalize

public static void normalize(float[] dst,
                             int dstIndex,
                             float[] a,
                             int aIndex)
Normalizes a, that is, a = a/|a|

Parameters:
a - vector to be normalized
aIndex - index in a array
dst - vector to receive the result
dstIndex - index in dst array

normalize

public static void normalize(float[] a,
                             int aIndex)
Normalizes a, that is, a = a/|a|

Parameters:
a - vector to be normalized
aIndex - index in a array

normalize

public static void normalize(float[] dst,
                             float[] a)
Normalizes a, that is, dst = a/|a|

Parameters:
a - vector to be normalized
dst - vector to receive the result

normalize

public static void normalize(float[] a)
Normalizes a, that is, a = a/|a|

Parameters:
a - vector to be normalized

pmul

public static void pmul(float[] u,
                        float[] v)
Performs pointwise multiplication of two vectors: u[i] = u[i]*v[i];