EigenMeat.EigenMaze
Class Vect3d

java.lang.Object
  extended byEigenMeat.EigenMaze.Vect3d

public class Vect3d
extends java.lang.Object

XYZ Vector class.


Field Summary
 float x
           
 float y
           
 float z
           
 
Constructor Summary
Vect3d()
          Default constructor for Vect3d.
Vect3d(double x, double y, double z)
          Constructor.
Vect3d(float x, float y, float z)
          Constructor.
Vect3d(Vect3d v)
          Copy constructor that allows you to copy another Vect3d object.
 
Method Summary
 void add(Vect3d add)
          Add a vector.
 void addm(Vect3d vector, float scalar)
          Helper function that multiplies a vector by a scalar before using it for addition.
 Vect3d cross(Vect3d v)
          Performs a cross product operation.
 void div(float scalar)
          Divide vector by a scalar.
 float dot(Vect3d v)
          Performs a dot product operation on the vector.
 boolean equals(Vect3d rhs)
           
 float getAngle(Vect3d v)
          Gets the angle between 2 vectors.
 float[] getArray()
           
static void getBounceVect(Vect3d vel, Vect3d normal, Vect3d result)
          Get the resulting vector after a bounce against a plane.
static Vect3d getClosestPointOnLine(Vect3d a, Vect3d b, Vect3d p)
          Get the closest point on the line between it and another point.
 float getDistance(Vect3d point)
           
static float getDistanceBetweenPoints(Vect3d a, Vect3d b)
          Get the distance between two points.
 float getX()
          Accessor method for X coordinate.
 float getY()
          Accessor method for Y coordinate.
 float getZ()
          Accessor method for Z coordinate.
 void invert()
          Inverts the vector.
 float length()
          Returns the vector length.
 void mult(float scalar)
          Multiply vector by a scalar.
 void mult(float scalar, Vect3d result)
          Multiply vector by a scalar and store the result in another vector.
 void normalize()
          Normalize the vector.
 void rotateY(float angle)
          Rotate vector around the Y Axis by an angle.
 void set(float x, float y, float z)
          Set method for XYZ coordinate.
 void set(Vect3d v)
          Sets XYZ coordinates using another Vect3d object.
 void sub(Vect3d s)
          Subtract the vector by another vector
 void sub(Vect3d s, Vect3d result)
          Subtract by a vector and store the results in another vector.
 void subm(Vect3d vector, float scalar)
          Helper function that multiplies a vector by a scalar before using it for subtraction
 java.lang.String toString()
          Method used to print the 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

Vect3d

public Vect3d()
Default constructor for Vect3d. Sets the vector to 0,0,0.


Vect3d

public Vect3d(float x,
              float y,
              float z)
Constructor. Allows you to set the XYZ of the vector.

Parameters:
x - x coordinate
y - y coordinate
z - z coordinate

Vect3d

public Vect3d(double x,
              double y,
              double z)
Constructor. Allows you to set the XYZ using double type variables. Mainly takes away the hassle of always appending "f" to the end of decimal numbers.

Parameters:
x - x coordinate
y - y coordinate
z - z coordinate

Vect3d

public Vect3d(Vect3d v)
Copy constructor that allows you to copy another Vect3d object.

Parameters:
v - Vect3d object to copy.
Method Detail

getX

public float getX()
Accessor method for X coordinate.


getY

public float getY()
Accessor method for Y coordinate.


getZ

public float getZ()
Accessor method for Z coordinate.


set

public void set(float x,
                float y,
                float z)
Set method for XYZ coordinate.

Parameters:
x - x coordinate
y - y coordinate
z - z coordinate

set

public void set(Vect3d v)
Sets XYZ coordinates using another Vect3d object.

Parameters:
v - Vect3d object to copy

invert

public void invert()
Inverts the vector.


length

public float length()
Returns the vector length.

Returns:
length of vector

normalize

public void normalize()
Normalize the vector. Changes the length to 1.


dot

public float dot(Vect3d v)
Performs a dot product operation on the vector.

Parameters:
v - The second vector to use for dot product operation
Returns:
the dot product

cross

public Vect3d cross(Vect3d v)
Performs a cross product operation.

Parameters:
v - The second Vect3d object to use for the cross product.
Returns:
a new Vect3d object representing the cross product.

getAngle

public float getAngle(Vect3d v)
Gets the angle between 2 vectors.

Parameters:
v - The second vector
Returns:
The angle (float)

mult

public void mult(float scalar)
Multiply vector by a scalar.

Parameters:
scalar - The number to multiply the vector with.

div

public void div(float scalar)
Divide vector by a scalar.

Parameters:
scalar - The number to divide the vector with.

mult

public void mult(float scalar,
                 Vect3d result)
Multiply vector by a scalar and store the result in another vector.

Parameters:
scalar - The number to multiply the vector with.
result - The vector the result is stored in.

sub

public void sub(Vect3d s)
Subtract the vector by another vector

Parameters:
s - The vector used to subtract with.

sub

public void sub(Vect3d s,
                Vect3d result)
Subtract by a vector and store the results in another vector.

Parameters:
s - The vector used to subtract with.
result - The vector the results are stored in.

add

public void add(Vect3d add)
Add a vector.

Parameters:
add - The vector used for addition.

addm

public void addm(Vect3d vector,
                 float scalar)
Helper function that multiplies a vector by a scalar before using it for addition.

Parameters:
vector - the Vector used for addition
scalar - scalar number to multiply vector before adding with it

subm

public void subm(Vect3d vector,
                 float scalar)
Helper function that multiplies a vector by a scalar before using it for subtraction

Parameters:
vector - vector to use for subtraction
scalar - the number to multiply the vector

rotateY

public void rotateY(float angle)
Rotate vector around the Y Axis by an angle.

Parameters:
angle - The angle to rotate the vector

equals

public boolean equals(Vect3d rhs)

getDistance

public float getDistance(Vect3d point)

getArray

public float[] getArray()

toString

public java.lang.String toString()
Method used to print the vector.

Returns:
the Vector in a formatted string

getBounceVect

public static void getBounceVect(Vect3d vel,
                                 Vect3d normal,
                                 Vect3d result)
Get the resulting vector after a bounce against a plane. Uses the formula: "R = 2*(-I dot N)*N + I" (N is the surface normal, I is the normalized direction of the original vector)

Parameters:
vel - the initial vector before the bounce
normal - the normal of the surface to bounce the vector around
result - the resulting bounced vector

getClosestPointOnLine

public static Vect3d getClosestPointOnLine(Vect3d a,
                                           Vect3d b,
                                           Vect3d p)
Get the closest point on the line between it and another point.

Parameters:
a - starting point of a line
b - end point of a line
p - a point
Returns:
a new vector representing the closest point on the line to point p

getDistanceBetweenPoints

public static float getDistanceBetweenPoints(Vect3d a,
                                             Vect3d b)
Get the distance between two points.

Parameters:
a - first point
b - second point
Returns:
the distance between the 2 points