render
Class Vec

java.lang.Object
  extended byrender.Vec

public class Vec
extends java.lang.Object

Provides functionality to manipulate vectors.


Constructor Summary
Vec()
           
 
Method Summary
static void capLength(double[] vector, double maxLength)
          If vector's length is greater than maxLength, reduces it to that.
static void copy(double[] src, double[] dst)
          Copies contents of the src vector to the dst vector.
static void cross(double[] a, double[] b, double[] dst)
          Computes the cross-product of two vectors a and b and stores the result in dst.
static double distance(double[] a, double[] b, double[] difference)
           
static double dot(double[] a, double[] b)
          Computes the dot product of vectors a and b.
static boolean equals(double[] a, double[] b)
           
static double length(double[] vector)
           
static double norm(double[] v)
          Computes the magnitude of the vector.
static void normalize(double[] v)
          Normalizes vector v to unit-length.
static void rotate(double[] dst, int axis, double angle)
          Rotates a vector about x or y or z axis
static void scale(double[] vector, double length)
          Resizes vector to given length
static void set(double[] dst, double x, double y, double z)
          Populates the dst vector with values x, y, z.
static void zero(double[] a)
          Set all the entries to 0
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Vec

public Vec()
Method Detail

normalize

public static void normalize(double[] v)
Normalizes vector v to unit-length.

Parameters:
v - a vector

norm

public static double norm(double[] v)
Computes the magnitude of the vector.

Parameters:
v - a vector
Returns:
the magnitude of vector v

dot

public static double dot(double[] a,
                         double[] b)
Computes the dot product of vectors a and b. Vectors a and b must be of the same length.

Parameters:
a - source vector
b - source vector
Returns:
the result of a dot b

cross

public static void cross(double[] a,
                         double[] b,
                         double[] dst)
Computes the cross-product of two vectors a and b and stores the result in dst. a, b, and dst must be 3 dimensional vectors.

Parameters:
a - source vector 1
b - source vector 2
dst - resulting vector from a cross b

copy

public static void copy(double[] src,
                        double[] dst)
Copies contents of the src vector to the dst vector. Both vectors must be of the same length.

Parameters:
src - original vector
dst - copy of original vector

equals

public static boolean equals(double[] a,
                             double[] b)
Returns:
true if entries are the same

set

public static void set(double[] dst,
                       double x,
                       double y,
                       double z)
Populates the dst vector with values x, y, z.

Parameters:
dst - vector to be populated
x - component 0
y - component 1
z - component 2

rotate

public static void rotate(double[] dst,
                          int axis,
                          double angle)
Rotates a vector about x or y or z axis

Parameters:
dst - vector to be rotated
axis - of rotation: 0=x, 1=y, 2=z
angle - in radians

capLength

public static void capLength(double[] vector,
                             double maxLength)
If vector's length is greater than maxLength, reduces it to that.

Parameters:
vector - vector to resize
maxLength - if vector is longer than this, resizes it to this.

scale

public static void scale(double[] vector,
                         double length)
Resizes vector to given length

Parameters:
vector - vector to resize
length - desired length

length

public static double length(double[] vector)

zero

public static void zero(double[] a)
Set all the entries to 0


distance

public static double distance(double[] a,
                              double[] b,
                              double[] difference)
Parameters:
difference - a temp array of the same size as a and b to work with (its contents will be modified). This can be null, which will cause the code to dynamically allocate an array to be used.
Returns:
length of difference or Double.NaN if a and b do not have the same # of dimensions