pamMaths

## Class PamVector

• java.lang.Object
• 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
Serialized Form
• ### Constructor Summary

Constructors
Constructor and Description
`PamVector()`
`PamVector(double[] vector)`
```PamVector(double x, double y, double z)```
`PamVector(PamVector vector)`
• ### Method Summary

Methods
Modifier and Type Method and Description
`double` `absAngle(PamVector vec)`
Calculates the smallest angle between two vectors (0 <= angle < pi/2);
`PamVector` `absElements()`
Make all elements within the vector positive.
`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)`
`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` ```fromHeadAndSlant(double heading, double slantAngle)```
Create a unit vector based on a heading (degrees from North) and a slant angle 90 up up, -90 = down
`static PamVector` `getCartesianAxes(int iAxis)`
`double` `getElement(int iElement)`
Get a single vector element
`int` `getPrincipleAxis()`
`static Jama.Matrix` `getRotMatrixX(double angle)`
Get a matrix which rotates a vector around the x axis.
`static Jama.Matrix` `getRotMatrixY(double angle)`
Get a matrix which rotates a vector around the y axis.
`static Jama.Matrix` `getRotMatrixZ(double angle)`
Get a matrix which rotates a vector around the z axis.
`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` `normalise()`
Normalise a vector so it has a magnitue of 1.
`double` `normSquared()`
`PamVector` `rotate(double rotationAngle)`
Rotate a vector anti-clockwise by an angle.
`PamVector` `rotate(Jama.Matrix rotationMatrix)`
Rotate the vector by a matrix.
`PamVector` `rotate(PamVector rotationVector)`
Rotate a vector using another vector.
`static PamVector` ```rotateVector(PamVector vector, double[] angle)```
Rotates a vector by the Euler angles.
`static PamVector` ```rotateVector(PamVector vector, PamQuaternion orientation)```
Rotates a vector by a Quaternion .
`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)`
`static double[]` `vectorsToSurfaceBearings(PamVector[] vectors)`
Convert an array of Cartesian vectors into bearings from North.
`static double` `vectorToSurfaceBearing(PamVector vector)`
Convert a Cartesian vector into a bearing from North.
`double` `xyDistance()`
• ### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### 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

```public static PamVector fromHeadAndSlant(double heading,
double slantAngle)```
Create a unit vector based on a heading (degrees from North) and a slant angle 90 up up, -90 = down
Parameters:
`heading` - heading from North in degrees
`slantAngle` - slant angle from the horizontal.
Returns:
Unit 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

`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

`public static PamVector add(PamVector... pamVectors)`
Add any number of vectors together.
Parameters:
`pamVectors` - list of vectors
Returns:
sum of all vectors.

`public static PamVector addQuadrature(PamVector... pamVectors)`
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.
• #### rotate

`public PamVector rotate(double rotationAngle)`
Rotate a vector anti-clockwise by an angle.
the third dimension of the matrix remains untouched. The first two dimensions will rotate anti clockwise by the given angle.
Parameters:
`rotationAngle` - rotation angle in radians.
Returns:
new rotated vector.
• #### rotate

`public PamVector rotate(PamVector rotationVector)`
Rotate a vector using another vector. This is basically a surface rotation in the x,y plane using the same functionality as the rotate(double rotationAngle) function, but the input are already in vector form
Parameters:
`rotationVector` -
Returns:
• #### 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:
• #### 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
• #### xyDistance

`public double xyDistance()`
Returns:
the magnitude of the xy components of the vector - generally the magnitude across the sea surface if the vector is in normal coordinates.
• #### 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`
• #### vectorsToSurfaceBearings

`public static double[] vectorsToSurfaceBearings(PamVector[] vectors)`
Convert an array of Cartesian vectors into bearings from North. Only the x and y parts of the vector are used in this and to be a pain, the bearing is left in radians !
Parameters:
`vectors` - Cartesian vector (need not be a unit vector)
Returns:
clockwise bearings from north in radians
• #### vectorToSurfaceBearing

`public static double vectorToSurfaceBearing(PamVector vector)`
Convert a Cartesian vector into a bearing from North. Only the x and y parts of the vector are used in this and to be a pain, the bearing is left in radians !
Parameters:
`vector` - Cartesian vector (need not be a unit vector)
Returns:
clockwise bearing from north in radians
• #### normalise

`public double normalise()`
Normalise a vector so it has a magnitue of 1. if the vector has magnitude 0, it is left with this magnitude and 0 is returned.
Returns:
0 if the vector had zero magnitude, a otherwise.
• #### absElements

`public PamVector absElements()`
Make all elements within the vector positive. This can be used to simplify symmetric problems.
Returns:
The vector but with all elements made positive.
• #### getRotMatrixX

`public static Jama.Matrix getRotMatrixX(double angle)`
Get a matrix which rotates a vector around the x axis.
Parameters:
`angle-` - angle to rotate around the x axis in RADIANS.
Returns:
x axis rotation matrix.
• #### getRotMatrixY

`public static Jama.Matrix getRotMatrixY(double angle)`
Get a matrix which rotates a vector around the y axis.
Parameters:
`angle-` - angle to rotate around the y axis in RADIANS.
Returns:
y axis rotation matrix.
• #### getRotMatrixZ

`public static Jama.Matrix getRotMatrixZ(double angle)`
Get a matrix which rotates a vector around the z axis.
Parameters:
`angle-` - angle to rotate around the z axis in RADIANS.
Returns:
z axis rotation matrix.
• #### rotateVector

```public static PamVector rotateVector(PamVector vector,
PamQuaternion orientation)```
Rotates a vector by a Quaternion .
Parameters:
`PamQuaternion` - - orientation
Returns:
vector rotated by the quaternion.
• #### rotateVector

```public static PamVector rotateVector(PamVector vector,
double[] angle)```
Rotates a vector by the Euler angles.
Parameters:
`heading-` - heading in RADIANS. Here we use 0 to 360 for heading.
`pitch-` - pitch in RADIANS. Use the standard PAMGUARD convention 90=-g; 0=0 -90=g (g =direction of gravitational field)
`tilt-` - tilt in RADIANS. Use the standard PAMGUARD convention
Returns:
vector rotated by the Euler angles.