Exemple #1
0
 public static void crossProduct3D(Vector A, Vector B, Vector C) {
   if (B.getData().equals(C.getData()))
     throw new IllegalArgumentException("Inner data structures are the same.");
   if (A.getLength() != 3 || B.getLength() != 3)
     throw new IllegalArgumentException("Vectors should both be 3D vectors");
   unCheckedCrossPorduct3D(A, B, C);
 }
Exemple #2
0
 /**
  * Returns the dot product of the two vectors. It's the user responsibility to make sure that each
  * vector has the same dimensions.
  */
 public static double unCheckedDotProduct(Vector A, Vector B) {
   double result = 0;
   double[] dataA = A.getData();
   double[] dataB = B.getData();
   for (int i = 0; i < A.getLength(); i++) result += dataA[i] * dataB[i];
   return result;
 }
Exemple #3
0
 /**
  * Multiplies the matrix A with the vector B and stores the result in vector C, the inner data
  * arrays of C may NOT be the same as the one in B (So be careful when using vectors from methods
  * like {@link Vector.wrapAround()} or {@link Matrix.wrapAround()}).
  *
  * @throws IllegalArgumentException If the dimensions of A, B and C are illegal for a
  *     matrix-vector multiplication.
  * @throws IllegalArgumentException If the inner data arrays of B and C are the same.
  */
 public static void mult(Matrix A, Vector B, Vector C) {
   if (B.getData().equals(C.getData()))
     throw new IllegalArgumentException("Inner data structures are the same.");
   if (A.getnCols() != B.getLength() || A.getnRows() != C.getLength())
     throw new IllegalArgumentException("Illegal matrix dimensions.");
   else unCheckedMult(A, B, C);
 }
Exemple #4
0
 /**
  * Multiplies the matrix A with the vector B and stores the result in vector C, the inner data
  * arrays of C may NOT be the same as the one in B (So be careful when using vectors from methods
  * like {@link Vector.wrapAround()} or {@link Matrix.wrapAround()}). It's the user responsibility
  * to make sure that each vector has the same dimensions.
  */
 public static void unCheckedMult(Matrix A, Vector B, Vector C) {
   double[][] dataA = A.getData();
   double[] dataB = B.getData();
   double[] dataC = C.getData();
   for (int j = 0; j < A.getnRows(); j++) {
     for (int k = 0; k < A.getnCols(); k++) dataC[j] += dataA[k][j] * dataB[k];
   }
 }
Exemple #5
0
 /**
  * Subtracts the vector B from the vector A and stores the result in vector C. It's the user
  * responsibility to make sure that each vector has the same dimensions.
  */
 public static void unCheckedSub(Vector A, Vector B, Vector C) {
   double[] dataA = A.getData();
   double[] dataB = B.getData();
   double[] dataC = C.getData();
   for (int i = 0; i < dataA.length; i++) dataC[i] = dataA[i] - dataB[i];
 }