From bc5bc47f080218f91ef987102204775e3e2b6677 Mon Sep 17 00:00:00 2001 From: adam Date: Sat, 15 Dec 2007 16:54:03 -0800 Subject: [PATCH] checkpoint darcs-hash:20071216005403-5007d-312a2df3e2656a7d6ed9b2632eba4905bad52747.gz --- src/edu/berkeley/qfat/Main.java | 28 ++++++------- src/edu/berkeley/qfat/Mesh.java | 2 +- src/edu/berkeley/qfat/geom/Matrix.java | 70 ++++++++++++++++---------------- 3 files changed, 51 insertions(+), 49 deletions(-) diff --git a/src/edu/berkeley/qfat/Main.java b/src/edu/berkeley/qfat/Main.java index d10f63b..0ff0dcf 100644 --- a/src/edu/berkeley/qfat/Main.java +++ b/src/edu/berkeley/qfat/Main.java @@ -66,7 +66,7 @@ public class Main extends MeshViewer { goal.ignorecollision = true; // rotate to align major axis -- this probably needs to be done by a human. - goal.transform(new Matrix(new Vec(0, 0, 1), (float)(Math.PI/2))); + goal.transform(Matrix.rotate(new Vec(0, 0, 1), (float)(Math.PI/2))); float goal_width = goal.diagonal().dot(new Vec(1, 0, 0)); float goal_height = goal.diagonal().dot(new Vec(0, 1, 0)); @@ -89,24 +89,24 @@ public class Main extends MeshViewer { translations = new Matrix[] { - new Matrix(new Vec(lshift, depth, halfup)), - new Matrix(new Vec(rshift, depth, halfup)), - new Matrix(new Vec(lshift, -depth, halfup)), - new Matrix(new Vec(rshift, -depth, halfup)), + Matrix.translate(new Vec(lshift, depth, halfup)), + Matrix.translate(new Vec(rshift, depth, halfup)), + Matrix.translate(new Vec(lshift, -depth, halfup)), + Matrix.translate(new Vec(rshift, -depth, halfup)), /* - new Matrix(new Vec(0, depth, halfup)), - new Matrix(new Vec(0, -depth, halfup)), + Matrix.translate(new Vec(0, depth, halfup)), + Matrix.translate(new Vec(0, -depth, halfup)), */ - new Matrix(new Vec(lshift, 0, height)), - new Matrix(new Vec(rshift, 0, height)), - new Matrix(new Vec(lshift, 0, -height)), - new Matrix(new Vec(rshift, 0, -height)), + Matrix.translate(new Vec(lshift, 0, height)), + Matrix.translate(new Vec(rshift, 0, height)), + Matrix.translate(new Vec(lshift, 0, -height)), + Matrix.translate(new Vec(rshift, 0, -height)), - new Matrix(new Vec( width, 0, 0)), - new Matrix(new Vec(-width, 0, 0)), + Matrix.translate(new Vec( width, 0, 0)), + Matrix.translate(new Vec(-width, 0, 0)), }; @@ -246,7 +246,7 @@ public class Main extends MeshViewer { goal.transform(Matrix.scale(factor)); // translate to match centroid - goal.transform(new Matrix(tile.centroid().minus(goal.centroid()))); + goal.transform(Matrix.translate(tile.centroid().minus(goal.centroid()))); //tx.e2.shatter(); //tx.e3.shatter(); diff --git a/src/edu/berkeley/qfat/Mesh.java b/src/edu/berkeley/qfat/Mesh.java index cd696b0..3544dba 100644 --- a/src/edu/berkeley/qfat/Mesh.java +++ b/src/edu/berkeley/qfat/Mesh.java @@ -378,7 +378,7 @@ public class Mesh implements Iterable { private boolean good; public boolean move(Vec v) { - Matrix m = new Matrix(v); + Matrix m = Matrix.translate(v); Vert p = this; boolean good = true; do { diff --git a/src/edu/berkeley/qfat/geom/Matrix.java b/src/edu/berkeley/qfat/geom/Matrix.java index 6712b28..514f7d7 100644 --- a/src/edu/berkeley/qfat/geom/Matrix.java +++ b/src/edu/berkeley/qfat/geom/Matrix.java @@ -13,31 +13,32 @@ public class Matrix { */ public final float a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p; + /** the zero matrix */ public static final Matrix ZERO = new Matrix(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); + + /** the identity matrix */ public static final Matrix ONE = new Matrix(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1); - public static Matrix scale(float scale) { return new Matrix(scale, 0, 0, 0, 0, scale, 0, 0, 0, 0, scale, 0, 0, 0, 0, 1); } + /** a scaling matrix (uniform in all dimensions) */ + public static Matrix scale(float scale) { return scale(scale, scale, scale); } + + /** a scaling matrix */ + public static Matrix scale(float scalex, float scaley, float scalez) { + return new Matrix(scalex, 0, 0, 0, 0, scaley, 0, 0, 0, 0, scalez, 0, 0, 0, 0, 1); } - public Matrix(float scalex, float scaley, float scalez) { - a = scalex; - f = scaley; - k = scalez; - l = h = d = e = b = i = c = j = g = 0; - m = n = o = 0; - p = 1; - } - public Matrix(Vec translate) { - d = translate.x; h = translate.y; l = translate.z; - a = f = k = 1; - b = c = e = g = i = j = 0; - m = n = o = 0; - p = 1; - } 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, float m, float n, float o, float p) { 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; this.j = j; this.k = k; this.l = l; this.m = m; this.n = n; this.o = o; this.p = p; } + + public static Matrix translate(Vec translate) { + return new Matrix(1, 0, 0, translate.x, + 0, 1, 0, translate.y, + 0, 0, 1, translate.z, + 0, 0, 0, 1); + } + public Matrix plus(Matrix x) { return new Matrix(a+x.a, b+x.b, c+x.c, d+x.d, e+x.e, f+x.f, g+x.g, h+x.h, i+x.i, j+x.j, k+x.k, l+x.l, m+x.m, n+x.n, o+x.o, p+x.p); } @@ -58,28 +59,29 @@ public class Matrix { return ret; } - public Matrix(Vec axis, float angle) { - double q = Math.cos(angle); - double s = Math.sin(angle); - double t = 1.0 - q; - a = (float)(q + axis.x*axis.x*t); - f = (float)(q + axis.y*axis.y*t); - k = (float)(q + axis.z*axis.z*t); - double tmp1 = axis.x*axis.y*t; - double tmp2 = axis.z*s; - e = (float)(tmp1 + tmp2); - b = (float)(tmp1 - tmp2); + public static Matrix rotate(Vec axis, float angle) { + float q = (float)Math.cos(angle); + float s = (float)Math.sin(angle); + float t = 1 - q; + float a = (float)(q + axis.x*axis.x*t); + float f = (float)(q + axis.y*axis.y*t); + float k = (float)(q + axis.z*axis.z*t); + float tmp1 = axis.x*axis.y*t; + float tmp2 = axis.z*s; + float e = (float)(tmp1 + tmp2); + float b = (float)(tmp1 - tmp2); tmp1 = axis.x*axis.z*t; tmp2 = axis.y*s; - i = (float)(tmp1 - tmp2); - c = (float)(tmp1 + tmp2); + float i = (float)(tmp1 - tmp2); + float c = (float)(tmp1 + tmp2); tmp1 = axis.y*axis.z*t; tmp2 = axis.x*s; - j = (float)(tmp1 + tmp2); - g = (float)(tmp1 - tmp2); - d = h = l = 0; - m = n = o = 0; - p = 1; + float j = (float)(tmp1 + tmp2); + float g = (float)(tmp1 - tmp2); + return new Matrix(a, b, c, 0, + e, f, g, 0, + i, j, k, 0, + 0, 0, 0, 1); } public Point times(Point p) { // discards bottom row -- 1.7.10.4