Java Utililty Methods Vector

List of utility methods to do Vector

Description

The list of methods to do Vector are organized into topic(s).

Method

Stringvector2string(int[] vector)
vectorstring
if (vector == null || vector.length == 0)
    return null;
String str = String.valueOf(vector[0]);
for (int i = 1; i < vector.length; i++) {
    str += " " + vector[i];
return str;
doublevector_dot(double[] vec1, double[] vec2)
vectodot
double sum = 0;
for (int i = 0; i < vec1.length && i < vec2.length; i++)
    sum += vec1[i] * vec2[i];
return sum;
doublevector_norm(double[] vec)
vectonorm
double sum = 0;
for (double v : vec)
    sum += v * v;
return Math.sqrt(sum);
double[]vector_sum(double[] v, double[] w)
vectosum
assert (v.length == w.length);
double[] r = new double[v.length];
for (int i = 0; i < v.length; i++)
    r[i] = v[i] + w[i];
return r;
doublevectorAbsoluteValue(double X, double Y, double Z)
vector Absolute Value
double absoluteValue = Math.sqrt(Math.pow(X, 2) + Math.pow(Y, 2) + Math.pow(Z, 2));
return absoluteValue;
doublevectorCos(int[] d1, int[] d2)
vector Cos
if (d1.length != d2.length)
    throw new IllegalArgumentException("length not equal");
double l1 = 0.0, l2 = 0.0;
long accumunate = 0;
for (int i = 0; i < d1.length; i++) {
    l1 += d1[i] * d1[i];
    l2 += d2[i] * d2[i];
    accumunate += d1[i] * d2[i];
...
double[]vectorDiff(final double[] vecOne, final double[] vecTwo)
Substract two vectors.
if (vecOne == null || vecTwo == null) {
    throw new IllegalArgumentException("vector 'vecOne' or 'vecTwo' == null!");
if (vecOne.length != vecTwo.length) {
    throw new IllegalArgumentException(
            "The vectors differs in length!( " + vecOne.length + " != " + vecTwo.length);
double[] ret = new double[vecOne.length];
...
intvectorDir(int vert, int horiz)
vector Dir
int v = verticalDir(vert);
int h = horizontalDir(horiz);
if (vert != v && horiz != h) {
    throw new IllegalArgumentException("Invalid directions");
return VECTOR_LOOKUP[h + v % 3];
doublevectorDistance(double[] vec1, double[] vec2, double power)
Calculate the p-norm (i.e.
return vectorDistance(vec1, vec2, power, 1.0 / power);
int[]vectorIndexToUpperTriangularIndices(int numberOfRows, int index)
vector Index To Upper Triangular Indices
int rowIndex = 0;
int columnIndex;
while (index >= numberOfRows - 1 - rowIndex) {
    index -= numberOfRows - 1 - rowIndex;
    rowIndex++;
columnIndex = rowIndex + 1 + index;
return (new int[] { rowIndex, columnIndex });
...