1 package edu.berkeley.qfat.geom;
3 /** affine matrix; immutable */
11 public final float a, b, c, d, e, f, g, h, i, j, k, l;
12 public Matrix() { this(1); }
13 public Matrix(float scale) {
15 l = h = d = e = b = i = c = j = g = 0;
17 public Matrix(float scalex, float scaley, float scalez) {
21 l = h = d = e = b = i = c = j = g = 0;
23 public Matrix(Vec translate) {
24 d = translate.x; h = translate.y; l = translate.z;
26 b = c = e = g = i = j = 0;
28 public Matrix(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l) {
29 this.a = a; this.b = b; this.c = c; this.d = d; this.e = e; this.f = f; this.g = g; this.h = h; this.i = i;
30 this.j = j; this.k = k; this.l = l;
32 public Matrix times(float x) {
33 return new Matrix(a*x, b*x, c*x, d*x, e*x, f*x, g*x, h*x, i*x, j*x, k*x, l*x);
35 public Matrix(Vec axis, float angle) {
36 double q = Math.cos(angle);
37 double s = Math.sin(angle);
39 a = (float)(q + axis.x*axis.x*t);
40 f = (float)(q + axis.y*axis.y*t);
41 k = (float)(q + axis.z*axis.z*t);
42 double tmp1 = axis.x*axis.y*t;
43 double tmp2 = axis.z*s;
44 e = (float)(tmp1 + tmp2);
45 b = (float)(tmp1 - tmp2);
46 tmp1 = axis.x*axis.z*t;
48 i = (float)(tmp1 - tmp2);
49 c = (float)(tmp1 + tmp2);
50 tmp1 = axis.y*axis.z*t;
52 j = (float)(tmp1 + tmp2);
53 g = (float)(tmp1 - tmp2);
56 public Point times(Point p) {
57 return new Point(a*p.x + b*p.y + c*p.z + d,
58 e*p.x + f*p.y + g*p.z + h,
59 i*p.x + j*p.y + k*p.z + l);
61 public Point apply(Point p) { return p; }
62 public Vec apply(Vec v) { return v; }
63 public Matrix invert() { return this; }
64 public Matrix times(Matrix m) { return this; }