Matrices can be represented in two forms:
- A two-dimensional array in which the first index is the row number and the second index is the column number. A matrix element Aij is thus represented as A[i][j] in Java.
- A one dimensional array in either row-major order or column-major order. In row-major order, the elements of a row are adjacent to each other, listed in the order specified by their columns. In column-major order, the elements of a column are adjacent to each other, listed in the order specified by their rows. For multidimensional arrays, C uses row-major order and FORTRAN uses column-major order.
transpose(double[],int,int,double[],int,int,boolean)
method. For example,
MatrixOps.transpose(matrix, 20, 20, matrix, 20, 20, true);
With a flat representation, matrices can be interleaved. In this form, each element of the matrix is a vector, with each element in a matrix using vectors of the same length. These vectors are stored contiguously. When a matrix operation is performed for this case, the arguments for a method will include the vector length and the index of the component of the vector that will be used. This representation is convenient for cases such as Bézier patches: for the cubic case, each patch is represented by 16 control points, typically named by two indices, each of which can take on 4 values (0, 1, 2, and 3). Each control point itself consists of three values: the X, Y, and Z coordinates for the point. The internal representation uses a sequence of three double-precision numbers for each control point, with the control points in column-major order. For example,
wheredouble[] controlPoints = { P00x, P00y, P00z, P10x, P10y, P10z, ... };
Pijx
is the X component of the control point
Pij, etc.-
Method Summary
Modifier and TypeMethodDescriptionstatic double[][]
add
(double[][] A, double[][] B) Add two matrices.static double[][]
add
(double[][] R, double[][] A, double[][] B) Add two matrices and store the results.static double[]
add
(double[] A, double[] B) Add two flat matrices.static double[]
add
(double[] R, double[] A, double[] B) Add two flat matrices and store the results.static void
add
(int n, int m, double[] C, int offsetC, double[] A, int offsetA, double[] B, int offsetB, int indC, int vlenC, int indA, int vlenA, int indB, int vlenB) Add two flat, interleaved matrices and store the results.static double[]
flatten
(double[][] matrix, boolean colOrder) Convert a matrix represented by a two-dimensional array to a linear array in either row- or column-major order.static double[]
flatten
(double[] result, double[][] matrix, boolean colOrder) Convert a matrix represented by a two-dimensional array to a linear array in either row- or column-major order, providing an array in which to store the results.static double[]
multiply
(double[][] A, double[] B) Multiply a matrix with a vectorstatic double[][]
multiply
(double[][] A, double[][] B) Multiple two matricesstatic double[][]
multiply
(double[][] C, double[][] A, double[][] B) Multiple two matrices, storing the results in a third matrix.static double[][]
multiply
(double[][] result, double s, double[][] matrix) Multiply a matrix by a scalar, storing the results.static double[]
multiply
(double[] C, double[][] A, double[] B) Multiply a matrix with a vector, storing the results in a specified vectorstatic double[]
multiply
(double[] result, double s, double[] matrix) Multiply a flattened matrix (or a vector) by a scalar, storing the results.static double[]
multiply
(double[] A, int mA, int nA, double[] B, int mB, int nB, boolean colOrder) Multiply two flattened matrices and return a flattened matrixstatic double[]
multiply
(double[] C, int mC, int nC, double[] A, int mA, int nA, double[] B, int mB, int nB, boolean colOrder) Multiply two flattened matrices and store the results in a third flattened matrix.static void
multiply
(double[] C, int mC, int nC, int offsetC, double[] A, int mA, int nA, int offsetA, double[] B, int mB, int nB, int offsetB, boolean colOrder, int indC, int vlenC, int indA, int vlenA, int indB, int vlenB) Multiply flattened matrices and store the results in a third flattened matrix, when matrix elements are interleaved.static double[]
multiply
(double s, double[] matrix) Multiply a flattened matrix (or a vector) by a scalar.static double[][]
multiply
(double s, double[][] matrix) Multiply a matrix by a scalarstatic void
multiply
(int n, int m, double[] R, int offsetR, double s, double[] A, int offsetA, int indR, int vlenR, int indA, int vlenA) Multiply flattened matrix by a scalar and store the results in a second flattened matrix, when matrix elements are interleaved.static double[][]
reflect
(double[][] A) Reflect the rows and columns in a matrix.static double[][]
reflect
(double[][] R, double[][] A) Reflect the rows and columns in a matrix, providing a matrix to return.static double[][]
reflect
(double[][] R, double[][] A, int m, int n) Reflect the rows and columns in a matrix, providing a matrix to return and specifying dimensions.static double[][]
reflect
(double[][] A, int m, int n) Reflect the rows and columns in a matrix, specifying dimensions.static double[]
reflect
(double[] R, double[] A, int m, int n, boolean colOrder) Reflect the rows and columns in a matrix, specifying dimensions and the column order, and providing a matrix to hold the results.static void
reflect
(double[] R, int offsetR, double[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) Reflect the rows and columns in an interleaved flat matrix, storing the results.static double[]
reflect
(double[] A, int m, int n, boolean colOrder) Reflect the rows and columns in a matrix, specifying dimensions and the column order..static void
reflect
(float[] R, int offsetR, float[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) Reflect the rows and columns in an interleaved flat matrix of single-precision real numbers, storing the results.static double[][]
reflectColumns
(double[][] A) Reflect the columns in a matrix.static double[][]
reflectColumns
(double[][] R, double[][] A) Reflect the columns in a matrix, providing a matrix to return.static double[][]
reflectColumns
(double[][] R, double[][] A, int m, int n) Reflect the columns in a matrix, providing a matrix to return and specifying dimensions.static double[][]
reflectColumns
(double[][] A, int m, int n) Reflect the columns in a matrix, specifying dimensions.static double[]
reflectColumns
(double[] R, double[] A, int m, int n, boolean colOrder) Reflect the columns in a matrix, specifying dimensions and the column order, and providing a matrix to hold the results.static void
reflectColumns
(double[] R, int offsetR, double[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) Reflect the columns in an interleaved flat matrix, storing the results.static double[]
reflectColumns
(double[] A, int m, int n, boolean colOrder) Reflect the columns in a matrix, specifying dimensions and the column order..static void
reflectColumns
(float[] R, int offsetR, float[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) Reflect the columns in an interleaved flat matrix, storing the results and representing the matrices by arrays of floats.static double[][]
reflectRows
(double[][] A) Reflect the rows in a matrix.static double[][]
reflectRows
(double[][] R, double[][] A) Reflect the rows in a matrix, providing a matrix to return.static double[][]
reflectRows
(double[][] R, double[][] A, int m, int n) Reflect the rows in a matrix, providing a matrix to return and specifying dimensions.static double[][]
reflectRows
(double[][] A, int m, int n) Reflect the rows in a matrix, specifying dimensions.static double[]
reflectRows
(double[] R, double[] A, int m, int n, boolean colOrder) Reflect the rows in a matrix, specifying dimensions and the column order, and providing a matrix to hold the results.static void
reflectRows
(double[] R, int offsetR, double[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) Reflect the rows in an interleaved flat matrix, storing the results.static double[]
reflectRows
(double[] A, int m, int n, boolean colOrder) Reflect the rows in a matrix, specifying dimensions and the column order..static void
reflectRows
(float[] R, int offsetR, float[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) Reflect the rows in an interleaved flat matrix, storing the results and representing the matrices by arrays of floats.static double[][]
subtract
(double[][] A, double[][] B) Subtract two matrices.static double[][]
subtract
(double[][] R, double[][] A, double[][] B) Subtract two matrices and store the results.static double[]
subtract
(double[] A, double[] B) Subtract two flat matrices.static double[]
subtract
(double[] R, double[] A, double[] B) Subtract two flat matrices and store the results.static double[][]
transpose
(double[][] A) Compute the transpose of a matrix.static double[][]
transpose
(double[][] R, double[][] A) Compute the transpose of a matrix.static double[][]
transpose
(double[][] R, double[][] A, int n, int m) Compute the transpose of a matrix given its dimensions.static double[][]
transpose
(double[][] A, int n, int m) Compute the transpose of a matrix of an m by n matrix.static double[]
transpose
(double[] A, int m, int n, boolean colOrder) Compute the transpose of a flat matrix.static double[]
transpose
(double[] R, int mR, int nR, double[] A, int mA, int nA, boolean colOrder) Compute the transpose of a flat matrix, storing the results.static void
transpose
(double[] R, int mR, int nR, int offsetR, double[] A, int mA, int nA, int offsetA, boolean colOrder, int indR, int vlenR, int indA, int vlenA) Compute the transpose of an interleaved, flat matrix, storing the results.static void
transpose
(float[] R, int mR, int nR, int offsetR, float[] A, int mA, int nA, int offsetA, boolean colOrder, int indR, int vlenR, int indA, int vlenA) Compute the transpose of an interleaved, flat, single-precision matrix, storing the results.static double[][]
unflatten
(double[][] result, double[] matrix, int m, int n, boolean colOrder) Convert a flattened matrix to an unflattened matrix.static double[][]
unflatten
(double[] matrix, int m, int n, boolean colOrder) Convert a flattened matrix to an unflattened matrix.
-
Method Details
-
flatten
Convert a matrix represented by a two-dimensional array to a linear array in either row- or column-major order.- Parameters:
matrix
- the matrix to convertcolOrder
- true for column-major order; false for row-major order- Returns:
- return the converted matrix
- Throws:
IllegalArgumentException
- the array passed as the first argument is too short
-
flatten
public static double[] flatten(double[] result, double[][] matrix, boolean colOrder) throws IllegalArgumentException Convert a matrix represented by a two-dimensional array to a linear array in either row- or column-major order, providing an array in which to store the results.- Parameters:
matrix
- the matrix to convertcolOrder
- true for column-major order; false for row-major orderresult
- the array in which to store the flattened matrix- Returns:
- the matrix containing the result
- Throws:
IllegalArgumentException
- the array passed as the first argument is too short
-
unflatten
public static double[][] unflatten(double[] matrix, int m, int n, boolean colOrder) throws IllegalArgumentException Convert a flattened matrix to an unflattened matrix. The flattened matrix can be in either row- or column-major order.- Parameters:
matrix
- the flattened matrixm
- the number of rowsn
- the number of columnscolOrder
- true for column-major order; false for row-major order- Returns:
- the unflattened matrix
- Throws:
IllegalArgumentException
- The first argument has the wrong dimensions or the second argument has the wrong length
-
unflatten
public static double[][] unflatten(double[][] result, double[] matrix, int m, int n, boolean colOrder) throws IllegalArgumentException Convert a flattened matrix to an unflattened matrix. The flattened matrix can be in either row- or column-major order. the length of the array matrix must be n*m and the matrix result must have n rows and m columns- Parameters:
result
- the matrix (n rows and m columns) used to store the unflattened matrixmatrix
- the flattened matrixm
- the number of rowsn
- the number of columnscolOrder
- true for column-major order; false for row-major order- Returns:
- the unflattened matrix
- Throws:
IllegalArgumentException
- The first argument has the wrong dimensions or the second argument has the wrong length
-
add
Add two matrices.- Parameters:
A
- the first matrixB
- the second matrix- Returns:
- the matrix sum A+B
- Throws:
IllegalArgumentException
- The matrix dimensions are not consistent
-
add
public static double[][] add(double[][] R, double[][] A, double[][] B) throws IllegalArgumentException Add two matrices and store the results.- Parameters:
R
- the result matrixA
- the first matrixB
- the second matrix All matrices must have the same number of rows and columns The matrices can be identical objects.- Returns:
- the matrix sum A+B
- Throws:
IllegalArgumentException
- The matrix dimensions are not consistent
-
add
Add two flat matrices.- Parameters:
A
- the first matrixB
- the second matrix- Returns:
- the matrix sum A+B
- Throws:
IllegalArgumentException
- an argument was illegal
-
add
Add two flat matrices and store the results. The matrices can be identical objects.- Parameters:
R
- the result matrixA
- the first matrixB
- the second matrix- Returns:
- the matrix sum A+B
- Throws:
IllegalArgumentException
- the arrays R, A, and B do not have the same lengths
-
add
public static void add(int n, int m, double[] C, int offsetC, double[] A, int offsetA, double[] B, int offsetB, int indC, int vlenC, int indA, int vlenA, int indB, int vlenB) Add two flat, interleaved matrices and store the results. The class documentation forMatrixOps
describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap.- Parameters:
n
- the number of rowsm
- the number of columnsC
- the result matrixoffsetC
- the index into C at which the results should be storedA
- the first matrixoffsetA
- the offset into A for the first matrixB
- the second matrixoffsetB
- the offset into B for the second matrixindC
- the index specifying the component of the vector representing an element of CvlenC
- the length of the vectors that are the components of CindA
- the index specifying the component of the vector representing an element of AvlenA
- the length of the vectors that are the components of AindB
- the index specifying the component of the vector representing an element of BvlenB
- the length of the vectors that are the components of B
-
transpose
Compute the transpose of a matrix.- Parameters:
A
- the matrix- Returns:
- a new matrix containing AT
- Throws:
IllegalArgumentException
- the matrix R does have dimensions compatible with the matrix A, or when R and A are the same matrix, that matrix is not a square matrix
-
transpose
Compute the transpose of a matrix of an m by n matrix.- Parameters:
A
- the matrixn
- the number of rowsm
- the number of columns- Returns:
- a new matrix containing AT
- Throws:
IllegalArgumentException
- the matrix R does have dimensions compatible with the matrix A, or when R and A are the same matrix, that matrix is not a square matrix
-
transpose
Compute the transpose of a matrix. The matrices can be identical objects.- Parameters:
R
- the matrix that will contain the transpose of AA
- the matrix to transpose- Returns:
- the matrix R = AT
- Throws:
IllegalArgumentException
- the matrix R does have dimensions compatible with the matrix A, or when R and A are the same matrix, that matrix is not a square matrix
-
transpose
public static double[][] transpose(double[][] R, double[][] A, int n, int m) throws IllegalArgumentException Compute the transpose of a matrix given its dimensions. The matrices can be identical objects. The matrix A may have longer rows or columns than its dimensions (m by n) indicate. Similarly R may have longer rows or colums than its dimensions (n, m) indicate.- Parameters:
R
- the matrix that will contain the transpose of AA
- the matrix to transposen
- the number of rows of A and columns of Rm
- the number of columns of A and rows of R- Returns:
- the matrix R = AT
- Throws:
IllegalArgumentException
- the matrix R does have dimensions compatible with the matrix A, or when R and A are the same matrix, that matrix is not a square matrix
-
transpose
public static double[] transpose(double[] A, int m, int n, boolean colOrder) throws IllegalArgumentException Compute the transpose of a flat matrix.- Parameters:
A
- the matrix to transposem
- the number of rowsn
- the number of columnscolOrder
- true if the matrices are stored in column-major order; false if the matrices are stored in row-major order- Returns:
- the transpose of A
- Throws:
IllegalArgumentException
- the array A is too short given the specified numbers of rows and columns
-
transpose
public static double[] transpose(double[] R, int mR, int nR, double[] A, int mA, int nA, boolean colOrder) throws IllegalArgumentException Compute the transpose of a flat matrix, storing the results. The matrices can be identical objects but in that case they must be square matrices.- Parameters:
R
- the matrix that will contain the transposemR
- the number of rows for RnR
- the number of columns for RA
- the matrix to transposemA
- the number of rows for AnA
- the number of columns for AcolOrder
- true if the matrices are stored in column-major order; false if the matrices are stored in row-major order- Returns:
- the matrix R = AT
- Throws:
IllegalArgumentException
- The matrix R must be an m by n matrix when A is an n by m matrix; the array A or the array R are too short given the specified numbers of rows and columns
-
transpose
public static void transpose(double[] R, int mR, int nR, int offsetR, double[] A, int mA, int nA, int offsetA, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException Compute the transpose of an interleaved, flat matrix, storing the results. The class documentation forMatrixOps
describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. If R and A are identical, they must be square matrices.- Parameters:
R
- the matrix that will contain the transposemR
- the number of rows for the matrix contained by RnR
- the number of columns for the matrix contained by RoffsetR
- the offset into R at which the matrix R startsA
- the matrix to transposemA
- the number of rows for the matrix contained by AnA
- the number of columns for the matrix contained by AoffsetA
- the offset into A at which the matrix A startscolOrder
- true if the matrices are stored in column-major order; false if the matrices are stored in row-major orderindR
- The index into each vector provided by each element of RvlenR
- the length of the vectors that are elements of RindA
- The index into each vector provided by each element of AvlenA
- the length of the vectors that are elements of A- Throws:
IllegalArgumentException
- the dimensions of the matrices are not consistent, a square message was expected in the case where R == A, or the R and A arrays are too short given the specified offsets and vector dimensions
-
transpose
public static void transpose(float[] R, int mR, int nR, int offsetR, float[] A, int mA, int nA, int offsetA, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException Compute the transpose of an interleaved, flat, single-precision matrix, storing the results. The class documentation forMatrixOps
describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. If R and A are identical, they must be square matrices.Note: This method is provided because it is needed in the implementation of some
Surface3D.Float
methods.- Parameters:
R
- the matrix that will contain the transposemR
- the number of rows for the matrix contained by RnR
- the number of columns for the matrix contained by RoffsetR
- the offset into R at which the matrix R startsA
- the matrix to transposemA
- the number of rows for the matrix contained by AnA
- the number of columns for the matrix contained by AoffsetA
- the offset into A at which the matrix A startscolOrder
- true if the matrices are stored in column-major order; false if the matrices are stored in row-major orderindR
- The index into each vector provided by each element of RvlenR
- the length of the vectors that are elements of RindA
- The index into each vector provided by each element of AvlenA
- the length of the vectors that are elements of A- Throws:
IllegalArgumentException
- the dimensions of the matrices are not consistent, a square message was expected in the case where R == A, or the R and A arrays are too short given the specified offsets and vector dimensions
-
reflectRows
Reflect the rows in a matrix. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.- Parameters:
A
- the orgininal matrix- Returns:
- the reflected matrix
- Throws:
IllegalArgumentException
-
reflectRows
Reflect the rows in a matrix, providing a matrix to return. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.R and A must have the same dimensions.
- Parameters:
R
- the reflected matrixA
- the orgininal matrix- Returns:
- the reflected matrix R
- Throws:
IllegalArgumentException
-
reflectRows
public static double[][] reflectRows(double[][] R, double[][] A, int m, int n) throws IllegalArgumentException Reflect the rows in a matrix, providing a matrix to return and specifying dimensions. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.R and A must have the dimensions large enough so that R[i][j] or A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored.
- Parameters:
R
- the reflected matrixA
- the orgininal matrixm
- the number of rowsn
- the number of columns- Returns:
- the reflected matrix R
- Throws:
IllegalArgumentException
-
reflectRows
public static double[][] reflectRows(double[][] A, int m, int n) Reflect the rows in a matrix, specifying dimensions. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible.
- Parameters:
A
- the orgininal matrixm
- the number of rowsn
- the number of columns- Returns:
- the reflected matrix R
-
reflectRows
public static double[] reflectRows(double[] A, int m, int n, boolean colOrder) throws IllegalArgumentException Reflect the rows in a matrix, specifying dimensions and the column order.. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.
- Parameters:
A
- the orgininal matrixm
- the number of rowsn
- the number of columnscolOrder
- true for column major order; false for row major order- Returns:
- the reflected matrix R
- Throws:
IllegalArgumentException
-
reflectRows
public static double[] reflectRows(double[] R, double[] A, int m, int n, boolean colOrder) throws IllegalArgumentException Reflect the rows in a matrix, specifying dimensions and the column order, and providing a matrix to hold the results. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.
- Parameters:
R
- the reflected matrix, the elements of which will be setA
- the orgininal matrixm
- the number of rowsn
- the number of columnscolOrder
- true for column major order; false for row major order- Returns:
- the reflected matrix R
- Throws:
IllegalArgumentException
-
reflectRows
public static void reflectRows(double[] R, int offsetR, double[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException Reflect the rows in an interleaved flat matrix, storing the results. The class documentation forMatrixOps
describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.
- Parameters:
R
- the reflected matrix, the elements of which will be setoffsetR
- the offset into the array R at which the reflected matrix startsA
- the orgininal matrixoffsetA
- the offset in the array A at which the matrix to be reflected startsm
- the number of rowsn
- the number of columnscolOrder
- true for column major order; false for row major orderindR
- The index into each vector provided by each element of RvlenR
- the length of the vectors that are elements of RindA
- The index into each vector provided by each element of AvlenA
- the length of the vectors that are elements of A- Throws:
IllegalArgumentException
-
reflectRows
public static void reflectRows(float[] R, int offsetR, float[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException Reflect the rows in an interleaved flat matrix, storing the results and representing the matrices by arrays of floats. The class documentation forMatrixOps
describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Aik where k = n-1-j for indices that start at 0.A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.
- Parameters:
R
- the reflected matrix, the elements of which will be setoffsetR
- the offset into the array R at which the reflected matrix startsA
- the orgininal matrixoffsetA
- the offset in the array A at which the matrix to be reflected startsm
- the number of rowsn
- the number of columnscolOrder
- true for column major order; false for row major orderindR
- The index into each vector provided by each element of RvlenR
- the length of the vectors that are elements of RindA
- The index into each vector provided by each element of AvlenA
- the length of the vectors that are elements of A- Throws:
IllegalArgumentException
-
reflectColumns
Reflect the columns in a matrix. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.- Parameters:
A
- the orgininal matrix- Returns:
- the reflected matrix
- Throws:
IllegalArgumentException
-
reflectColumns
Reflect the columns in a matrix, providing a matrix to return. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.R and A must have the same dimensions.
- Parameters:
R
- the reflected matrixA
- the orgininal matrix- Returns:
- the reflected matrix R
- Throws:
IllegalArgumentException
-
reflectColumns
public static double[][] reflectColumns(double[][] R, double[][] A, int m, int n) throws IllegalArgumentException Reflect the columns in a matrix, providing a matrix to return and specifying dimensions. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.R and A must have the dimensions large enough so that R[i][j] or A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored.
- Parameters:
R
- the reflected matrixA
- the orgininal matrixm
- the number of rowsn
- the number of columns- Returns:
- the reflected matrix R
- Throws:
IllegalArgumentException
-
reflectColumns
public static double[][] reflectColumns(double[][] A, int m, int n) Reflect the columns in a matrix, specifying dimensions. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible.
- Parameters:
A
- the orgininal matrixm
- the number of rowsn
- the number of columns- Returns:
- the reflected matrix R
-
reflectColumns
public static double[] reflectColumns(double[] A, int m, int n, boolean colOrder) throws IllegalArgumentException Reflect the columns in a matrix, specifying dimensions and the column order.. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.
- Parameters:
A
- the orgininal matrixm
- the number of rowsn
- the number of columnscolOrder
- true for column major order; false for row major order- Returns:
- the reflected matrix R
- Throws:
IllegalArgumentException
-
reflectColumns
public static double[] reflectColumns(double[] R, double[] A, int m, int n, boolean colOrder) throws IllegalArgumentException Reflect the columns in a matrix, specifying dimensions and the column order, and providing a matrix to hold the results. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.
- Parameters:
R
- the reflected matrix, the elements of which will be setA
- the orgininal matrixm
- the number of rowsn
- the number of columnscolOrder
- true for column major order; false for row major order- Returns:
- the reflected matrix R
- Throws:
IllegalArgumentException
-
reflectColumns
public static void reflectColumns(double[] R, int offsetR, double[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException Reflect the columns in an interleaved flat matrix, storing the results. The class documentation forMatrixOps
describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.
- Parameters:
R
- the reflected matrix, the elements of which will be setoffsetR
- the offset into the array R at which the reflected matrix startsA
- the orgininal matrixoffsetA
- the offset in the array A at which the matrix to be reflected startsm
- the number of rowsn
- the number of columnscolOrder
- true for column major order; false for row major orderindR
- The index into each vector provided by each element of RvlenR
- the length of the vectors that are elements of RindA
- The index into each vector provided by each element of AvlenA
- the length of the vectors that are elements of A- Throws:
IllegalArgumentException
-
reflectColumns
public static void reflectColumns(float[] R, int offsetR, float[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException Reflect the columns in an interleaved flat matrix, storing the results and representing the matrices by arrays of floats. The class documentation forMatrixOps
describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.
- Parameters:
R
- the reflected matrix, the elements of which will be setoffsetR
- the offset into the array R at which the reflected matrix startsA
- the orgininal matrixoffsetA
- the offset in the array A at which the matrix to be reflected startsm
- the number of rowsn
- the number of columnscolOrder
- true for column major order; false for row major orderindR
- The index into each vector provided by each element of RvlenR
- the length of the vectors that are elements of RindA
- The index into each vector provided by each element of AvlenA
- the length of the vectors that are elements of A- Throws:
IllegalArgumentException
-
reflect
Reflect the rows and columns in a matrix. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.- Parameters:
A
- the orgininal matrix- Returns:
- the reflected matrix
- Throws:
IllegalArgumentException
-
reflect
Reflect the rows and columns in a matrix, providing a matrix to return. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.R and A must have the same dimensions.
- Parameters:
R
- the reflected matrixA
- the orgininal matrix- Returns:
- the reflected matrix R
- Throws:
IllegalArgumentException
-
reflect
public static double[][] reflect(double[][] R, double[][] A, int m, int n) throws IllegalArgumentException Reflect the rows and columns in a matrix, providing a matrix to return and specifying dimensions. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.R and A must have the dimensions large enough so that R[i][j] or A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored.
- Parameters:
R
- the reflected matrixA
- the orgininal matrixm
- the number of rowsn
- the number of columns- Returns:
- the reflected matrix R
- Throws:
IllegalArgumentException
-
reflect
public static double[][] reflect(double[][] A, int m, int n) Reflect the rows and columns in a matrix, specifying dimensions. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible.
- Parameters:
A
- the orgininal matrixm
- the number of rowsn
- the number of columns- Returns:
- the reflected matrix R
-
reflect
public static double[] reflect(double[] A, int m, int n, boolean colOrder) throws IllegalArgumentException Reflect the rows and columns in a matrix, specifying dimensions and the column order.. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.
- Parameters:
A
- the orgininal matrixm
- the number of rowsn
- the number of columnscolOrder
- true for column major order; false for row major order- Returns:
- the reflected matrix R
- Throws:
IllegalArgumentException
-
reflect
public static double[] reflect(double[] R, double[] A, int m, int n, boolean colOrder) throws IllegalArgumentException Reflect the rows and columns in a matrix, specifying dimensions and the column order, and providing a matrix to hold the results. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.
- Parameters:
R
- the reflected matrix, the elements of which will be setA
- the orgininal matrixm
- the number of rowsn
- the number of columnscolOrder
- true for column major order; false for row major order- Returns:
- the reflected matrix R
- Throws:
IllegalArgumentException
-
reflect
public static void reflect(double[] R, int offsetR, double[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException Reflect the rows and columns in an interleaved flat matrix, storing the results. The class documentation forMatrixOps
describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.
- Parameters:
R
- the reflected matrix, the elements of which will be setoffsetR
- the offset into the array R at which the reflected matrix startsA
- the orgininal matrixoffsetA
- the offset in the array A at which the matrix to be reflected startsm
- the number of rowsn
- the number of columnscolOrder
- true for column major order; false for row major orderindR
- The index into each vector provided by each element of RvlenR
- the length of the vectors that are elements of RindA
- The index into each vector provided by each element of AvlenA
- the length of the vectors that are elements of A- Throws:
IllegalArgumentException
-
reflect
public static void reflect(float[] R, int offsetR, float[] A, int offsetA, int m, int n, boolean colOrder, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException Reflect the rows and columns in an interleaved flat matrix of single-precision real numbers, storing the results. The class documentation forMatrixOps
describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap. Each row will have its entries listed in the opposite order: For an m by n matrix A, its reflected matrix R satisfies Rij = Akj where k = m-1-j for indices that start at 0.A must have the dimensions large enough so that A[i][j] are with the array bounds for i ∈ [0,m) and j ∈ [0, m). Elements outside this range are ignored. The matrix returned will be as small as possible. The matrix elements will be stored in a one-dimensional array in either row major order or column major order.
- Parameters:
R
- the reflected matrix, the elements of which will be setoffsetR
- the offset into the array R at which the reflected matrix startsA
- the orgininal matrixoffsetA
- the offset in the array A at which the matrix to be reflected startsm
- the number of rowsn
- the number of columnscolOrder
- true for column major order; false for row major orderindR
- The index into each vector provided by each element of RvlenR
- the length of the vectors that are elements of RindA
- The index into each vector provided by each element of AvlenA
- the length of the vectors that are elements of A- Throws:
IllegalArgumentException
-
multiply
public static double[][] multiply(double s, double[][] matrix) Multiply a matrix by a scalar- Parameters:
s
- the scalarmatrix
- a matrix- Returns:
- the product matrix
-
multiply
public static double[][] multiply(double[][] result, double s, double[][] matrix) throws IllegalArgumentException Multiply a matrix by a scalar, storing the results. The matrices may be identical.- Parameters:
result
- the matrix to store the resultss
- the scalarmatrix
- a matrix- Returns:
- the product matrix
- Throws:
IllegalArgumentException
- the dimensions of the matrices are not compatible
-
multiply
Multiply a flattened matrix (or a vector) by a scalar. The matrices may be identical.- Parameters:
s
- the scalarmatrix
- a matrix- Returns:
- the product matrix
- Throws:
IllegalArgumentException
- the dimensions of the matrices are not compatible
-
multiply
public static double[] multiply(double[] result, double s, double[] matrix) throws IllegalArgumentException Multiply a flattened matrix (or a vector) by a scalar, storing the results.- Parameters:
result
- the matrix to store the resultss
- the scalarmatrix
- a matrix- Returns:
- the matrix result
- Throws:
IllegalArgumentException
- the result matrix has the wrong length
-
multiply
public static void multiply(int n, int m, double[] R, int offsetR, double s, double[] A, int offsetA, int indR, int vlenR, int indA, int vlenA) throws IllegalArgumentException Multiply flattened matrix by a scalar and store the results in a second flattened matrix, when matrix elements are interleaved. The class documentation forMatrixOps
describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector. The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap.- Parameters:
n
- the number of rowsm
- the number of columnsR
- the result matrixoffsetR
- the index into R at which the results should be storeds
- the scalarA
- the matrix being multipliedoffsetA
- the offset into A for the first matrixindR
- the index specifying the component of the vector representing an element of RvlenR
- the length of the vectors that are the components of RindA
- the index specifying the component of the vector representing an element of AvlenA
- the length of the vectors that are the components of A- Throws:
IllegalArgumentException
- arguments are out of range or inconsistent
-
multiply
Multiply a matrix with a vector- Parameters:
A
- the matrixB
- the vector- Returns:
- the vector containing the product
- Throws:
IllegalArgumentException
- The dimensions of A and B are not compatible with matrix multiplication, or C has the wrong length
-
multiply
public static double[] multiply(double[] C, double[][] A, double[] B) Multiply a matrix with a vector, storing the results in a specified vector- Parameters:
C
- the vector storing the resultA
- the matrixB
- the vector- Returns:
- the vector containing the product
- Throws:
IllegalArgumentException
- The dimensions of A and B are not compatible with matrix multiplication, or C has the wrong length
-
multiply
Multiple two matrices- Parameters:
A
- the first matrixB
- the second matrix- Returns:
- the matrix product AB
- Throws:
IllegalArgumentException
- the dimensions of A, B and C are not compatible
-
multiply
public static double[][] multiply(double[][] C, double[][] A, double[][] B) throws IllegalArgumentException Multiple two matrices, storing the results in a third matrix. The result matrix C may be equal to A or B, provided these are square matrices.- Parameters:
C
- the matrix whose value will be changed to the matrix product ABA
- the first matrixB
- the second matrix- Returns:
- the result matrix C
- Throws:
IllegalArgumentException
- the dimensions of A, B and C are not compatible
-
multiply
public static double[] multiply(double[] A, int mA, int nA, double[] B, int mB, int nB, boolean colOrder) throws IllegalArgumentException Multiply two flattened matrices and return a flattened matrix- Parameters:
A
- the first matrixB
- the second matrixmA
- the number of rows for matrix AnA
- the number of columns for matrix AmB
- the number of rows for matrix BnB
- the number of columns for matrix BcolOrder
- true for column-major order; false for row-major order- Returns:
- a flattened matrix containing the matrix product AB
- Throws:
IllegalArgumentException
- one of more of the matrices, represented by an array, are too short or the dimensions of the matrices are not compatible for matrix multiplication
-
multiply
public static double[] multiply(double[] C, int mC, int nC, double[] A, int mA, int nA, double[] B, int mB, int nB, boolean colOrder) Multiply two flattened matrices and store the results in a third flattened matrix. The matrix C may be equal to A or B provided that these are square matrices.- Parameters:
C
- the flattened matrix that will hold the resultmC
- the number of rows for matrix AnC
- the number of columns for matrix AA
- the first flattened matrixmA
- the number of rows for matrix AnA
- the number of columns for matrix AB
- the second flattened matrixmB
- the number of rows for matrix BnB
- the number of columns for matrix BcolOrder
- true for column-major order; false for row-major order- Returns:
- the matrix C
- Throws:
IllegalArgumentException
- one of more of the matrices, represented by an array, are too short or the dimensions of the matrices are not compatible for matrix multiplication
-
multiply
public static void multiply(double[] C, int mC, int nC, int offsetC, double[] A, int mA, int nA, int offsetA, double[] B, int mB, int nB, int offsetB, boolean colOrder, int indC, int vlenC, int indA, int vlenA, int indB, int vlenB) throws IllegalArgumentException Multiply flattened matrices and store the results in a third flattened matrix, when matrix elements are interleaved. The class documentation forMatrixOps
describes interleaved matrices, which are effectively matrices of vectors where an operation applies to a specific component of the vector.This method has a large number of parameters. It is used by some classes in the org.bzdev.geom package involving Bézier surfaces. For example, the control points of a Bézier patch with coordinate (u, v) can be represented by a 4 by 4 matrix P whose components Pij are points in a three dimensional space. The index i is used with u and the index j with v. Points with the same value of v are stored together in the order of increasing i in a flattened matrix (i.e., the points are stored in column-major order). Each of these points is represented by three contiguous numbers representing the control points' X, Y, and Z coordinates. Splitting a Bézier involves computing the control points for a new patch, and this can be done by creating a matrix with the same indices but containing only one of the coordinates (X, Y, or Z). This matrix is then multiplied with two fixed matrices. This method allows the multiplication to be done in place. For example,
will perform one of these multiplications. The matrix SR is a constant matrix - the same for X, Y, and Z - so its elements are a one dimensional vector (i.e., a single number). The other two are vectors with three dimensions. The patch offset allows one out of a multiple of matrices stored in the same array to be referenced.for (int k = 0; k < 3; k++) { MatrixOps.multiply(C, 4, 4, 0, P, 4, 4, patchOffset, SR, 4, 4, 0, true, k, 3, k, 3, 0, 1); }
The arrays can be identical arrays but the regions of the arrays representing matrices must not partially overlap.
- Parameters:
C
- the flattened matrix that will hold the result, the matrix product ABmC
- the number of rows for matrix CnC
- the number of columns for matrix CoffsetC
- the offset into C at which the matrix starts (i.e, the index in C of the first element of the matrix)A
- the first flattened matrixmA
- the number of rows for matrix AnA
- the number of columns for matrix AoffsetA
- the offset into A at which the matrix starts (i.e, the index in A of the first element of the matrix)B
- the second flattened matrixmB
- the number of rows for matrix BnB
- the number of columns for matrix BoffsetB
- the offset into B at which the matrix starts (i.e, the index in B of the first element of the matrix)colOrder
- true for column-major order; false for row-major orderindC
- the index of the vector component for C to use for this computationvlenC
- the vector length for an element of CindA
- the index of the vector component for A to use for this computationvlenA
- the vector length for an element of AindB
- the index of the vector component for B to use for this computationvlenB
- the vector length for an element of B- Throws:
IllegalArgumentException
- if the vector lengths are not incorrect or an array is not long enough to hold the specified number of rows and columns, or the offsets are not appropriate
-
subtract
Subtract two matrices.- Parameters:
A
- the first matrixB
- the second matrix- Returns:
- the matrix difference A-B
- Throws:
IllegalArgumentException
- The matrix dimensions are not consistent
-
subtract
public static double[][] subtract(double[][] R, double[][] A, double[][] B) throws IllegalArgumentException Subtract two matrices and store the results.- Parameters:
R
- the result matrixA
- the first matrixB
- the second matrix All matrices must have the same number of rows and columns The matrices can be identical objects.- Returns:
- the matrix difference A-B
- Throws:
IllegalArgumentException
- The matrix dimensions are not consistent
-
subtract
Subtract two flat matrices.- Parameters:
A
- the first matrixB
- the second matrix- Returns:
- the matrix difference A-B
- Throws:
IllegalArgumentException
- if the arguments are not valid
-
subtract
Subtract two flat matrices and store the results. The matrices can be identical objects.- Parameters:
R
- the result matrixA
- the first matrixB
- the second matrix- Returns:
- the matrix difference A-B
- Throws:
IllegalArgumentException
- the arrays R, A, and B do not have the same lengths
-