net.java.dev.joode.util
Class Vector3

java.lang.Object
  extended by net.java.dev.joode.util.Real
      extended by net.java.dev.joode.util.Vector3

public class Vector3
extends Real

Author:
Tom Larkworthy, Arne Mueller A Vector3 is used to save positions and directions in 3D space.

Field Summary
 
Fields inherited from class net.java.dev.joode.util.Real
m
 
Constructor Summary
Vector3()
          creates a new Vector3 at (0|0|0); use aquire instance instead for reduced garbage (and return the instance afterwards)
Vector3(float x, float y, float z)
          creates a new Vector3 at (i|j|k)
Vector3(Real r)
          creates a new Vector3 by copying all the values from r.
Vector3(Vector3 v)
          creates a new Vector3 by copying all the values from v.
 
Method Summary
 void add(float x, float y, float z)
           
 Vector3 add(Vector3 v, Vector3 result)
           
static Vector3 aquireDirtyInstance()
          returns a Vector3.
static Vector3 aquireInstance()
          returns a zeroed Vector3.
static Vector3 aquireInstance(float x, float y, float z)
          returns an initialized Vector3.
static Vector3 aquireInstance(Real values)
          returns a Vector3 initialized to the first three parameters of the passed in Real.
static Vector3 aquireInstance(Vector3 values)
          returns a Vector3 initialized to the first three parameters of the passed in vector3.
 void bar(Matrix3 result)
          if this is a returns abar such that abar * b = a cross b abar = [0 -a3 a2 a3 0 -a1 -a2 a1 0 ] as refered to in the ODE joint documentation "A cross product between two vectors in 3d space can be rewritten in terms of pure matrix multiplication as the product of a Skew-symmetric matrix and a vector" from Wikipedia
 void constructPlaneSpace(Vector3 p, Vector3 q)
          given a unit length "normal" vector n, generate vectors p and q vectors that are an orthonormal basis for the plane space perpendicular to n.
 float cosAngle(Vector3 other)
          this = a other = b computes the cos of the angle between the two vectors: cos(theta) = a.dot(b)/(|a||b|)
 Vector3 cross(Vector3 v)
          does not modify this, creates a new vector and returns it
 void cross(Vector3 v, RealPointer result)
           
 Vector3 cross(Vector3 v, Vector3 result)
          garbageless cross product of this X v = result result is overwitten
 float dist(Vector3 o)
          calculates the distance of this Vector and o.
 float dist2D(Vector3 o)
          Calculates a distance without using the z information
 float distSquared(Vector3 o)
          calculates the squared distance of this Vector and o.
static boolean epsilonEquals(Vector3 a, Vector3 b, float e)
          tests if two vectors are equal to within the given tolerance
 float getX()
           
 float getY()
           
 float getZ()
           
 float max()
          returns the maximum value among the components
 float mean()
           
 float min()
          returns the minumum value among the components
 float norm()
           
static float planePlaneAngle(Real normal1, Real normal2)
          returns the angle between a plane and another plane n1.n2=|n1||n2|cos(theta) note this function assumes the input normals ARE nomalized (works with hyperplanes)
static float planePlaneCosAngle(Vector3 normal1, Vector3 normal2)
           
static float planeVectorAngle(Vector3 planeNormal, Vector3 line)
          returns the angle between a plane and a line from:- n.b=|n||b|sin(theta)
static Vector3 randomVector()
          returns a random vector with components uniformly distruted between 0-1
static void releaseInstance(Vector3 instance)
          releases the instance of the Vector3 back into an object pool.
 void set(float x, float y, float z)
           
 void set(Vector3 v)
           
 void setX(float x)
           
 void setY(float y)
           
 void setZ(float z)
           
 void sub(float x, float y, float z)
           
 java.lang.String toString()
           
 float var()
           
 
Methods inherited from class net.java.dev.joode.util.Real
add, aquireDirtyInstance, aquireInstance, dot, dot, epsilonEquals, epsilonEquals, fill, get, length, lengthSquared, normalize, releaseInstance, scale, set, set, setZero, size, sub
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Vector3

public Vector3()
creates a new Vector3 at (0|0|0); use aquire instance instead for reduced garbage (and return the instance afterwards)


Vector3

public Vector3(float x,
               float y,
               float z)
creates a new Vector3 at (i|j|k)

Parameters:
x - the x coordinate
y - the y coordinate
z - the z coordinate use aquire instance instead for reduced garbage (and return the instance afterwards)

Vector3

public Vector3(Vector3 v)
creates a new Vector3 by copying all the values from v. use aquire instance instead for reduced garbage (and return the instance afterwards)

Parameters:
v - the Vector to clone.

Vector3

public Vector3(Real r)
creates a new Vector3 by copying all the values from r. r must have a size equal or bigger than 3

Parameters:
r - the real to clone. use aquire instance instead for reduced garbage (and return the instance afterwards)
Method Detail

aquireInstance

public static Vector3 aquireInstance(float x,
                                     float y,
                                     float z)
returns an initialized Vector3. Release the instance when the calling code no longer requires the vector3.

Returns:

aquireDirtyInstance

public static Vector3 aquireDirtyInstance()
returns a Vector3. The initial state is unspecified, so use in code where the contents of the vector are overwritten. Release the instance when the calling code no longer requires the vector3.


aquireInstance

public static Vector3 aquireInstance()
returns a zeroed Vector3. Release the instance when the calling code no longer requires the vector3.


aquireInstance

public static Vector3 aquireInstance(Vector3 values)
returns a Vector3 initialized to the first three parameters of the passed in vector3. Release the instance when the calling code no longer requires the vector3.


aquireInstance

public static Vector3 aquireInstance(Real values)
returns a Vector3 initialized to the first three parameters of the passed in Real. Release the instance when the calling code no longer requires the vector3.


releaseInstance

public static void releaseInstance(Vector3 instance)
releases the instance of the Vector3 back into an object pool.

Parameters:
instance -

getX

public float getX()

getY

public float getY()

getZ

public float getZ()

set

public void set(float x,
                float y,
                float z)

set

public void set(Vector3 v)

setX

public void setX(float x)

setY

public void setY(float y)

setZ

public void setZ(float z)

add

public void add(float x,
                float y,
                float z)

add

public Vector3 add(Vector3 v,
                   Vector3 result)
Returns:
result = this + v

sub

public void sub(float x,
                float y,
                float z)

cross

public Vector3 cross(Vector3 v)
does not modify this, creates a new vector and returns it

Parameters:
v -
Returns:

cross

public Vector3 cross(Vector3 v,
                     Vector3 result)
garbageless cross product of this X v = result result is overwitten

Parameters:
v -
result -
Returns:

cross

public void cross(Vector3 v,
                  RealPointer result)

cosAngle

public float cosAngle(Vector3 other)
this = a other = b computes the cos of the angle between the two vectors: cos(theta) = a.dot(b)/(|a||b|)

Returns:
cos(theta)

bar

public void bar(Matrix3 result)
if this is a returns abar such that abar * b = a cross b abar = [0 -a3 a2 a3 0 -a1 -a2 a1 0 ] as refered to in the ODE joint documentation "A cross product between two vectors in 3d space can be rewritten in terms of pure matrix multiplication as the product of a Skew-symmetric matrix and a vector" from Wikipedia

Parameters:
result -

dist

public float dist(Vector3 o)
calculates the distance of this Vector and o.

Parameters:
o - the Vector3, to calculate the distance to.
Returns:
the distance

dist2D

public float dist2D(Vector3 o)
Calculates a distance without using the z information


distSquared

public float distSquared(Vector3 o)
calculates the squared distance of this Vector and o. This calculation is faster than dist(Vector3), so it should be used, if distances get only compared.

Parameters:
o - the Vector3, to calculate the distance to.
Returns:
the squared distance

norm

public float norm()
Overrides:
norm in class Real
Returns:
sqrt(x^2 + y^2 + z^2)

min

public float min()
returns the minumum value among the components

Overrides:
min in class Real
Returns:

max

public float max()
returns the maximum value among the components

Overrides:
max in class Real
Returns:

mean

public float mean()

var

public float var()

constructPlaneSpace

public void constructPlaneSpace(Vector3 p,
                                Vector3 q)
given a unit length "normal" vector n, generate vectors p and q vectors that are an orthonormal basis for the plane space perpendicular to n. i.e. this makes p,q such that n,p,q are all perpendicular to each other. q will equal n x p. if n is not unit length then p will be unit length but q wont be. does it work? I don't know (it should)


planeVectorAngle

public static float planeVectorAngle(Vector3 planeNormal,
                                     Vector3 line)
returns the angle between a plane and a line from:- n.b=|n||b|sin(theta)

Parameters:
planeNormal -
line -
Returns:

planePlaneAngle

public static float planePlaneAngle(Real normal1,
                                    Real normal2)
returns the angle between a plane and another plane n1.n2=|n1||n2|cos(theta) note this function assumes the input normals ARE nomalized (works with hyperplanes)

Returns:

planePlaneCosAngle

public static float planePlaneCosAngle(Vector3 normal1,
                                       Vector3 normal2)

toString

public java.lang.String toString()
Overrides:
toString in class Real

randomVector

public static Vector3 randomVector()
returns a random vector with components uniformly distruted between 0-1

Returns:

epsilonEquals

public static boolean epsilonEquals(Vector3 a,
                                    Vector3 b,
                                    float e)
tests if two vectors are equal to within the given tolerance

Parameters:
e - tolerance in equality
Returns: