pamMaths
Class PamVector

java.lang.Object
  extended by pamMaths.PamVector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class PamVector
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Author:
Doug Gillespie Vector calculations for spatial orientation.
All vectors have three elements for x,y,z.
Package includes basic vector calculations, mostly copied from Stephenson 1961
See Also:
Serialized Form

Field Summary
private static PamVector[] cartesianAxes
           
private static long serialVersionUID
           
protected  double[] vector
           
private static PamVector xAxis
           
private static PamVector yAxis
           
private static PamVector zAxis
           
 
Constructor Summary
PamVector()
           
PamVector(double[] vector)
           
PamVector(double x, double y, double z)
           
PamVector(PamVector vector)
           
 
Method Summary
 double absAngle(PamVector vec)
          Calculates the smallest angle between two vectors (0 <= angle < pi/2);
static PamVector add(PamVector... pamVectors)
          Add any number of vectors together.
 PamVector add(PamVector vec)
          Add another vector to this vector and return the result in a new Vector
static PamVector addQuadrature(PamVector... pamVectors)
          Add any number of vectors together in quadrature.
 double angle(PamVector vec)
          Calculate the angle between two vectors
static Jama.Matrix arrayToMatrix(PamVector[] pamVectors)
          convert a series of vectors into a Matrix
 PamVector clone()
           
 double dist(PamVector vec)
           
 double distSquared(PamVector vec)
           
 double dotProd(PamVector vec)
           
 boolean equals(PamVector vec)
           
static PamVector getCartesianAxes(int iAxis)
           
 double getElement(int iElement)
          Get a single vector element
 int getPrincipleAxis()
           
 PamVector getUnitVector()
          Get the unit vector, or if the vector is zero, return the zero vector (0,0,0).
 double[] getVector()
           
static PamVector[] getVectorPairs(PamVector[] vectors)
          Create a set of vector pairs, which are vectors between all the vectors in the input argument
static PamVector getXAxis()
           
static PamVector getYAxis()
           
static PamVector getZAxis()
           
 boolean isInLine(PamVector vec)
          Test to see whether two vectors lie in a perfect line
 boolean isParallel(PamVector vec)
          Tests to see whether two vectors are parallel
 double norm()
           
 double normSquared()
           
 PamVector rotate(Jama.Matrix rotationMatrix)
          Rotate the vector by a matrix.
 void setElement(int iElement, double val)
          Set a single vector element
 void setVector(double[] vector)
           
 PamVector sub(PamVector vec)
          Subtract another vector from this vector and return the result in a new Vector
 double sumComponentsSquared(PamVector vec)
          A bit like a dot product, but the three components are added in quadrature.
 PamVector times(double scalar)
          Multiply a vector by a scalar
 java.lang.String toString()
           
 double tripleDotProduct(PamVector v1, PamVector v2)
          Calculate the triple product of this with v1 and v2
 PamVector vecProd(PamVector vec)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

vector

protected double[] vector

xAxis

private static final PamVector xAxis

yAxis

private static final PamVector yAxis

zAxis

private static final PamVector zAxis

cartesianAxes

private static final PamVector[] cartesianAxes
Constructor Detail

PamVector

public PamVector(double[] vector)

PamVector

public PamVector(double x,
                 double y,
                 double z)

PamVector

public PamVector(PamVector vector)

PamVector

public PamVector()
Method Detail

clone

public PamVector clone()
Overrides:
clone in class java.lang.Object

normSquared

public double normSquared()
Returns:
The magnitude squared of the vector

equals

public boolean equals(PamVector vec)
Parameters:
vec - other vector to compare.
Returns:
true if the vectors are equal in all dimensions

sub

public PamVector sub(PamVector vec)
Subtract another vector from this vector and return the result in a new Vector

Parameters:
vec - vector to subtract
Returns:
new vector

add

public PamVector add(PamVector vec)
Add another vector to this vector and return the result in a new Vector

Parameters:
vec - vector to add
Returns:
new vector

add

public static PamVector add(PamVector... pamVectors)
Add any number of vectors together.

Parameters:
pamVectors - list of vectors
Returns:
sum of all vectors.

addQuadrature

public static PamVector addQuadrature(PamVector... pamVectors)
Add any number of vectors together in quadrature.

Parameters:
pamVectors - list of vectors
Returns:
sum of all vectors.

arrayToMatrix

public static Jama.Matrix arrayToMatrix(PamVector[] pamVectors)
convert a series of vectors into a Matrix

Parameters:
pamVectors - array of vectors
Returns:
Jama Matrix

rotate

public PamVector rotate(Jama.Matrix rotationMatrix)
Rotate the vector by a matrix.

Parameters:
rotationMatrix - rotation matrix
Returns:
rotated vector.

times

public PamVector times(double scalar)
Multiply a vector by a scalar

Parameters:
scalar - scalar value
Returns:
new vector

getUnitVector

public PamVector getUnitVector()
Get the unit vector, or if the vector is zero, return the zero vector (0,0,0).

Returns:
the unit vector

angle

public double angle(PamVector vec)
Calculate the angle between two vectors

Parameters:
vec - other vector
Returns:
angle in radians between 0 and pi

absAngle

public double absAngle(PamVector vec)
Calculates the smallest angle between two vectors (0 <= angle < pi/2);

Parameters:
vec - other vector
Returns:
angle between two vectors (0 < angle < pi/2)

distSquared

public double distSquared(PamVector vec)
Parameters:
vec - other vector
Returns:
square of the distance between two vectors

dist

public double dist(PamVector vec)
Parameters:
vec - other vector
Returns:
the distance between two vectors

norm

public double norm()
Returns:
the magnitude of the vector

dotProd

public double dotProd(PamVector vec)
Parameters:
vec - a PamVector
Returns:
the dot product of this and vec

sumComponentsSquared

public double sumComponentsSquared(PamVector vec)
A bit like a dot product, but the three components are added in quadrature. This is used to estimate errors along a particular vector component.

Parameters:
vec - a Pam Vector
Returns:
sum of components in each direction, added in quadrature.

vecProd

public PamVector vecProd(PamVector vec)
Parameters:
vec -
Returns:
vector product of this and vec.

tripleDotProduct

public double tripleDotProduct(PamVector v1,
                               PamVector v2)
Calculate the triple product of this with v1 and v2

Parameters:
v1 - other vector
v2 - other vector
Returns:
triple produce this.(v1^v2);

isParallel

public boolean isParallel(PamVector vec)
Tests to see whether two vectors are parallel

Parameters:
vec - other vector
Returns:
true if parallel to within 1/1000 radian.

isInLine

public boolean isInLine(PamVector vec)
Test to see whether two vectors lie in a perfect line

Parameters:
vec - other vector
Returns:
true if they line up perfectly

getVector

public double[] getVector()

setVector

public void setVector(double[] vector)

getElement

public double getElement(int iElement)
Get a single vector element

Parameters:
iElement - element index
Returns:
value

setElement

public void setElement(int iElement,
                       double val)
Set a single vector element

Parameters:
iElement - element index
val - element value

getXAxis

public static PamVector getXAxis()

getYAxis

public static PamVector getYAxis()

getZAxis

public static PamVector getZAxis()

getCartesianAxes

public static PamVector getCartesianAxes(int iAxis)
Parameters:
iAxis -
Returns:
a unit vector along a Cartesian axis (x,y,z)

getVectorPairs

public static PamVector[] getVectorPairs(PamVector[] vectors)
Create a set of vector pairs, which are vectors between all the vectors in the input argument

Parameters:
vectors - array of vectors
Returns:
array of vectors between all the input vectors (creates n*(n-1)/2 new vectors)

getPrincipleAxis

public int getPrincipleAxis()
Returns:
the axis to which the vector is closest.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object