org.deegree.commons.utils.math
Class Vectors3d

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

public class Vectors3d
extends Object

The Vectors3f class supplies convenience methods for 3 dimensional vector (represented as a double 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: 30119 $, $Date: 2011-03-22 10:02:35 +0100 (Tue, 22 Mar 2011) $
Author:
Rutger Bezema, last edited by: $Author: aschmitz $

Constructor Summary
Vectors3d()
           
 
Method Summary
static String asString(double[] a)
           
static double[] cross(double[] a, double[] b)
          Calculate the cross product of given vectors and store the result in a new allocated array of length 3.
static void cross(double[] a, double[] b, double[] result)
          Calculate the cross product of given vectors and store the result in given result vector with length 3
static double dot(double[] a, double[] b)
          Calculate the dot product of given vectors (with length 3).
static double length(double[] a)
           
static double[] normal(double[] a, double[] b, double[] 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(double[] a, double[] b, double[] c, double[] 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 double[] normal(double[] 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(double[] a, int index, double[] 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 double[] normal(double[] 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(double[] a, int ia, int ib, int ic, double[] 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 double[] normalize(double[] a)
          Normalize the given vector (of length 3) and store the result in a new allocated array of length 3.
static double[] normalizedNormal(double[] a, double[] b, double[] 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(double[] a, double[] b, double[] c, double[] 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 double[] normalizedNormal(double[] 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(double[] a, int index, double[] 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 double[] normalizedNormal(double[] 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(double[] a, int ia, int ib, int ic, double[] 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(double[] a)
          Normalize the given vector (of length 3) in place.
static double[] sub(double[] a, double[] b)
          Subtract b from a and store the result in a new allocated double[3] array.
static void sub(double[] a, double[] b, double[] result)
          Subtract b from a and store the result in result.
static double[] sub(double[] a, int ia, int ib)
           
static void sub(double[] a, int ia, int ib, double[] result)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Vectors3d

public Vectors3d()
Method Detail

sub

public static void sub(double[] a,
                       double[] b,
                       double[] 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 double[] sub(double[] a,
                           double[] b)
Subtract b from a and store the result in a new allocated double[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(double[] a,
                       int ia,
                       int ib,
                       double[] 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 double[] sub(double[] 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(double[] 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 double[] normal(double[] 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 double[] normal(double[] 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(double[] a,
                                int ia,
                                int ib,
                                int ic,
                                double[] 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(double[] a,
                                int index,
                                double[] 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 double[] normalizedNormal(double[] 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 double[] normalizedNormal(double[] 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(double[] a,
                                          int index,
                                          double[] 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(double[] a,
                                          int ia,
                                          int ib,
                                          int ic,
                                          double[] 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 double[] normal(double[] a,
                                    double[] b,
                                    double[] 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(double[] a,
                                double[] b,
                                double[] c,
                                double[] 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 double[] normalizedNormal(double[] a,
                                              double[] b,
                                              double[] 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(double[] a,
                                          double[] b,
                                          double[] c,
                                          double[] 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 double[] cross(double[] a,
                                   double[] 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(double[] a,
                               double[] b,
                               double[] 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 double dot(double[] a,
                               double[] 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 double length(double[] a)
Parameters:
a - array with length 3
Returns:
the euclidean length of the given vector

normalizeInPlace

public static final void normalizeInPlace(double[] 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 double[] normalize(double[] 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


Copyright © 2011. All Rights Reserved.