Class Vector3D

java.lang.Object
  |
  +--Vector3D

public class Vector3D
extends java.lang.Object

A class to represent a vector or a point in 3D system


Field Summary
 double[] v
          double v[3]
purpose : store the values of the coordinates
 
Constructor Summary
Vector3D()
          Default constructor
purpose : initialize the vector to (0.0, 0.0, 0.0)
Vector3D(double x, double y, double z)
          Constructor
purpose : initialize the vector to (x, y, z)
Vector3D(Vector3D x)
          Copy constructor
purpose : initialize the vector to the input Vector3D x)
 
Method Summary
static Vector3D cross(Vector3D a, Vector3D b)
          purpose : cross product
static double dot(Vector3D a, Vector3D b)
          purpose : dot product
 double length()
          purpose : length of the vector
static Vector3D minus(Vector3D a, Vector3D b)
          purpose : subtract one vector by another vector
static Vector3D multi(int factor, Vector3D a)
          purpose : multiply a number with a vector
 double normalize()
          purpose : normalizing the vector
static Vector3D plus(Vector3D a, Vector3D b)
          purpose add two vectors together
 void round(int decPlace)
          purpose : round off the coordinates of the vector to some decimal places
 java.lang.String toString()
          purpose : convert the vector to String
static Vector3D transformPoint(Matrix m, Vector3D p)
          purpose : multiply a matrix with a vector
static Vector3D transformPointQ(Matrix m, Vector3D p)
          purpose : multiply a matrix with a vector, assume last row of the matrix is 0,0,0,1
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

v

public double[] v
double v[3]
purpose : store the values of the coordinates
Constructor Detail

Vector3D

public Vector3D()
Default constructor
purpose : initialize the vector to (0.0, 0.0, 0.0)

Vector3D

public Vector3D(double x,
                double y,
                double z)
Constructor
purpose : initialize the vector to (x, y, z)
Parameters:
x - x-coordinate
y - y-coordinate
z - z-coordinate

Vector3D

public Vector3D(Vector3D x)
Copy constructor
purpose : initialize the vector to the input Vector3D x)
Method Detail

plus

public static Vector3D plus(Vector3D a,
                            Vector3D b)
purpose add two vectors together
Parameters:
a - first Vector3D
b - second Vector3D
Returns:
a new copy of a + b

minus

public static Vector3D minus(Vector3D a,
                             Vector3D b)
purpose : subtract one vector by another vector
Parameters:
a - first Vector3D
b - second Vector3D
Returns:
a new copy of a - b

multi

public static Vector3D multi(int factor,
                             Vector3D a)
purpose : multiply a number with a vector
Parameters:
factor - integer
a - Vector3D
Returns:
a new copy of factor * a

dot

public static double dot(Vector3D a,
                         Vector3D b)
purpose : dot product
Parameters:
a - first Vector3D
b - second Vector3D
Returns:
a(.)b

cross

public static Vector3D cross(Vector3D a,
                             Vector3D b)
purpose : cross product
Parameters:
a - first Vector3D
b - second Vector3D
Returns:
a(x)b

length

public double length()
purpose : length of the vector
Returns:
length of the Vector3D

normalize

public double normalize()
purpose : normalizing the vector
Returns:
length of the original Vector3D

transformPointQ

public static Vector3D transformPointQ(Matrix m,
                                       Vector3D p)
purpose : multiply a matrix with a vector, assume last row of the matrix is 0,0,0,1
Parameters:
m - Matrix
p - Vector3D
Returns:
a new copy of m x p

transformPoint

public static Vector3D transformPoint(Matrix m,
                                      Vector3D p)
purpose : multiply a matrix with a vector
Parameters:
m - Matrix
p - Vector3D
Returns:
a new copy of m x p

toString

public java.lang.String toString()
purpose : convert the vector to String
Returns:
the vector in String format
Overrides:
toString in class java.lang.Object

round

public void round(int decPlace)
purpose : round off the coordinates of the vector to some decimal places
Parameters:
decPlace - number of decimal places