cdx
Class VectorMath

java.lang.Object
  extended by cdx.VectorMath

public final class VectorMath
extends java.lang.Object

The VectorMath class implements the mathematical functions for manipulating vectors of two and three dimensions. Its operators are patterned after three address code machines, specifying two operands and a destination operand. This machine is optimised for performance, thus the methods are static, contain no calls, create no objects, and do not perform error checking or synchronisation.


Constructor Summary
VectorMath()
           
 
Method Summary
static void add(Vector2d a, Vector2d b, Vector2d dest)
          The add method takes two vectors and adds them, placing the result in a third vector.
static void add(Vector3d a, Vector3d b, Vector3d dest)
          The add method takes two vectors and adds them, placing the result in a third vector.
static void convert(Vector2d src, Vector3d dest)
          The convert methods have been overridden to allow 2d vectors to be converted to 3d vectors and vice versa.
static void convert(Vector3d src, Vector2d dest)
          The convert methods have been overridden to allow 2d vectors to be converted to 3d vectors and vice versa.
static float distance(Vector2d a, Vector2d b)
          The distance method takes two vectors and computes their (Euclidean) distance.
static float distance(Vector2d a, Vector3d b)
          The distance method takes two vectors and computes their (Euclidean) distance.
static float distance(Vector3d a, Vector2d b)
          The distance method takes two vectors and computes their (Euclidean) distance.
static float distance(Vector3d a, Vector3d b)
          The distance method takes two vectors and computes their (Euclidean) distance.
static float dotProduct(Vector2d a, Vector2d b)
          The dotProduct method computes the dot product between two vectors using the standard inner product formula.
static float dotProduct(Vector3d a, Vector3d b)
          The dotProduct method computes the dot product between two vectors using the standard inner product formula.
static float magnitude(Vector2d a)
          The magnitude method takes a Vector2d and computes its magnitude according the Euclidean norm.
static float magnitude(Vector3d a)
          The magnitude method takes a Vector3d and computes its magnitude according the Euclidean norm.
static void normalize(Vector2d a, Vector2d dest)
          The normalize method takes a Vector2d and if it is non-zero, will normalize it so that its magnitude will be 1.
static void normalize(Vector3d a, Vector3d dest)
          The normalize method takes a Vector3d and if it is non-zero, will normalize it so that its magnitude will be 1.
static float phi(Vector3d a)
          The phi method takes a Vector3d and calculates the elevation between the XY-plane and the vector.
static int quadrant(Vector2d a)
          The quadrant method is a utility function for two dimensional vectors that takes a vector as a parameter and will return an integer describing what quadrant of the xy plane the vector lies in.
static void rotate(Vector3d a, float radians, Vector3d dest)
          The rotate method takes a Vector3d and a scalar float value and will rotate the vector in the xy plane.
static void scale(Vector2d a, float scale, Vector2d dest)
          The scale method takes a Vector2d and a scalar float value multiplies each component of the Vector, storing the result in the third parameter.
static void scale(Vector3d a, float scale, Vector3d dest)
          The scale method takes a Vector3d and a scalar float value multiplies each component of the Vector, storing the result in the third parameter.
static float sqDistance(Vector2d a, Vector2d b)
          The sqDistance method takes two vectors and computes the square of their (Euclidean) distance.
static float sqDistance(Vector2d a, Vector3d b)
          The sqDistance method takes two vectors and computes the square of their (Euclidean) distance.
static float sqDistance(Vector3d a, Vector2d b)
          The sqDistance method takes two vectors and computes the square of their (Euclidean) distance.
static float sqDistance(Vector3d a, Vector3d b)
          The sqDistance method takes two vectors and computes the square of their (Euclidean) distance.
static void subtract(Vector2d a, Vector2d b, Vector2d dest)
          The subtract method takes two vectors and subtracts them, placing the result in a third vector.
static void subtract(Vector3d a, Vector3d b, Vector3d dest)
          The subtract method takes two vectors and subtracts them, placing the result in a third vector.
static float theta(Vector3d a)
          The theta method takes a Vector3d and calculates the angle between the X-axis and the vector, ignoring the z component of the vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VectorMath

public VectorMath()
Method Detail

add

public static void add(Vector3d a,
                       Vector3d b,
                       Vector3d dest)
The add method takes two vectors and adds them, placing the result in a third vector.

Parameters:
a - the value of the first vector
b - the value of the second vector
dest - the destination Vector3d to store the result

subtract

public static void subtract(Vector3d a,
                            Vector3d b,
                            Vector3d dest)
The subtract method takes two vectors and subtracts them, placing the result in a third vector.

Parameters:
a - the value of the first vector
b - the value of the second vector
dest - the destination Vector3d to store the result

scale

public static void scale(Vector3d a,
                         float scale,
                         Vector3d dest)
The scale method takes a Vector3d and a scalar float value multiplies each component of the Vector, storing the result in the third parameter.

Parameters:
a - the value of the first vector
scale - the value to scale the vector by
dest - the destination Vector3d to store the result

normalize

public static void normalize(Vector3d a,
                             Vector3d dest)
The normalize method takes a Vector3d and if it is non-zero, will normalize it so that its magnitude will be 1.

Parameters:
a - the value of the vector to normalize
dest - the destination Vector3d to store the result
Throws:
ZeroVectorException - if the vector is zero

magnitude

public static float magnitude(Vector3d a)
The magnitude method takes a Vector3d and computes its magnitude according the Euclidean norm.

Parameters:
a - the value of the vector of which to compute the magnitude
Returns:
the magnitude of the vector

distance

public static float distance(Vector3d a,
                             Vector3d b)
The distance method takes two vectors and computes their (Euclidean) distance.

Parameters:
a - the value of the first vector
b - the value of the second vector
Returns:
the distance between the two vectors

sqDistance

public static float sqDistance(Vector3d a,
                               Vector3d b)
The sqDistance method takes two vectors and computes the square of their (Euclidean) distance. This is just an optimization for the distance method that avoids an expensive floating point square root computation.

Parameters:
a - the value of the first vector
b - the value of the second vector
Returns:
the square of the distance between the two vectors

dotProduct

public static float dotProduct(Vector3d a,
                               Vector3d b)
The dotProduct method computes the dot product between two vectors using the standard inner product formula.

Parameters:
a - the value of the first vector
b - the value of the second vector
Returns:
the value of their dot product

rotate

public static void rotate(Vector3d a,
                          float radians,
                          Vector3d dest)
The rotate method takes a Vector3d and a scalar float value and will rotate the vector in the xy plane.

Parameters:
a - the value of the first vector
radians - the value to rotate the vector by
dest - the destination Vector3d to store the result

theta

public static float theta(Vector3d a)
The theta method takes a Vector3d and calculates the angle between the X-axis and the vector, ignoring the z component of the vector.

Parameters:
a - the vector of which to calculate the theta angle
Returns:
the radian value in the range [0, 2*pi] that represents the angle between the x axis and this vector (in the xy plane)
Throws:
ZeroVectorException - if the vector passed equals the zero vector, for which the theta value is undefined

phi

public static float phi(Vector3d a)
The phi method takes a Vector3d and calculates the elevation between the XY-plane and the vector.

Parameters:
a - the vector of which to calculate the phi angle
Returns:
the radian value in the range [-pi/2, pi/2] that represents the angle between the x axis and this vector (in the xy plane)
Throws:
ZeroVectorException - if the vector passed equals the zero vector, for which the phi value is undefined

add

public static void add(Vector2d a,
                       Vector2d b,
                       Vector2d dest)
The add method takes two vectors and adds them, placing the result in a third vector.

Parameters:
a - the value of the first vector
b - the value of the second vector
dest - the destination Vector2d to store the result

subtract

public static void subtract(Vector2d a,
                            Vector2d b,
                            Vector2d dest)
The subtract method takes two vectors and subtracts them, placing the result in a third vector.

Parameters:
a - the value of the first vector
b - the value of the second vector
dest - the destination Vector2d to store the result

scale

public static void scale(Vector2d a,
                         float scale,
                         Vector2d dest)
The scale method takes a Vector2d and a scalar float value multiplies each component of the Vector, storing the result in the third parameter.

Parameters:
a - the value of the first vector
scale - the value to scale the vector by
dest - the destination Vector2d to store the result

normalize

public static void normalize(Vector2d a,
                             Vector2d dest)
The normalize method takes a Vector2d and if it is non-zero, will normalize it so that its magnitude will be 1.

Parameters:
a - the value of the vector to normalize
dest - the destination Vector2d to store the result
Throws:
ZeroVectorException - if the vector is zero

magnitude

public static float magnitude(Vector2d a)
The magnitude method takes a Vector2d and computes its magnitude according the Euclidean norm.

Parameters:
a - the value of the vector of which to compute the magnitude
Returns:
the magnitude of the vector

distance

public static float distance(Vector2d a,
                             Vector2d b)
The distance method takes two vectors and computes their (Euclidean) distance.

Parameters:
a - the value of the first vector
b - the value of the second vector
Returns:
the distance between the two vectors

sqDistance

public static float sqDistance(Vector2d a,
                               Vector2d b)
The sqDistance method takes two vectors and computes the square of their (Euclidean) distance. This is just an optimization for the distance method that avoids an expensive floating point square root computation.

Parameters:
a - the value of the first vector
b - the value of the second vector
Returns:
the square of the distance between the two vectors

dotProduct

public static float dotProduct(Vector2d a,
                               Vector2d b)
The dotProduct method computes the dot product between two vectors using the standard inner product formula.

Parameters:
a - the value of the first vector
b - the value of the second vector
Returns:
the value of their dot product

quadrant

public static int quadrant(Vector2d a)
The quadrant method is a utility function for two dimensional vectors that takes a vector as a parameter and will return an integer describing what quadrant of the xy plane the vector lies in.

Parameters:
a - the vector to compute the quadrant of
Returns:
the integer VectorConstants.XX_QUADRANT value corresponding to which quadrant the vector lies in

convert

public static void convert(Vector3d src,
                           Vector2d dest)
The convert methods have been overridden to allow 2d vectors to be converted to 3d vectors and vice versa.

Parameters:
src - the value of the source vector
dest - the value of the destination vector

convert

public static void convert(Vector2d src,
                           Vector3d dest)
The convert methods have been overridden to allow 2d vectors to be converted to 3d vectors and vice versa.

Parameters:
src - the value of the source vector
dest - the value of the destination vector

distance

public static float distance(Vector3d a,
                             Vector2d b)
The distance method takes two vectors and computes their (Euclidean) distance. It has been overloaded to allow the computation of the distance between a 3d vector and a 2d vector.

Parameters:
a - the value of the first vector
b - the value of the second vector
Returns:
the distance between the two vectors

distance

public static float distance(Vector2d a,
                             Vector3d b)
The distance method takes two vectors and computes their (Euclidean) distance. It has been overloaded to allow the computation of the distance between a 3d vector and a 2d vector.

Parameters:
a - the value of the first vector
b - the value of the second vector
Returns:
the distance between the two vectors

sqDistance

public static float sqDistance(Vector3d a,
                               Vector2d b)
The sqDistance method takes two vectors and computes the square of their (Euclidean) distance. This is just an optimization for the distance method that avoids an expensive floating point square root computation. It has been overloaded to allow the computation of the distance between a 3d vector and a 2d vector.

Parameters:
a - the value of the first vector
b - the value of the second vector
Returns:
the square of the distance between the two vectors

sqDistance

public static float sqDistance(Vector2d a,
                               Vector3d b)
The sqDistance method takes two vectors and computes the square of their (Euclidean) distance. This is just an optimization for the distance method that avoids an expensive floating point square root computation. It has been overloaded to allow the computation of the distance between a 3d vector and a 2d vector.

Parameters:
a - the value of the first vector
b - the value of the second vector
Returns:
the square of the distance between the two vectors