Vectors (Mathematics) - singa-bio/singa GitHub Wiki
Vectors
Vectors are mathematical constructs that contain multiple values, referenced by their indices.
A vector is a Ring, MultiDimensional, Divisible, and Metrizable.
The primary implementation for Vectors is the RegularVector. Additionally Scalar, Vector2D, and Vector3D handle general properties and operations of one, two and three dimensional vectors.
Vector
With the various implemented methods you can get a lot of information about the vectors. For example:
Vector vector = new Vector2D(20,-5);
Now there are methods like getMagnitude, getElement or getDimension to retrieve elements from the vector.
vector.getMagnitude();
result: 20.615528128088304
Further, there are methods that use two Vectors. Calculations and comparisons can be performed. For example:
Vector vector1 = new Vector2D(20,-5);
Vector vector2 = new Vector2D(41,17);
Creates two vectors.
With the vectors you can perform simple arithmetic operations like add, substract, divide, and so on. Additionally, you can retrieve the angle, the dot product or the dyadic product of two vectors.
Examples:
double dotProduct = vector1.dotProduct(vector2);
Dot product: 715.0
double distance = vector1.distanceTo(vector2);
Distance between: 29.732137494637012
double angle = Math.toDegrees(vector1.angleTo(vector2));
Angle between: 37.061735476454515
Matrix dyadicProduct = vector1.dyadicProduct(vector2);
Dyadic Product:
800,00 340,00
-200,00 -85,00
Vectors
The class Vectors contains static utility methods to create and handle different vectors. The following table shows some methods an their function.
| Method | Function |
|---|---|
generateRandomVector3D |
Generates a random 3D vector (a similar method is also available for 2D vectors). |
getMedian |
Returns the median value for a given vector. |
getStandardDeviation |
Returns the standard deviation of all elements in the vector. |
getMaximalValueForIndex |
Compares all values of the given index for all given vectors and returns the largest value found (a similar method is also available for minimal value). |
getCentroid |
Computes the centroid of all vectors in the collection by summing them and dividing by the number of vectors in the collection. |
gramSchmidtProjection |
The projection for the (modified) Graham-Schmidt process. |