summaryrefslogtreecommitdiff
path: root/CSMath/src/bezier/geom/Matrix.java
diff options
context:
space:
mode:
Diffstat (limited to 'CSMath/src/bezier/geom/Matrix.java')
-rw-r--r--CSMath/src/bezier/geom/Matrix.java76
1 files changed, 63 insertions, 13 deletions
diff --git a/CSMath/src/bezier/geom/Matrix.java b/CSMath/src/bezier/geom/Matrix.java
index a728a02..f9395ea 100644
--- a/CSMath/src/bezier/geom/Matrix.java
+++ b/CSMath/src/bezier/geom/Matrix.java
@@ -1,44 +1,94 @@
package bezier.geom;
+/**
+ * Matrix class.
+ *
+ * @author bjculkin
+ *
+ */
public class Matrix {
+ /**
+ * Matrix values.
+ */
public final double[][] mat;
+ /**
+ * Create a new matrix, with the specified values.
+ *
+ * @param mat
+ * The matrix to use.
+ */
public Matrix(double[][] mat) {
this.mat = mat;
}
-
+
+ /**
+ * Add two matrices together.
+ *
+ * @param m
+ * The matrix to add.
+ * @return An added matrix.
+ */
public Matrix add(Matrix m) {
return add(m.mat);
}
-
+
+ /**
+ * Multiply this matrix by a scalar vector.
+ *
+ * @param vec
+ * The vector to multiply by.
+ * @return The resulting vector.
+ */
public double[] scalarMultiply(double[] vec) {
double[] ret = new double[vec.length];
-
- for(int i = 0; i < mat[0].length; i++) {
- for(int j = 0; j < mat.length; j++) {
+
+ for (int i = 0; i < mat[0].length; i++) {
+ for (int j = 0; j < mat.length; j++) {
ret[i] += mat[i][j] * vec[j];
}
}
-
+
return ret;
}
-
+
+ /**
+ * Add a matrix to this one.
+ *
+ * @param matr
+ * The matrix to add.
+ * @return The resulting matrix.
+ */
public Matrix add(double[][] matr) {
double[][] ret = new double[mat.length][mat[0].length];
-
- for(int i = 0; i < mat.length; i++) {
- for(int j = 0; j < mat[0].length; j++) {
+
+ for (int i = 0; i < mat.length; i++) {
+ for (int j = 0; j < mat[0].length; j++) {
ret[i][j] = mat[i][j] + matr[i][j];
}
}
-
+
return new Matrix(ret);
}
-
+
+ /**
+ * Multiply this matrix by another.
+ *
+ * @param m
+ * The matrix to multiply by
+ * @return The multiplied matrix.
+ */
public Matrix multiply(Matrix m) {
return multiply(m.mat);
}
-
+
+ /**
+ * Multiply this matrix by another.
+ *
+ * @param matr
+ * The matrix to multiply by
+ * @return The multiplied matrix.
+ */
public Matrix multiply(double[][] matr) {
double[][] ret = new double[mat.length][matr[0].length];