summaryrefslogtreecommitdiff
path: root/CSMath/src/bezier/geom/transform/TDHMatrixTransform.java
blob: 0952703274a32d6b28bd1ed942add5f7e5b8fff3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package bezier.geom.transform;

import bezier.geom.Matrix;
import bezier.geom.TDHPoint;

/**
 * 2D homogenous transform defined by a matrix.
 * 
 * @author bjculkin
 *
 */
public class TDHMatrixTransform implements TDHTransform {
	/**
	 * The matrix for the transform.
	 */
	public final Matrix mat;

	/**
	 * Create a new matrix-based transform.
	 * 
	 * @param mat
	 *                The matrix that defines the transform.
	 */
	public TDHMatrixTransform(Matrix mat) {
		this.mat = mat;
	}

	/**
	 * Create a new matrix-based transform.
	 * 
	 * @param mat
	 *                The matrix that defines the transform.
	 */
	public TDHMatrixTransform(double[][] mat) {
		this.mat = new Matrix(mat);
	}

	@Override
	public TDHTransformType type() {
		return TDHTransformType.MATRIX;
	}

	@Override
	public TDHPoint transform(TDHPoint punkt) {
		double[] mult = mat.scalarMultiply(new double[] { punkt.x, punkt.y, punkt.z });

		return new TDHPoint(mult[0], mult[1], mult[2]);
	}

	/**
	 * Chain two matrix transforms together.
	 * 
	 * @param trans
	 *                The next transform to use.
	 * @return A transform that represents the two transforms in serial.
	 */
	public TDHTransform then(TDHMatrixTransform trans) {
		return new TDHMatrixTransform(mat.multiply(trans.mat));
	}
}