/** * Extracts the row from the matrix a. * @param a Input matrix * @param row Which row is to be extracted * @param output output. Storage for the extracted row. If null then a new vector will be returned. * @return The extracted row. */ public static FMatrix3 extractRow(FMatrix3x3 a, int row, FMatrix3 output) { if (output == null) { output = new FMatrix3(); } switch (row) { case 0: output.a1 = a.a11; output.a2 = a.a12; output.a3 = a.a13; break; case 1: output.a1 = a.a21; output.a2 = a.a22; output.a3 = a.a23; break; case 2: output.a1 = a.a31; output.a2 = a.a32; output.a3 = a.a33; break; default: throw new ArgumentException("Out of bounds row. row = " + row); } return(output); }
/** * Extracts the column from the matrix a. * @param a Input matrix * @param column Which column is to be extracted * @param output output. Storage for the extracted column. If null then a new vector will be returned. * @return The extracted column. */ public static FMatrix3 extractColumn(FMatrix3x3 a, int column, FMatrix3 output) { if (output == null) { output = new FMatrix3(); } switch (column) { case 0: output.a1 = a.a11; output.a2 = a.a21; output.a3 = a.a31; break; case 1: output.a1 = a.a12; output.a2 = a.a22; output.a3 = a.a32; break; case 2: output.a1 = a.a13; output.a2 = a.a23; output.a3 = a.a33; break; default: throw new ArgumentException("Out of bounds column. column = " + column); } return(output); }
public FMatrix3(FMatrix3 other) { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { matrix[i, j] = other.matrix[i, j]; } } }
public FMatrix3 Transpose() { FMatrix3 tmatrix = new FMatrix3(); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { tmatrix.matrix[i, j] = matrix[j, i]; } } return(tmatrix); }
public static float normF(FMatrix3 M) { float scale = CommonOps_FDF3.elementMaxAbs(M); if (scale == 0.0f) { return(0.0f); } float a1 = M.a1 / scale, a2 = M.a2 / scale, a3 = M.a3 / scale; float sum = a1 * a1 + a2 * a2 + a3 * a3; return(scale * (float)Math.Sqrt(sum)); }
/** * <p> * Returns the value of the element in the vector that has the largest value.<br> * <br> * Max{ a<sub>i</sub> } for all i<br> * </p> * * @param a A vector. Not modified. * @return The max element value of the matrix. */ public static float elementMax(FMatrix3 a) { float max = a.a1; if (a.a2 > max) { max = a.a2; } if (a.a3 > max) { max = a.a3; } return(max); }
/** * <p> * Returns the value of the element in the vector that has the minimum value.<br> * <br> * Min{ a<sub>i</sub> } for all<br> * </p> * * @param a A matrix. Not modified. * @return The value of element in the vector with the minimum value. */ public static float elementMin(FMatrix3 a) { float min = a.a1; if (a.a2 < min) { min = a.a2; } if (a.a3 < min) { min = a.a3; } return(min); }
public static bool hasUncountable(FMatrix3 a) { if (UtilEjml.isUncountable(a.a1)) { return(true); } if (UtilEjml.isUncountable(a.a2)) { return(true); } if (UtilEjml.isUncountable(a.a3)) { return(true); } return(false); }
public static bool isIdentical(FMatrix3 a, FMatrix3 b, float tol) { if (!MatrixFeatures_FDRM.isIdentical(a.a1, b.a1, tol)) { return(false); } if (!MatrixFeatures_FDRM.isIdentical(a.a2, b.a2, tol)) { return(false); } if (!MatrixFeatures_FDRM.isIdentical(a.a3, b.a3, tol)) { return(false); } return(true); }
/** * <p> * Returns the absolute value of the element in the vector that has the smallest absolute value.<br> * <br> * Min{ |a<sub>i</sub>| } for all i<br> * </p> * * @param a A matrix. Not modified. * @return The max element value of the vector. */ public static float elementMinAbs(FMatrix3 a) { float min = Math.Abs(a.a1); float tmp = Math.Abs(a.a1); if (tmp < min) { min = tmp; } tmp = Math.Abs(a.a2); if (tmp < min) { min = tmp; } tmp = Math.Abs(a.a3); if (tmp < min) { min = tmp; } return(min); }
/** * <p> * Returns the absolute value of the element in the vector that has the largest absolute value.<br> * <br> * Max{ |a<sub>i</sub>| } for all i<br> * </p> * * @param a A matrix. Not modified. * @return The max abs element value of the vector. */ public static float elementMaxAbs(FMatrix3 a) { float max = Math.Abs(a.a1); float tmp = Math.Abs(a.a2); if (tmp > max) { max = tmp; } tmp = Math.Abs(a.a2); if (tmp > max) { max = tmp; } tmp = Math.Abs(a.a3); if (tmp > max) { max = tmp; } return(max); }
/** * Converts {@link FMatrixRMaj} into {@link FMatrix3} * * @param input Input matrix. * @param output Output matrix. If null a new matrix will be declared. * @return Converted matrix. */ public static FMatrix3 convert(FMatrixRMaj input, FMatrix3 output) { if (output == null) { output = new FMatrix3(); } if (input.getNumRows() != 1 && input.getNumCols() != 1) { throw new ArgumentException("One row or column must have a length of 1 for it to be a vector"); } int length = Math.Max(input.getNumRows(), input.getNumCols()); if (length != 3) { throw new ArgumentException("Length of input vector is not 3. It is " + length); } output.a1 = input.data[0]; output.a2 = input.data[1]; output.a3 = input.data[2]; return(output); }
/** * <p> * Performs an in-place element by element scalar division. Scalar denominator.<br> * <br> * a<sub>i</sub> = a<sub>i</sub>/α * </p> * * @param a The vector whose elements are to be divided. Modified. * @param alpha the amount each element is divided by. */ public static void divide(FMatrix3 a, float alpha) { a.a1 /= alpha; a.a2 /= alpha; a.a3 /= alpha; }
public static float fastNormF(FMatrix3 M) { float sum = M.a1 * M.a1 + M.a2 * M.a2 + M.a3 * M.a3; return((float)Math.Sqrt(sum)); }
/** * <p> * Performs an element by element scalar multiplication.<br> * <br> * b<sub>i</sub> = α*a<sub>i</sub> * </p> * * @param alpha the amount each element is multiplied by. * @param a The vector that is to be scaled. Not modified. * @param b Where the scaled matrix is stored. Modified. */ public static void scale(float alpha, FMatrix3 a, FMatrix3 b) { b.a1 = a.a1 * alpha; b.a2 = a.a2 * alpha; b.a3 = a.a3 * alpha; }
/** * <p>Performs an element by element multiplication operation:<br> * <br> * a<sub>i</sub> = a<sub>i</sub> * b<sub>i</sub> <br> * </p> * @param a The left vector in the multiplication operation. Modified. * @param b The right vector in the multiplication operation. Not modified. */ public static void elementMult(FMatrix3 a, FMatrix3 b) { a.a1 *= b.a1; a.a2 *= b.a2; a.a3 *= b.a3; }
public static void normalizeF(FMatrix3 M) { float val = normF(M); CommonOps_FDF3.divide(M, val); }
/** * <p>Performs the following operation:<br> * <br> * a = a - b <br> * a<sub>i</sub> = a<sub>i</sub> - b<sub>i</sub> <br> * </p> * * @param a A Vector. Modified. * @param b A Vector. Not modified. */ public static void subtractEquals(FMatrix3 a, FMatrix3 b) { a.a1 -= b.a1; a.a2 -= b.a2; a.a3 -= b.a3; }
/** * <p>Performs the following operation:<br> * <br> * a = a + b <br> * a<sub>i</sub> = a<sub>i</sub> + b<sub>i</sub> <br> * </p> * * @param a A Vector. Modified. * @param b A Vector. Not modified. */ public static void addEquals(FMatrix3 a, FMatrix3 b) { a.a1 += b.a1; a.a2 += b.a2; a.a3 += b.a3; }
/** * <p>Performs matrix to vector multiplication:<br> * <br> * c = a * b <br> * <br> * c<sub>i</sub> = ∑<sub>k=1:n</sub> { a<sub>ik</sub> * b<sub>k</sub>} * </p> * * @param a The left matrix in the multiplication operation. Not modified. * @param b The right vector in the multiplication operation. Not modified. * @param c Where the results of the operation are stored. Modified. */ public static void mult(FMatrix3x3 a, FMatrix3 b, FMatrix3 c) { c.a1 = a.a11 * b.a1 + a.a12 * b.a2 + a.a13 * b.a3; c.a2 = a.a21 * b.a1 + a.a22 * b.a2 + a.a23 * b.a3; c.a3 = a.a31 * b.a1 + a.a32 * b.a2 + a.a33 * b.a3; }
/** * <p>Performs the following operation:<br> * <br> * c = a - b <br> * c<sub>i</sub> = a<sub>i</sub> - b<sub>i</sub> <br> * </p> * * <p> * Vector C can be the same instance as Vector A and/or B. * </p> * * @param a A Vector. Not modified. * @param b A Vector. Not modified. * @param c A Vector where the results are stored. Modified. */ public static void subtract(FMatrix3 a, FMatrix3 b, FMatrix3 c) { c.a1 = a.a1 - b.a1; c.a2 = a.a2 - b.a2; c.a3 = a.a3 - b.a3; }
/** * <p> * Performs an element by element scalar division. Scalar denominator.<br> * <br> * b<sub>i</sub> = a<sub>i</sub> /α * </p> * * @param alpha the amount each element is divided by. * @param a The vector whose elements are to be divided. Not modified. * @param b Where the results are stored. Modified. */ public static void divide(FMatrix3 a, float alpha, FMatrix3 b) { b.a1 = a.a1 / alpha; b.a2 = a.a2 / alpha; b.a3 = a.a3 / alpha; }
/** * <p> * Performs an in-place element by element scalar multiplication.<br> * <br> * a<sub>ij</sub> = α*a<sub>ij</sub> * </p> * * @param a The vector that is to be scaled. Modified. * @param alpha the amount each element is multiplied by. */ public static void scale(float alpha, FMatrix3 a) { a.a1 *= alpha; a.a2 *= alpha; a.a3 *= alpha; }
/** * <p> * Changes the sign of every element in the vector.<br> * <br> * a<sub>i</sub> = -a<sub>i</sub> * </p> * * @param a A vector. Modified. */ public static void changeSign(FMatrix3 a) { a.a1 = -a.a1; a.a2 = -a.a2; a.a3 = -a.a3; }
/** * <p>Performs the vector dot product:<br> * <br> * c = a * b <br> * <br> * c ≥ ∑<sub>k=1:n</sub> { b<sub>k</sub> * a<sub>k</sub> } * </p> * * @param a The left vector in the multiplication operation. Not modified. * @param b The right matrix in the multiplication operation. Not modified. * @return The dot product */ public static float dot(FMatrix3 a, FMatrix3 b) { return(a.a1 * b.a1 + a.a2 * b.a2 + a.a3 * b.a3); }
/** * <p>Performs vector to matrix multiplication:<br> * <br> * c = a * b <br> * <br> * c<sub>j</sub> = ∑<sub>k=1:n</sub> { b<sub>k</sub> * a<sub>kj</sub> } * </p> * * @param a The left vector in the multiplication operation. Not modified. * @param b The right matrix in the multiplication operation. Not modified. * @param c Where the results of the operation are stored. Modified. */ public static void mult(FMatrix3 a, FMatrix3x3 b, FMatrix3 c) { c.a1 = a.a1 * b.a11 + a.a2 * b.a21 + a.a3 * b.a31; c.a2 = a.a1 * b.a12 + a.a2 * b.a22 + a.a3 * b.a32; c.a3 = a.a1 * b.a13 + a.a2 * b.a23 + a.a3 * b.a33; }
/** * <p>Performs the following operation:<br> * <br> * c = a + b <br> * c<sub>i</sub> = a<sub>i</sub> + b<sub>i</sub> <br> * </p> * * <p> * Vector C can be the same instance as Vector A and/or B. * </p> * * @param a A Vector. Not modified. * @param b A Vector. Not modified. * @param c A Vector where the results are stored. Modified. */ public static void add(FMatrix3 a, FMatrix3 b, FMatrix3 c) { c.a1 = a.a1 + b.a1; c.a2 = a.a2 + b.a2; c.a3 = a.a3 + b.a3; }
/** * <p> * Sets every element in the vector to the specified value.<br> * <br> * a<sub>i</sub> = value * <p> * * @param a A vector whose elements are about to be set. Modified. * @param v The value each element will have. */ public static void fill(FMatrix3 a, float v) { a.a1 = v; a.a2 = v; a.a3 = v; }
/** * <p> * Extracts all diagonal elements from 'input' and places them inside the 'output' vector. Elements * are in sequential order. * </p> * * * @param input Matrix. Not modified. * @param output Vector containing diagonal elements. Modified. */ public static void diag(FMatrix3x3 input, FMatrix3 output) { output.a1 = input.a11; output.a2 = input.a22; output.a3 = input.a33; }
/** * <p>Performs an element by element division operation:<br> * <br> * c<sub>i</sub> = a<sub>i</sub> / b<sub>i</sub> <br> * </p> * @param a The left vector in the division operation. Not modified. * @param b The right vector in the division operation. Not modified. * @param c Where the results of the operation are stored. Modified. */ public static void elementDiv(FMatrix3 a, FMatrix3 b, FMatrix3 c) { c.a1 = a.a1 / b.a1; c.a2 = a.a2 / b.a2; c.a3 = a.a3 / b.a3; }