noope.core
Class Vector3D

java.lang.Object
  |
  +--noope.core.Vector3D
Direct Known Subclasses:
MutableVector3D

public class Vector3D
extends java.lang.Object

Manipulate a 3D cartesian vector. Note that objects of this class are immutable; i.e. they cannot be changed. To create mutable (i.e. changable) vectors, use the MutableVector3D class instead.

Version:
Modified by James Kermode, 22-Mar-2001, again by Paul Evans, 28-Mar-2001
Author:
Paul Evans

Field Summary
static Vector3D ex
          Unit vector in x direction
static Vector3D ey
          Unit vector in y direction
static Vector3D ez
          Unit vector in z direction
protected  double x
          x component
protected  double y
          y component
protected  double z
          z component
 
Constructor Summary
Vector3D()
          Construct a Vector3D and initialise it to (0, 0, 0).
Vector3D(double new_x, double new_y, double new_z)
          Construct a Vector3D and initialise it to (new_x, new_y, new_z).
Vector3D(java.lang.String s)
          Construct a new Vector3D by parsing a string.
Vector3D(Vector3D v)
          Construct a Vector3D equal to v.
 
Method Summary
 Vector3D add(Vector3D v)
          Return a new Vector3D representing the vector sum of this Vector3D and the Vector3D v.
 Vector3D crossProduct(Vector3D v)
          Return the cross product of this Vector3D and the Vector3D v.
 double dotProduct(Vector3D v)
          Return the scalar product of this Vector3D and the Vector3D v.
 boolean equals(java.lang.Object o)
          Compare a Vector3D and an Object.
 boolean equals(Vector3D v)
          Compare two Vector3D objects.
 double getModulus()
          Return the modulus of this Vector3D.
 double getModulusSquared()
          Return the square modulus of this Vector3D.
 Vector3D getUnitVector()
          Return a new Vector3D representing a unit vector in the direction of this Vector3D.
 double getX()
          Return the x component of this Vector3D
 double getY()
          Return the y component of this Vector3D
 double getZ()
          Return the z component of this Vector3D
 int hashCode()
          Hash this Vector3D to an integer.
 Vector3D multScalar(double d)
          Return a new Vector3D which is result of multiplying each component of this Vector3D by the scalar d.
 Vector3D negative()
          Return a new Vector3D in the opposite direction to this Vector3D.
 Vector3D subtract(Vector3D v)
          Return a new Vector3D representing the vector difference between this Vector3D and the Vector3D v.
 java.lang.String toString()
          Return a string representation of this Vector3D formatted as (x y z)
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

x

protected double x
x component

y

protected double y
y component

z

protected double z
z component

ex

public static final Vector3D ex
Unit vector in x direction

ey

public static final Vector3D ey
Unit vector in y direction

ez

public static final Vector3D ez
Unit vector in z direction
Constructor Detail

Vector3D

public Vector3D()
Construct a Vector3D and initialise it to (0, 0, 0).

Vector3D

public Vector3D(double new_x,
                double new_y,
                double new_z)
Construct a Vector3D and initialise it to (new_x, new_y, new_z).
Parameters:
new_x - x component
new_y - y component
new_z - z component

Vector3D

public Vector3D(Vector3D v)
Construct a Vector3D equal to v.
Parameters:
v - the vector to copy from

Vector3D

public Vector3D(java.lang.String s)
         throws java.text.ParseException
Construct a new Vector3D by parsing a string. Parses the String s for a Vector3D given in the form (x, y, z) where x, y and z are doubles. All whitespace is stripped and "0" is recognised to mean the zero vector (0, 0, 0). Originially written by Miklos Reiter, relocated and minor modifications by James Kermode
Parameters:
s - the string to parse
Throws:
java.text.ParseException - if there was an error parsing the string
Method Detail

hashCode

public int hashCode()
Hash this Vector3D to an integer.
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Compare a Vector3D and an Object.
Overrides:
equals in class java.lang.Object
See Also:
equals(Vector3D)

equals

public boolean equals(Vector3D v)
Compare two Vector3D objects.
Returns:
true if the x, y, and z components of the two vectors are equal, false otherwise.

getX

public double getX()
Return the x component of this Vector3D

getY

public double getY()
Return the y component of this Vector3D

getZ

public double getZ()
Return the z component of this Vector3D

getModulusSquared

public double getModulusSquared()
Return the square modulus of this Vector3D. This is equal to (x*x) + (y*y) + (z*z).

getModulus

public double getModulus()
Return the modulus of this Vector3D. This is equal to the sqrt((x*x) + (y*y) + (z*z)).

getUnitVector

public Vector3D getUnitVector()
Return a new Vector3D representing a unit vector in the direction of this Vector3D. This is found by dividing all components by the magnitude.

negative

public Vector3D negative()
Return a new Vector3D in the opposite direction to this Vector3D.

multScalar

public Vector3D multScalar(double d)
Return a new Vector3D which is result of multiplying each component of this Vector3D by the scalar d.

add

public Vector3D add(Vector3D v)
Return a new Vector3D representing the vector sum of this Vector3D and the Vector3D v.

subtract

public Vector3D subtract(Vector3D v)
Return a new Vector3D representing the vector difference between this Vector3D and the Vector3D v.

dotProduct

public double dotProduct(Vector3D v)
Return the scalar product of this Vector3D and the Vector3D v. This is a scalar equal to the product of the magnitudes of the two vectors times the cosine of the angle between them, and is also equal to the sum of the products of corresponding components.

crossProduct

public Vector3D crossProduct(Vector3D v)
Return the cross product of this Vector3D and the Vector3D v. This is a vector normal to the plan containing the two vectors, with a magnitude equal to the product of the magnitudes of the two vectors times the sine of the angle between them, and is also equal to the determinent of the cartesian unit vectors and the components of the two vectors in row form.

toString

public java.lang.String toString()
Return a string representation of this Vector3D formatted as (x y z)
Overrides:
toString in class java.lang.Object