org.vizzini.math
Class Vector

java.lang.Object
  extended by org.vizzini.math.Vector
All Implemented Interfaces:
Serializable

public class Vector
extends Object
implements Serializable

Provides a vector. Instances of this class are immutable.

Since:
v0.1
Version:
v0.3
Author:
Jeffrey M. Thompson
See Also:
Serialized Form

Field Summary
static Vector X_AXIS
          X axis.
static Vector Y_AXIS
          Y axis.
static Vector Z_AXIS
          Z axis.
static Vector ZERO
          Zero vector.
 
Constructor Summary
Vector()
          Construct this object.
Vector(double rightAscension, double declination)
          Construct a unit vector pointing in the direction specified by the given angles.
Vector(double x, double y, double z)
          Construct this object with the given parameters.
Vector(double t, Vector v0, Vector v1)
          Construct a vector from v0 to v1 at t.
 
Method Summary
 Vector add(Vector v)
          Return a new Vector which is the sum of this and the given vector..
 double angle(Vector v)
          Return the angle between this vector and the given vector, in radians.
 Object clone()
          Return a clone of this instance.
 Vector cross(Vector v)
          Return a new vector which is the cross between the given vectors.
 Vector cross(Vector v, boolean force)
          Return a new vector which is the cross between this and the given vector.
 Vector divide(double m)
          Return a new vector divided by the given scalar.
 double dot(Vector v)
          Return the vector dot product.
 boolean equals(Object object)
          Return true if this vector equals the given object.
 boolean equals(Object object, double delta)
          Return true if this vector equals the given object.
 double getDeclination()
          Return the declination angle of this vector in radians.
 double getMagnitude()
          Return the magnitude of this vector.
 double getRightAscension()
          Return the right ascension angle of this vector in radians.
 double getX()
          Return the X component.
 double getY()
          Return the Y component.
 double getZ()
          Return the Z component.
 int hashCode()
          Return a hash code.
 Vector multiply(double m)
          Return a new vector multiplied by the given scalar.
static Vector parseVector(String vectorString)
          Parse the given string into a Vector.
 Vector subtract(Vector v)
          Return a new Vector which is this minus the given vector..
 String toAnglesString()
          Return a string representation of this object as right ascension and declination angles..
 double[] toArray()
          Return this vector's components as an array.
 String toString()
          Return a string representation of this object.
 Vector unit()
          Return a new vector which is a unit vector of this.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ZERO

public static final Vector ZERO
Zero vector.


X_AXIS

public static final Vector X_AXIS
X axis.


Y_AXIS

public static final Vector Y_AXIS
Y axis.


Z_AXIS

public static final Vector Z_AXIS
Z axis.

Constructor Detail

Vector

public Vector(double rightAscension,
              double declination)
Construct a unit vector pointing in the direction specified by the given angles.

Parameters:
rightAscension - Right ascension angle in radians.
declination - Declination angle in radians.
Since:
v0.1

Vector

public Vector(double x,
              double y,
              double z)
Construct this object with the given parameters.

Since:
v0.1

Vector

public Vector(double t,
              Vector v0,
              Vector v1)
Construct a vector from v0 to v1 at t. If t == 0.0, this vector equals v0; if t == 1.0, this vector equals v1.

Parameters:
t - Parameter from v0 to v1.
v0 - Start vector.
v1 - End vector.
Since:
v0.1

Vector

public Vector()
Construct this object.

Since:
v0.1
Method Detail

parseVector

public static Vector parseVector(String vectorString)
Parse the given string into a Vector.

Since:
v0.1

add

public Vector add(Vector v)
Return a new Vector which is the sum of this and the given vector..

Since:
v0.1

angle

public double angle(Vector v)
Return the angle between this vector and the given vector, in radians. The returned angle is always positive.

Since:
v0.1

clone

public Object clone()
Return a clone of this instance.

Overrides:
clone in class Object
Since:
v0.1

cross

public Vector cross(Vector v)
Return a new vector which is the cross between the given vectors.

Since:
v0.1

cross

public Vector cross(Vector v,
                    boolean force)
Return a new vector which is the cross between this and the given vector.

Parameters:
v - Vector with which to cross.
force - Flag indicating whether to force the algorithm to return a valid vector if this and v are 180 degrees apart.
Since:
v0.1

divide

public Vector divide(double m)
Return a new vector divided by the given scalar.

Since:
v0.1

dot

public double dot(Vector v)
Return the vector dot product.

Since:
v0.1

equals

public boolean equals(Object object)
Return true if this vector equals the given object.

Overrides:
equals in class Object
Parameters:
object - Object to compare.
Since:
v0.1

equals

public boolean equals(Object object,
                      double delta)
Return true if this vector equals the given object.

Parameters:
object - Object to compare.
delta - Allowable difference in coordinates.
Since:
v0.1

getDeclination

public double getDeclination()
Return the declination angle of this vector in radians. This angle is in [-pi/2,+pi/2], with +pi/2 along the +Z axis.

Since:
v0.1

getMagnitude

public double getMagnitude()
Return the magnitude of this vector.

Since:
v0.1

getRightAscension

public double getRightAscension()
Return the right ascension angle of this vector in radians. This angle is in [0,2pi). A vector with right ascension of zero (and declination of zero) lies along the +X axis.

Since:
v0.1

getX

public double getX()
Return the X component.

Since:
v0.1

getY

public double getY()
Return the Y component.

Since:
v0.1

getZ

public double getZ()
Return the Z component.

Since:
v0.1

hashCode

public int hashCode()
Return a hash code.

Overrides:
hashCode in class Object
Since:
v0.1

multiply

public Vector multiply(double m)
Return a new vector multiplied by the given scalar.

Since:
v0.1

subtract

public Vector subtract(Vector v)
Return a new Vector which is this minus the given vector..

Since:
v0.1

toAnglesString

public String toAnglesString()
Return a string representation of this object as right ascension and declination angles..

Since:
v0.1

toArray

public double[] toArray()
Return this vector's components as an array.

Since:
v0.1

toString

public String toString()
Return a string representation of this object.

Overrides:
toString in class Object
Since:
v0.1

unit

public Vector unit()
Return a new vector which is a unit vector of this.

Since:
v0.1


Copyright 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02