From: adam Date: Wed, 5 Dec 2007 03:20:55 +0000 (-0800) Subject: checkpoint X-Git-Url: http://git.megacz.com/?p=anneal.git;a=commitdiff_plain;h=8918917f15a999a99acd7b33e9afe678a456c226;ds=sidebyside checkpoint darcs-hash:20071205032055-5007d-664aca6ab4792fb94ace77493f8ab4b85b70913a.gz --- diff --git a/src/Geom.java b/src/Geom.java index 6bfe4f1..c7374f7 100644 --- a/src/Geom.java +++ b/src/Geom.java @@ -13,11 +13,9 @@ public class Geom implements Iterable { public static float EPSILON = (float)0.0001; public static Random random = new Random(); - private HashMap ps = new HashMap(); - //public PriorityQueue es = new PriorityQueue(); - public HashSet es = new HashSet(); - //private HashSet ts = new HashSet(); - public ArrayList ts = new ArrayList(); + private HashMap ps = new HashMap(); + public HashSet es = new HashSet(); + public ArrayList ts = new ArrayList(); public Iterator iterator() { return ts.iterator(); } @@ -55,7 +53,7 @@ public class Geom implements Iterable { for(P p : set) p.transform(m); } - public V diagonal() { + public Vec diagonal() { float min_x = Float.MAX_VALUE; float min_y = Float.MAX_VALUE; float min_z = Float.MAX_VALUE; @@ -70,7 +68,7 @@ public class Geom implements Iterable { if (p.y > max_y) max_y = p.y; if (p.z > max_z) max_z = p.z; } - return new V(max_x - min_x, max_y - min_y, max_z - min_z); + return new Vec(max_x - min_x, max_y - min_y, max_z - min_z); } public P centroid() { @@ -96,8 +94,8 @@ public class Geom implements Iterable { public P newP(double x, double y, double z) { return newP((float)x, (float)y, (float)z); } public P newP(float x, float y, float z) { return new P(x, y, z); } - public T newT(P p12, P p23, P p31, V norm) { - V norm2 = p31.minus(p12).cross(p23.minus(p12)); + public T newT(P p12, P p23, P p31, Vec norm) { + Vec norm2 = p31.minus(p12).cross(p23.minus(p12)); float dot = norm.dot(norm2); //if (Math.abs(dot) < EPSILON) throw new Error("dot products within epsilon of each other: "+norm+" "+norm2); if (dot < 0) { P p = p12; p12=p23; p23 = p; } @@ -109,7 +107,7 @@ public class Geom implements Iterable { double total = 0; for(T t : ts) { double area = t.area(); - V origin_to_centroid = new V(newP(0, 0, 0), t.centroid()); + Vec origin_to_centroid = new Vec(newP(0, 0, 0), t.centroid()); boolean facingAway = t.norm().dot(origin_to_centroid) > 0; double height = Math.abs(t.norm().dot(origin_to_centroid)); total += ((facingAway ? 1 : -1) * area * height) / 3.0; @@ -142,14 +140,11 @@ public class Geom implements Iterable { return ret; } - private char allname = 'A'; - public M aspect = new M(); public M invaspect = new M(); /** [UNIQUE] point in 3-space */ public final class P { - char name; float x, y, z; @@ -169,7 +164,7 @@ public class Geom implements Iterable { public P register() { P p2 = ps.get(this); - if (p2==null) { p2 = this; ps.put(this,this); name = allname++; } + if (p2==null) { p2 = this; ps.put(this,this); } return p2; } @@ -284,7 +279,7 @@ public class Geom implements Iterable { */ return good; } - public boolean move(V v) { + public boolean move(Vec v) { M m = new M(v); P p = this; boolean good = true; @@ -361,8 +356,8 @@ public class Geom implements Iterable { this.x = x; this.y = y; this.z = z; } - public V minus(P p) { return new V(x-p.x, y-p.y, z-p.z); } - public P plus(V v) { return newP(x+v.x, y+v.y, z+v.z); } + public Vec minus(P p) { return new Vec(x-p.x, y-p.y, z-p.z); } + public P plus(Vec v) { return newP(x+v.x, y+v.y, z+v.z); } public boolean equals(Object o) { if (o==null || !(o instanceof P)) return false; P p = (P)o; @@ -382,8 +377,8 @@ public class Geom implements Iterable { gl.glVertex3f(x, y, z); } public String toString() { return "("+x+","+y+","+z+")"; } - public V norm() { - V norm = new V(0, 0, 0); + public Vec norm() { + Vec norm = new Vec(0, 0, 0); E e = this.e; do { if (e.t != null) norm = norm.plus(e.t.norm().times((float)e.prev.angle())); @@ -394,19 +389,19 @@ public class Geom implements Iterable { } /** vector in 3-space */ - public final class V { + public final class Vec { public final float x, y, z; - public V(double x, double y, double z) { this((float)x, (float)y, (float)z); } - public V(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } - public V(P p1, P p2) { this(p2.x-p1.x, p2.y-p1.y, p2.z-p1.z); } - public V cross(V v) { return new V(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x); } - public V plus(V v) { return new V(x+v.x, y+v.y, z+v.z); } - public V norm() { return mag()==0 ? this : div(mag()); } - public V times(M m) { return m.apply(this); } + public Vec(double x, double y, double z) { this((float)x, (float)y, (float)z); } + public Vec(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } + public Vec(P p1, P p2) { this(p2.x-p1.x, p2.y-p1.y, p2.z-p1.z); } + public Vec cross(Vec v) { return new Vec(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x); } + public Vec plus(Vec v) { return new Vec(x+v.x, y+v.y, z+v.z); } + public Vec norm() { return mag()==0 ? this : div(mag()); } + public Vec times(M m) { return m.apply(this); } public float mag() { return (float)Math.sqrt(x*x+y*y+z*z); } - public float dot(V v) { return x*v.x + y*v.y + z*v.z; } - public V times(float mag) { return new V(x*mag, y*mag, z*mag); } - public V div(float mag) { return new V(x/mag, y/mag, z/mag); } + public float dot(Vec v) { return x*v.x + y*v.y + z*v.z; } + public Vec times(float mag) { return new Vec(x*mag, y*mag, z*mag); } + public Vec div(float mag) { return new Vec(x/mag, y/mag, z/mag); } public String toString() { return "<"+x+","+y+","+z+">"; } } @@ -600,8 +595,8 @@ public class Geom implements Iterable { /** angle between this half-edge and the next */ public double angle() { - V v1 = next.p2.minus(p2); - V v2 = this.p1.minus(p2); + Vec v1 = next.p2.minus(p2); + Vec v2 = this.p1.minus(p2); return Math.acos(v1.norm().dot(v2.norm())); } @@ -729,12 +724,12 @@ public class Geom implements Iterable { public E e1() { return e1; } public E e2() { return e1.next; } public E e3() { return e1.prev; } - public V norm() { return p2().minus(p1()).cross(p3().minus(p1())).norm(); } + public Vec norm() { return p2().minus(p1()).cross(p3().minus(p1())).norm(); } public boolean hasE(E e) { return e1==e || e1.next==e || e1.prev==e; } public boolean has(P p) { return p1()==p || p2()==p || p3()==p; } public float area() { - return (float)Math.abs(0.5 * e1().length() * new V(p1(), p2()).norm().dot(new V(p2(), p3()))); + return (float)Math.abs(0.5 * e1().length() * new Vec(p1(), p2()).norm().dot(new Vec(p2(), p3()))); } public void glVertices(GL gl) { @@ -775,7 +770,7 @@ public class Geom implements Iterable { k = scalez; l = h = d = e = b = i = c = j = g = 0; } - public M(V translate) { + public M(Vec translate) { d = translate.x; h = translate.y; l = translate.z; a = f = k = 1; b = c = e = g = i = j = 0; @@ -787,7 +782,7 @@ public class Geom implements Iterable { public M times(float x) { return new M(a*x, b*x, c*x, d*x, e*x, f*x, g*x, h*x, i*x, j*x, k*x, l*x); } - public M(V axis, float angle) { + public M(Vec axis, float angle) { double q = Math.cos(angle); double s = Math.sin(angle); double t = 1.0 - q; @@ -814,7 +809,7 @@ public class Geom implements Iterable { i*p.x + j*p.y + k*p.z + l); } public P apply(P p) { return p; } - public V apply(V v) { return v; } + public Vec apply(Vec v) { return v; } public M invert() { return this; } public M times(M m) { return this; } } diff --git a/src/Main.java b/src/Main.java index c789e0f..dc880cd 100644 --- a/src/Main.java +++ b/src/Main.java @@ -80,37 +80,37 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener Geom.P p0 = goal.newP(stlf.coordArray[i+0].x * MAG, stlf.coordArray[i+0].y * MAG, stlf.coordArray[i+0].z * MAG); Geom.P p1 = goal.newP(stlf.coordArray[i+1].x * MAG, stlf.coordArray[i+1].y * MAG, stlf.coordArray[i+1].z * MAG); Geom.P p2 = goal.newP(stlf.coordArray[i+2].x * MAG, stlf.coordArray[i+2].y * MAG, stlf.coordArray[i+2].z * MAG); - Geom.V n = goal.new V(stlf.normArray[i/3].x * MAG, stlf.normArray[i/3].y * MAG, stlf.normArray[i/3].z * MAG); + Geom.Vec n = goal.new Vec(stlf.normArray[i/3].x * MAG, stlf.normArray[i/3].y * MAG, stlf.normArray[i/3].z * MAG); Geom.T t = goal.newT(p0, p1, p2, n); } // rotate to align major axis -- this probably needs to be done by a human. - goal.transform(goal.new M(goal.new V(0, 0, 1), (float)(Math.PI/2))); + goal.transform(goal.new M(goal.new Vec(0, 0, 1), (float)(Math.PI/2))); - float goal_width = goal.diagonal().dot(goal.new V(1, 0, 0)); - float goal_height = goal.diagonal().dot(goal.new V(0, 1, 0)); - float goal_depth = goal.diagonal().dot(goal.new V(0, 0, 1)); + float goal_width = goal.diagonal().dot(goal.new Vec(1, 0, 0)); + float goal_height = goal.diagonal().dot(goal.new Vec(0, 1, 0)); + float goal_depth = goal.diagonal().dot(goal.new Vec(0, 0, 1)); float width = (float)0.6; float height = (float)0.08; float depth = (float)0.3; translations = new Geom.M[] { - tile.new M(tile.new V(-(width/2), height, 0)), - tile.new M(tile.new V( (width/2), height, 0)), - tile.new M(tile.new V(-(width/2), -height, 0)), - tile.new M(tile.new V( (width/2), -height, 0)), - tile.new M(tile.new V(-(width/2), 0, depth)), - tile.new M(tile.new V( (width/2), 0, depth)), - tile.new M(tile.new V(-(width/2), 0, -depth)), - tile.new M(tile.new V( (width/2), 0, -depth)), - - tile.new M(tile.new V( width, 0, 0)), - tile.new M(tile.new V(-width, 0, 0)), + tile.new M(tile.new Vec(-(width/2), height, 0)), + tile.new M(tile.new Vec( (width/2), height, 0)), + tile.new M(tile.new Vec(-(width/2), -height, 0)), + tile.new M(tile.new Vec( (width/2), -height, 0)), + tile.new M(tile.new Vec(-(width/2), 0, depth)), + tile.new M(tile.new Vec( (width/2), 0, depth)), + tile.new M(tile.new Vec(-(width/2), 0, -depth)), + tile.new M(tile.new Vec( (width/2), 0, -depth)), + + tile.new M(tile.new Vec( width, 0, 0)), + tile.new M(tile.new Vec(-width, 0, 0)), /* - tile.new M(tile.new V( 0, 0, depth)), - tile.new M(tile.new V( 0, 0, -depth)), + tile.new M(tile.new Vec( 0, 0, depth)), + tile.new M(tile.new Vec( 0, 0, -depth)), */ }; @@ -221,10 +221,10 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener tile.bind(); - //mid.move(tile.new V((float)0,0,(float)-0.05)); - //ltn.move(tile.new V((float)0,0,(float)-0.05)); + //mid.move(tile.new Vec((float)0,0,(float)-0.05)); + //ltn.move(tile.new Vec((float)0,0,(float)-0.05)); - //mtf.move(tile.new V(0, (float)-0.05, (float)0.05)); + //mtf.move(tile.new Vec(0, (float)-0.05, (float)0.05)); System.out.println("tile volume: " + tile.volume()); @@ -236,7 +236,7 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener Random random = new Random(); public synchronized void breakit() { - if (verts > 20) return; + if (verts > 300) return; //double min = (tile.avgedge/tile.numedges)*(1+(4/(double)verts)); //if (verts>0 && tile.es.peek().length() < min) return; PriorityQueue es = new PriorityQueue(); @@ -261,7 +261,7 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener r1 = r1 - (float)Math.floor(r1); r1 = r1 * (float)0.01; r1 = r1 - (float)0.005; - Geom.V v = p.watchback().minus(p).norm().times(r1); + Geom.Vec v = p.watchback().minus(p).norm().times(r1); //v = p.norm().times(v.dot(p.norm())); @@ -350,7 +350,7 @@ public class Main implements GLEventListener, MouseListener, MouseMotionListener i++; if (i != 1 /*&& i!=4*/) continue; Geom.P p = tile.newP(0, 0, 0).times(m); - Geom.V v = tile.new V(p.x, p.y, p.z); + Geom.Vec v = tile.new Vec(p.x, p.y, p.z); v = v.times((float)1.04); gl.glTranslatef(v.x, v.y, v.z); draw(gl, false, tile);