org.haphazard.util
Class Vector3D

java.lang.Object
  extended byjava.awt.geom.Point2D
      extended byjava.awt.geom.Point2D.Double
          extended byorg.haphazard.util.Point3D
              extended byorg.haphazard.util.Vector3D
All Implemented Interfaces:
java.lang.Cloneable

public class Vector3D
extends Point3D

An ordinary mathematical Vector


Nested Class Summary
 
Nested classes inherited from class java.awt.geom.Point2D
java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Float
 
Field Summary
static Vector3D NULLVECTOR
           
 
Fields inherited from class org.haphazard.util.Point3D
z
 
Fields inherited from class java.awt.geom.Point2D.Double
x, y
 
Constructor Summary
Vector3D()
          Creates a new instance of Vector3D
Vector3D(double x, double y, double z)
          Creates a new Vector3D with specified coordinates
Vector3D(Point3D point)
          Creates a vector from a point
Vector3D(Point3D origin, Point3D destination)
          Creates a vector from origin to destination
 
Method Summary
 Vector3D cross(Vector3D vector)
          Takes the cross product of two vectors
 double dot(Vector3D vector)
          Calculates the dot product of two vectors
 double getLength()
          Gets the length of this vector
 Vector3D projectOn(Vector3D vector)
          Projects this vector onto another vector
 void setLength(double length)
          Sets the length of this vector
 void setVector(Point3D origin, Point3D destination)
          Creates a vector from origin to destination
 void setVector(Vector3D vector)
          Sets this vector to be equal to another vector
 
Methods inherited from class org.haphazard.util.Point3D
add, add, clone, distance, equals, equals, getZ, setLocation, toString
 
Methods inherited from class java.awt.geom.Point2D.Double
getX, getY, setLocation
 
Methods inherited from class java.awt.geom.Point2D
distance, distance, distance, distanceSq, distanceSq, distanceSq, equals, hashCode, setLocation
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NULLVECTOR

public static final Vector3D NULLVECTOR
Constructor Detail

Vector3D

public Vector3D()
Creates a new instance of Vector3D


Vector3D

public Vector3D(Point3D point)
Creates a vector from a point

Parameters:
point - The point to create from

Vector3D

public Vector3D(Point3D origin,
                Point3D destination)
Creates a vector from origin to destination

Parameters:
origin - The origin of the vector
destination - The destination of the vector

Vector3D

public Vector3D(double x,
                double y,
                double z)
Creates a new Vector3D with specified coordinates

Parameters:
x - The x-coordinate
y - The y-coordinate
z - The z-coordinate
Method Detail

setVector

public void setVector(Point3D origin,
                      Point3D destination)
Creates a vector from origin to destination

Parameters:
origin - The origin of the vector
destination - The destination of the vector

setVector

public void setVector(Vector3D vector)
Sets this vector to be equal to another vector

Parameters:
vector - The vector to set this vector to

getLength

public double getLength()
Gets the length of this vector

Returns:
The length of the vector

setLength

public void setLength(double length)
Sets the length of this vector

Parameters:
length - The length to set

projectOn

public Vector3D projectOn(Vector3D vector)
Projects this vector onto another vector

Parameters:
vector - The vector to project this vector on
Returns:
The projection in a new vector

dot

public double dot(Vector3D vector)
Calculates the dot product of two vectors

Parameters:
vector - The vector to dot with
Returns:
The dot product of the vectors

cross

public Vector3D cross(Vector3D vector)
Takes the cross product of two vectors

Parameters:
vector - The vector to cross with
Returns:
A new vector with the result