Package cnuphys.swim.util
Class VectorSupport
java.lang.Object
cnuphys.swim.util.VectorSupport
Static classes for treating arrays of doubles as 2D or 3D vectors
- Author:
- heddle
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic doubleangleBetween(double[] v1, double[] v2) Get the angle between two vectorsstatic double[]createVector(double... comp) Create a vector as a double array from its componentsstatic double[]cross(double[] v1, double[] v2) Get the vector cross product.static double[]diff(double[] a, double[] b) The vector difference a - bstatic doubledot(double[] v1, double[] v2) Usual inner productstatic doublelength(double[] v) Get the magnitude of the vector.static doublelength(float[] v) Get the magnitude of the vector.static doublelengthSquared(double[] v) Get the square of the magnitude of the vector.static doublelengthSquared(float[] v) Get the square of the magnitude of the vector.static double[]project(double[] v, double[] a) Project one vector onto another vectorvoidscale(double[] v, double scaleFactor) Scale the vectorstatic voidset(double[] v, double... components) Set all the componentsstatic StringtoString(double[] v) Returns a string representation of the form: "(x,y,z)" using three decimals points.static StringtoString(double[] v, int numDec) Returns a string representation of the form: "(x,y,z)".static double[]unitVector(double[] v) Obtain a unit vector in the same direction as this vector
- 
Constructor Details- 
VectorSupportpublic VectorSupport()
 
- 
- 
Method Details- 
createVectorpublic static double[] createVector(double... comp) Create a vector as a double array from its components- Parameters:
- comp- an arbitrary number of components
- Returns:
- the vector
 
- 
lengthSquaredpublic static double lengthSquared(float[] v) Get the square of the magnitude of the vector.- Parameters:
- v- the vector (of any length)
- Returns:
- the square of the magnitude of the vector
 
- 
lengthSquaredpublic static double lengthSquared(double[] v) Get the square of the magnitude of the vector.- Parameters:
- v- the vector (of any length)
- Returns:
- the square of the magnitude of the vector
 
- 
lengthpublic static double length(float[] v) Get the magnitude of the vector.- Parameters:
- v- the vector (of any length)
- Returns:
- the magnitude of the vector
 
- 
lengthpublic static double length(double[] v) Get the magnitude of the vector.- Parameters:
- v- the vector (of any length)
- Returns:
- the magnitude of the vector
 
- 
setpublic static void set(double[] v, double... components) Set all the components- Parameters:
- v- the vector (of any length)
- components- the vector components. The number of entries should match the length of v.
 
- 
scalepublic void scale(double[] v, double scaleFactor) Scale the vector- Parameters:
- v- the vector
- scaleFactor- the scale factor
 
- 
toStringReturns a string representation of the form: "(x,y,z)".- Parameters:
- v- the vector (of any length)
- numDec- the number of decimal places for each coordinate.
- Returns:
- a String representation of the vector
 
- 
toStringReturns a string representation of the form: "(x,y,z)" using three decimals points.- Parameters:
- v- the vector (of any length)
- numDec- the number of decimal places for each coordinate.
- Returns:
- a String representation of the vector
 
- 
unitVectorpublic static double[] unitVector(double[] v) Obtain a unit vector in the same direction as this vector- Parameters:
- v- the vector (of any length)
- Returns:
- a unit vector in the same direction as this vector
 
- 
dotpublic static double dot(double[] v1, double[] v2) Usual inner product- Parameters:
- v1- one vector on any length
- v2- another vector of matching length
- Returns:
- the dot product
 
- 
crosspublic static double[] cross(double[] v1, double[] v2) Get the vector cross product. The vectors must match and be 2D or 3D. A 3D vector is return. For for two 2D inputs, the result look like- Parameters:
- v1- one vector
- v2- another vector
- Returns:
- the magnitude of the cross product
 
- 
angleBetweenpublic static double angleBetween(double[] v1, double[] v2) Get the angle between two vectors- Parameters:
- v1- one vector of any length (2 or 3)
- v2- another vector of matching length
- Returns:
- the angle between the vectors in degrees.
 
- 
projectpublic static double[] project(double[] v, double[] a) Project one vector onto another vector- Parameters:
- v- the vector being projected
- a- the vector defining the projection direction.
- Returns:
- the result of projecting v in the direction of a.
 
- 
diffpublic static double[] diff(double[] a, double[] b) The vector difference a - b- Parameters:
- a- one vector
- b- the vector being subtracted
- Returns:
- the difference a - b
 
 
-