hmi.math
Class Vec2f

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

public final class Vec2f
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 VEC2F_SIZE
          Length of Vec2f arrays is 2
static int X
          Offset values for Vec4 vectors.
static int Y
           
 
Constructor Summary
private Vec2f()
           
 
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 2 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 float dot(float[] a, float[] b)
          Calculates the dot product for two vectors of length 2
static float dot(float[] a, int aIndex, float[] b, int bIndex)
          Calculates the dot product for two vectors of length 2
static boolean epsilonEquals(float[] a, float[] b, 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)
          Tests for equality of one vectors and 2 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[] getVec2f()
          Returns a new float[2] array with zero components
static float[] getVec2f(float[] vec2f)
          Rturns a new float[2] array with initialized components
static float[] getVec2f(float x, float y)
          Returns a new float[2] array with initialized components
static float[] getZero()
          Returns a new float[2] 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 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)
          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 Vec2f to (0, 0)
static void setZero(float[] dst, int dstIndex)
          Resets the Vec2f to (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 2 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), representing the Vec2f value.
static String toString(float[] a, int index)
          Returns a String of the form (x, y), representing the Vec2f value.
static String toString(float[] a, int fieldwidth, int precision)
          Returns a String of the form (x, y), representing the Vec2f value.
static String toString(float[] a, String fmt)
          Returns a String of the form (x, y), representing the Vec2f value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VEC2F_SIZE

public static final int VEC2F_SIZE
Length of Vec2f arrays is 2

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

BUFSIZE

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

Vec2f

private Vec2f()
Method Detail

getVec2f

public static float[] getVec2f()
Returns a new float[2] array with zero components


getVec2f

public static float[] getVec2f(float x,
                               float y)
Returns a new float[2] array with initialized components


getVec2f

public static float[] getVec2f(float[] vec2f)
Rturns a new float[2] array with initialized components


getZero

public static float[] getZero()
Returns a new float[2] 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


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)
Tests for equality of one vectors and 2 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.


toString

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


toString

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


toString

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


toString

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


setZero

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


setZero

public static void setZero(float[] dst,
                           int dstIndex)
Resets the Vec2f to (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)
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 2 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 2 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


dot

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


dot

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


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


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];