jme.math
Class Vector

java.lang.Object
  extended byjme.math.Vector

public class Vector
extends java.lang.Object

Vector defines a three dimensional vector of (x,y,z).

Version:
$Id: Vector.java,v 1.8 2003/09/04 21:17:51 mojomonkey Exp $
Author:
Mark Powell

Field Summary
 float x
           
 float y
           
 float z
           
 
Constructor Summary
Vector()
          Constructor creates a base Vector with values of (0, 0, 0).
Vector(float[] attributes)
          Constructor creates a Vector based on an array of length three.
Vector(float x, float y, float z)
          Constructor creates a Vector with the value given in the parameter as (x, y, z).
Vector(Vector v)
          Constructor builds a new Vector as a copy of a passed in vector.
 
Method Summary
 Vector add(Vector v)
          add adds the values of this vector by another vector and returns the result.
 Vector cross(Vector v)
          cross calculates the cross product of this vector with a parameter vector v.
 Vector divide(float scalar)
          divide divides the values of this vector by a scalar and returns the result.
 float dot(Vector v)
          dot calculates the dot product of this vector with the parameter vector.
static void generateOrthonormalBasis(Vector u, Vector v, Vector w, boolean isUnitLength)
          generateOrthonormalBasis generates a vector that satisfies u and v are perpendicular in respect to w.
 Vector inverseRotate(Matrix m)
           
 float length()
          length calculates the magnitude of this vector.
 float lengthSquared()
          lengthSquared calculates the squared value of the magnitude of the vector.
 Vector mult(float scalar)
          mult multiplies the values of this vector by a scalar and returns the result.
 void negate()
          negate sets this vector to the negative (-x, -y, -z).
 Vector normalize()
          normalize returns the unit vector of this vector.
 Vector rotate(Matrix m)
          rotate rotates a vector about a rotation matrix.
 Vector subtract(Vector v)
          subtract subtracts the values of this vector by another vector and returns the result.
 java.lang.String toString()
          toString returns the string representation of this Vector.
 void unitize()
          unitize sets this vector to the unit vector or direction vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

x

public float x

y

public float y

z

public float z
Constructor Detail

Vector

public Vector()
Constructor creates a base Vector with values of (0, 0, 0).


Vector

public Vector(float x,
              float y,
              float z)
Constructor creates a Vector with the value given in the parameter as (x, y, z).

Parameters:
x - the x value of the vector.
y - the y value of the vector.
z - the z value of the vector.

Vector

public Vector(float[] attributes)
Constructor creates a Vector based on an array of length three. Where the first position is x, second y, and third z.

Parameters:
attributes - the attributes of the Vector.
Throws:
MonkeyRuntimeException - if the attributes is not length 3.

Vector

public Vector(Vector v)
Constructor builds a new Vector as a copy of a passed in vector.

Parameters:
v - the vector to copy.
Method Detail

divide

public Vector divide(float scalar)
divide divides the values of this vector by a scalar and returns the result. The values of this vector remain untouched.

Parameters:
scalar - the value to divide this vectors attributes by.
Returns:
the result Vector.

mult

public Vector mult(float scalar)
mult multiplies the values of this vector by a scalar and returns the result. The values of this vector remain untouched.

Parameters:
scalar - the value to multiply the vector attributes by.
Returns:
the result Vector.

add

public Vector add(Vector v)
add adds the values of this vector by another vector and returns the result. The values of this vector remain untouched.

Returns:
the result Vector.

subtract

public Vector subtract(Vector v)
subtract subtracts the values of this vector by another vector and returns the result. The values of this vector remain untouched.

Returns:
the result Vector.

length

public float length()
length calculates the magnitude of this vector.

Returns:
the length or magnitude of the vector.

lengthSquared

public float lengthSquared()
lengthSquared calculates the squared value of the magnitude of the vector.

Returns:
the magnitude squared of the vector.

dot

public float dot(Vector v)
dot calculates the dot product of this vector with the parameter vector.

Parameters:
v - the vector to use for the dot product with this.
Returns:
the dot product of this vector with the parameter vector.

cross

public Vector cross(Vector v)
cross calculates the cross product of this vector with a parameter vector v.

Parameters:
v - the vector to take the cross product of with this.
Returns:
the cross product vector.

rotate

public Vector rotate(Matrix m)
rotate rotates a vector about a rotation matrix. The resulting vector is returned.

Parameters:
m - the rotation matrix.
Returns:
the rotated vector.

inverseRotate

public Vector inverseRotate(Matrix m)

negate

public void negate()
negate sets this vector to the negative (-x, -y, -z).


normalize

public Vector normalize()
normalize returns the unit vector of this vector.

Returns:
unit vector of this vector.

unitize

public void unitize()
unitize sets this vector to the unit vector or direction vector.


generateOrthonormalBasis

public static void generateOrthonormalBasis(Vector u,
                                            Vector v,
                                            Vector w,
                                            boolean isUnitLength)
generateOrthonormalBasis generates a vector that satisfies u and v are perpendicular in respect to w.

Parameters:
u - the u vector to be set.
v - the v vector to be set.
w - the w vector should already be set.
isUnitLength - true if w is unitized, false otherwise.

toString

public java.lang.String toString()
toString returns the string representation of this Vector. The format is as follows:

(XXX.XXX, YYY.YYY, ZZZ.ZZZ)

Returns:
the string representation of the vector.