org.deegree.commons.utils.math
Class Vectors3f

java.lang.Object
  extended by org.deegree.commons.utils.math.Vectors3f

public class Vectors3f
extends Object

The Vectors3f class supplies convenience methods for 3 dimensional vector (represented as a float array with length 3 ) calculations. No checking what so ever is done, so the callee has to make sure the arrays are initialized and have a length of 3.

Two different methods of almost all functions exist, one which creates a new allocated array and one which puts the result in a supplied array. Again, the callee has to make sure the supplied array is initialized and has a length of at least 3.

Version:
$Revision: 19841 $, $Date: 2009-09-29 14:03:45 +0200 (Tue, 29 Sep 2009) $
Author:
Rutger Bezema, last edited by: $Author: rbezema $

Constructor Summary
Vectors3f()
           
 
Method Summary
static String asString(float[] a)
           
static float[] cross(float[] a, float[] b)
          Calculate the cross product of given vectors and store the result in a new allocated array of length 3.
static void cross(float[] a, float[] b, float[] result)
          Calculate the cross product of given vectors and store the result in given result vector with length 3
static float distance(float[] a, float[] b)
          Returns the distance between the two given vectors.
static float distance(float[] a, int ia, float[] b, int ib)
          Returns the distance between the two given vectors.
static float dot(float[] a, float[] b)
          Calculate the dot product of given vectors (with length 3).
static boolean equals(float[] first, float[] second, float precision)
           
static float length(float[] a)
           
static float[] normal(float[] a, float[] b, float[] c)
          Calculate the normal vector for given vectors a, b, c by calculating the cross product from ab x ac and store the result in a new allocated array with length 3.
static void normal(float[] a, float[] b, float[] c, float[] result)
          Calculate the normal vector for given vectors a, b, c by calculating the cross product from ab x ac and store the result in given result vector.
static float[] normal(float[] a, int index)
          Calculate the normal vector for vectors starting at index by using the vectors a=(index, index+1, index+2), b=(index+3, index+4, index+5) and c=(index+6, index+7, index+8) by calculating the cross product from ab x ac and store the result in a new allocated array with length 3.
static void normal(float[] a, int index, float[] result)
          Calculate the normal vector for vectors starting at index by using the vectors a=(index, index+1, index+2), b=(index+3, index+4, index+5) and c=(index+6, index+7, index+8) by calculating the cross product from ab x ac and store the result in given array with length 3.
static float[] normal(float[] a, int ia, int ib, int ic)
          Calculate the normal vector for vectors starting at index by using the vectors a=(ia, ia+1, ia+2), b=(ib, ib+1, ib+3) and c=(ic, ic+1, ic+2) by calculating the cross product from ab x ac and store the result in a new allocated array with length 3.
static void normal(float[] a, int ia, int ib, int ic, float[] result)
          Calculate the normal vector for vectors starting at given indizes a=(ia, ia+1, ia+2), b=(ib, ib+1, ib+2) and c=(ic, ic+1, ic+2) by calculating the cross product from ab x ac and store the result in given array with length 3.
static float[] normalize(float[] a)
          Normalize the given vector (of length 3) and store the result in a new allocated array of length 3.
static float[] normalizedNormal(float[] a, float[] b, float[] c)
          Calculate the normalized normal vector for given triangle with vertices a, b, c by calculating the cross product from ab x ac and normalize the result which will be stored in a new allocated array of length 3.
static void normalizedNormal(float[] a, float[] b, float[] c, float[] result)
          Calculate the normalized normal vector for given triangle with vertices a, b, c by calculating the cross product from ab x ac and normalize the result which will be stored in the given result array with length 3.
static float[] normalizedNormal(float[] a, int index)
          Calculate the normal vector for vectors starting at index by using the vectors a=(index, index+1, index+2), b=(index+3, index+4, index+5) and c=(index+6, index+7, index+8) by calculating the cross product from ab x ac and store the result in a new allocated array with length 3.
static void normalizedNormal(float[] a, int index, float[] result)
          Calculate the normalized normal vector for given triangle with vertices a=(index, index+1, index+2), b=(index+3, index+4, index+5) and c=(index+6, index+7, index+8) by calculating the cross product from ab x ac and normalize the result which will be stored in the given result array with length 3.
static float[] normalizedNormal(float[] a, int ia, int ib, int ic)
          Calculate the normal vector for vectors starting at index by using the vectors a=(ia, ia+1, ia+2), b=(ib, ib+1, ib+2) and c=(ic, ic+1, ic+2) by calculating the cross product from ab x ac and store the result in a new allocated array with length 3.
static void normalizedNormal(float[] a, int ia, int ib, int ic, float[] result)
          Calculate the normalized normal vector for given triangle with vertices a=(ia, ia+1, ia+2), b=(ib, ib+1, ib+2) and c=(ic, ic+1, ic+2) by calculating the cross product from ab x ac and normalize the result which will be stored in the given result array with length 3.
static void normalizeInPlace(float[] a)
          Normalize the given vector (of length 3) in place.
static void scale(float scale, float[] vector)
          Apply the given scale to all scalars in the vector
static float[] sub(float[] a, float[] b)
          Subtract b from a and store the result in a new allocated float[3] array.
static void sub(float[] a, float[] b, float[] result)
          Subtract b from a and store the result in result.
static float[] sub(float[] a, int ia, int ib)
           
static void sub(float[] a, int ia, int ib, float[] result)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Vectors3f

public Vectors3f()
Method Detail

distance

public static float distance(float[] a,
                             float[] b)
Returns the distance between the two given vectors.

Parameters:
a - array with length 3
b - array with length 3
Returns:
the distance between a and b.

distance

public static float distance(float[] a,
                             int ia,
                             float[] b,
                             int ib)
Returns the distance between the two given vectors.

Parameters:
a - array with arbitrary length
ia - index of vector in a array
b - array with arbitrary length
ib - index of vector in b array
Returns:
the distance between a and b.

sub

public static void sub(float[] a,
                       float[] b,
                       float[] result)
Subtract b from a and store the result in result.

Parameters:
a - array with length 3
b - array with length 3
result - array with length 3

sub

public static float[] sub(float[] a,
                          float[] b)
Subtract b from a and store the result in a new allocated float[3] array.

Parameters:
a - array with length 3
b - array with length 3
Returns:
an array with length 3 containing a-b.

sub

public static void sub(float[] a,
                       int ia,
                       int ib,
                       float[] result)
Parameters:
a - an array containing the ordinates of the vectors
ia - index of the first vector
ib - index of the second vector
result - an array with length 3

sub

public static float[] sub(float[] a,
                          int ia,
                          int ib)
Parameters:
a - an array containing the ordinates of the vectors
ia - index of the first vector
ib - index of the second vector
Returns:
a new allocated array with length 3 containing (a[ia])-(a[ib]).

asString

public static final String asString(float[] a)
Parameters:
a - array with length 3
Returns:
the String representation of the scalars of given array separated by a comma (',')

normal

public static final float[] normal(float[] a,
                                   int index)
Calculate the normal vector for vectors starting at index by using the vectors a=(index, index+1, index+2), b=(index+3, index+4, index+5) and c=(index+6, index+7, index+8) by calculating the cross product from ab x ac and store the result in a new allocated array with length 3.

Parameters:
a - array with length > index + 9
index - index of the first vector
Returns:
a newly allocated array with length 3 containing the normal vector.

normal

public static final float[] normal(float[] a,
                                   int ia,
                                   int ib,
                                   int ic)
Calculate the normal vector for vectors starting at index by using the vectors a=(ia, ia+1, ia+2), b=(ib, ib+1, ib+3) and c=(ic, ic+1, ic+2) by calculating the cross product from ab x ac and store the result in a new allocated array with length 3.

Parameters:
a - array containing the ordinates of the vectors
ia - index of the first vector
ib - index of the second vector
ic - index of the third vector
Returns:
a newly allocated array with length 3 containing the normal vector.

normal

public static final void normal(float[] a,
                                int ia,
                                int ib,
                                int ic,
                                float[] result)
Calculate the normal vector for vectors starting at given indizes a=(ia, ia+1, ia+2), b=(ib, ib+1, ib+2) and c=(ic, ic+1, ic+2) by calculating the cross product from ab x ac and store the result in given array with length 3.

Parameters:
a - array containing the ordinates of the vectors
ia - index of the first vector
ib - index of the second vector
ic - index of the third vector
result - array with length 3
Throws:
IndexOutOfBoundsException - if one of the indizes doesn't fit

normal

public static final void normal(float[] a,
                                int index,
                                float[] result)
Calculate the normal vector for vectors starting at index by using the vectors a=(index, index+1, index+2), b=(index+3, index+4, index+5) and c=(index+6, index+7, index+8) by calculating the cross product from ab x ac and store the result in given array with length 3.

Parameters:
a - an array containing the ordinates of the vectors with length > index + 9
index - index of the first vector
result - array with length 3
Throws:
IndexOutOfBoundsException - if a.length < index +9

normalizedNormal

public static final float[] normalizedNormal(float[] a,
                                             int index)
Calculate the normal vector for vectors starting at index by using the vectors a=(index, index+1, index+2), b=(index+3, index+4, index+5) and c=(index+6, index+7, index+8) by calculating the cross product from ab x ac and store the result in a new allocated array with length 3. If the resulting normal has length 0, the (unnormalized) vector will be returned .

Parameters:
a - array containing the ordinates of the vectors with length > index + 9
index - index of the first vector
Returns:
a new allocated array with length 3 containing the normalized normal vector.

normalizedNormal

public static final float[] normalizedNormal(float[] a,
                                             int ia,
                                             int ib,
                                             int ic)
Calculate the normal vector for vectors starting at index by using the vectors a=(ia, ia+1, ia+2), b=(ib, ib+1, ib+2) and c=(ic, ic+1, ic+2) by calculating the cross product from ab x ac and store the result in a new allocated array with length 3. If the resulting normal has length 0, the (unnormalized) vector will be returned .

Parameters:
a - array containing the ordinates of the vectors
ia - index of the first vector
ib - index of the second vector
ic - index of the third vector
Returns:
a new allocated array with length 3 containing the normalized normal vector.

normalizedNormal

public static final void normalizedNormal(float[] a,
                                          int index,
                                          float[] result)
Calculate the normalized normal vector for given triangle with vertices a=(index, index+1, index+2), b=(index+3, index+4, index+5) and c=(index+6, index+7, index+8) by calculating the cross product from ab x ac and normalize the result which will be stored in the given result array with length 3. If the resulting normal has length 0, the (unnormalized) vector will be returned .

Parameters:
a - array containing the ordinates of the vectors with length > index + 9
index - index of the first vector
result - array with length 3

normalizedNormal

public static final void normalizedNormal(float[] a,
                                          int ia,
                                          int ib,
                                          int ic,
                                          float[] result)
Calculate the normalized normal vector for given triangle with vertices a=(ia, ia+1, ia+2), b=(ib, ib+1, ib+2) and c=(ic, ic+1, ic+2) by calculating the cross product from ab x ac and normalize the result which will be stored in the given result array with length 3. If the resulting normal has length 0, the (unnormalized) vector will be returned .

Parameters:
a - array containing the ordinates of the vectors
ia - index of the first vector
ib - index of the second vector
ic - index of the third vector
result - array with length 3

normal

public static final float[] normal(float[] a,
                                   float[] b,
                                   float[] c)
Calculate the normal vector for given vectors a, b, c by calculating the cross product from ab x ac and store the result in a new allocated array with length 3.

Parameters:
a - array with length 3
b - array with length 3
c - array with length 3
Returns:
a newly allocated array with length 3 containing the normalized normal vector.

normal

public static final void normal(float[] a,
                                float[] b,
                                float[] c,
                                float[] result)
Calculate the normal vector for given vectors a, b, c by calculating the cross product from ab x ac and store the result in given result vector.

Parameters:
a - array with length 3
b - array with length 3
c - array with length 3
result - array with length 3

normalizedNormal

public static final float[] normalizedNormal(float[] a,
                                             float[] b,
                                             float[] c)
Calculate the normalized normal vector for given triangle with vertices a, b, c by calculating the cross product from ab x ac and normalize the result which will be stored in a new allocated array of length 3. If the resulting normal has length 0, the (unnormalized) vector will be returned .

Parameters:
a - array with length 3
b - array with length 3
c - array with length 3
Returns:
a new allocated array with length 3 containing the normalized normal vector.

normalizedNormal

public static final void normalizedNormal(float[] a,
                                          float[] b,
                                          float[] c,
                                          float[] result)
Calculate the normalized normal vector for given triangle with vertices a, b, c by calculating the cross product from ab x ac and normalize the result which will be stored in the given result array with length 3. If the resulting normal has length 0, the (unnormalized) vector will be returned .

Parameters:
a - array with length 3
b - array with length 3
c - array with length 3
result - array with length 3

cross

public static final float[] cross(float[] a,
                                  float[] b)
Calculate the cross product of given vectors and store the result in a new allocated array of length 3.

Parameters:
a - array with length 3
b - array with length 3
Returns:
a new allocated array with length 3.

cross

public static final void cross(float[] a,
                               float[] b,
                               float[] result)
Calculate the cross product of given vectors and store the result in given result vector with length 3

Parameters:
a - array with length 3
b - array with length 3
result - array with length 3

dot

public static final float dot(float[] a,
                              float[] b)
Calculate the dot product of given vectors (with length 3).

Parameters:
a - array with length 3
b - array with length 3
Returns:
the dot product of given vectors.

length

public static final float length(float[] a)
Parameters:
a - array with length 3
Returns:
the euclidean length of the given vector

normalizeInPlace

public static final void normalizeInPlace(float[] a)
Normalize the given vector (of length 3) in place. If the length of the vector is 0, the vector will not be modified.

Parameters:
a - array with length 3

normalize

public static final float[] normalize(float[] a)
Normalize the given vector (of length 3) and store the result in a new allocated array of length 3. If the length of the vector is 0, the result vector will contain the same values as the given vector.

Parameters:
a - array with length 3
Returns:
the normalized vector

equals

public static boolean equals(float[] first,
                             float[] second,
                             float precision)
Parameters:
first -
second -
precision -
Returns:
true if the ordinate values of the vectors are in range of precision.

scale

public static void scale(float scale,
                         float[] vector)
Apply the given scale to all scalars in the vector

Parameters:
scale - to be applied
vector - with length 3.


Copyright © 2011. All Rights Reserved.