public double score = 0;
public float score() { return (float)score; }
+ public void unbind() {
+
+ for(Geom.T t : this) {
+ t.p1().unbind();
+ t.p2().unbind();
+ t.p3().unbind();
+ }
+
+ }
+ public void bind() {
+ for(Geom.T t : this) {
+ t.e1().dobind();
+ t.e2().dobind();
+ t.e3().dobind();
+ }
+ }
+ public int numedges = 0;
+ public float avgedge = 0;
+
public float rescore() {
int num = 0;
double dist = 0;
return ret;
}
+ public class BindingGroup {
+ public HashSet<E> es = new HashSet<E>();
+ public BindingGroup() { }
+ public BindingGroup(E e) {
+ es.add(e);
+ }
+ public void add(E e) {
+ if (e.bg != null) { merge(e.bg); return; }
+ es.add(e);
+ e.bg = this;
+ }
+ public void merge(BindingGroup bg) {
+ for(E e : bg.es) {
+ e.bg = null;
+ add(e);
+ }
+ }
+ }
+
public final class V {
public P p;
public V(P p) {
if (ps.get(p) != null) throw new Error();
ps.put(this.p, this);
}
- public int hashCode() {
- throw new Error();
- }
public void kdremove() {
if (!inserted) return;
inserted = false;
}
public V partner() { return watch==null ? this : watch; }
public V watchback() { return watch_count==0 ? partner() :
- new P(watch_x/watch_count, watch_y/watch_count, watch_z/watch_count).register(); }
+ register(new P(watch_x/watch_count, watch_y/watch_count, watch_z/watch_count)); }
public void rescore() {
if (score_against == null) return;
} while(e != this.e);
return norm.norm();
}
- V bound_to = this;
+ V bound_to = this;
int watch_count;
float watch_x;
float watch_y;
boolean inserted = false;
}
- public class P {
- float x, y, z;
- public P(double x, double y, double z) { this((float)x, (float)y, (float)z); }
- public P(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
- public float distance(P p) { return distance(p.x, p.y, p.z); }
- public float distance(float ox, float oy, float oz) { return (float)Math.sqrt((x-ox)*(x-ox)+(y-oy)*(y-oy)+(z-oz)*(z-oz)); }
- public V register() { V v = ps.get(this); return v==null ? new V(this) : v; }
- public P times(M m) { return m.times(this); }
- public Vec minus(P p) { return new Vec(x-p.x, y-p.y, z-p.z); }
- public P plus(Vec v) { return new P(x+v.x, y+v.y, z+v.z); }
- public boolean equals(Object o) { return o!=null && (o instanceof P) && ((P)o).x==x && ((P)o).y==y && ((P)o).z==z; }
- public void glVertex(GL gl) { _glVertex(gl); }
- private void _glVertex(GL gl) { gl.glVertex3f(x, y, z); }
- public String toString() { return "("+x+","+y+","+z+")"; }
- // FIXME: moving a point alters its hashCode
- public int hashCode() {
- return
- Float.floatToIntBits(x) ^
- Float.floatToIntBits(y) ^
- Float.floatToIntBits(z);
- }
- }
-
- /** vector in 3-space */
- public final class Vec {
- public final float x, y, z;
- 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(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+">"; }
- }
-
- public class BindingGroup {
- public HashSet<E> es = new HashSet<E>();
- public BindingGroup() { }
- public BindingGroup(E e) {
- es.add(e);
- }
- public void add(E e) {
- if (e.bg != null) { merge(e.bg); return; }
- es.add(e);
- e.bg = this;
- }
- public void merge(BindingGroup bg) {
- for(E e : bg.es) {
- e.bg = null;
- add(e);
- }
- }
- }
-
/** [UNIQUE] an edge */
public final class E implements Comparable<E> {
}
boolean shattered = false;
- public V shatter() { return shatter(midpoint().register(), null, null); }
+ public V shatter() { return shatter(register(midpoint()), null, null); }
public V shatter(V mid, BindingGroup bg1, BindingGroup bg2) {
if (shattered) return mid;
shattered = true;
if (bg1==null) bg1 = new BindingGroup();
if (bg2==null) bg2 = new BindingGroup();
- for(E e : bg.es) e.shatter(e.midpoint().register(), bg1, bg2);
+ for(E e : bg.es) e.shatter(register(e.midpoint()), bg1, bg2);
pair.shatter();
destroy();
}
+
+ public V register(P p) { V v = ps.get(p); return v==null ? new V(p) : v; }
+
+ //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+ /** point in 3-space; immutable */
+ public static final class P {
+ public final float x, y, z;
+ public P(double x, double y, double z) { this((float)x, (float)y, (float)z); }
+ public P(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
+ public float distance(P p) { return distance(p.x, p.y, p.z); }
+ public float distance(float ox, float oy, float oz) { return (float)Math.sqrt((x-ox)*(x-ox)+(y-oy)*(y-oy)+(z-oz)*(z-oz)); }
+ public P times(M m) { return m.times(this); }
+ public Vec minus(P p) { return new Vec(x-p.x, y-p.y, z-p.z); }
+ public P plus(Vec v) { return new P(x+v.x, y+v.y, z+v.z); }
+ public boolean equals(Object o) { return o!=null && (o instanceof P) && ((P)o).x==x && ((P)o).y==y && ((P)o).z==z; }
+ public void glVertex(GL gl) { _glVertex(gl); }
+ private void _glVertex(GL gl) { gl.glVertex3f(x, y, z); }
+ public String toString() { return "("+x+","+y+","+z+")"; }
+ public int hashCode() { return Float.floatToIntBits(x) ^ Float.floatToIntBits(y) ^ Float.floatToIntBits(z); }
+ }
+ /** vector in 3-space; immutable */
+ public static final class Vec {
+ public final float x, y, z;
+ 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(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+">"; }
+ }
- /** matrix */
- public class M {
+ /** affine matrix */
+ public static class M {
//
// [ a b c d ] [ x ]
// [ e f g h ] [ y ]
public M times(M m) { return this; }
}
- public void unbind() {
-
- for(Geom.T t : this) {
- t.p1().unbind();
- t.p2().unbind();
- t.p3().unbind();
- }
-
- }
- public void bind() {
- for(Geom.T t : this) {
- t.e1().dobind();
- t.e2().dobind();
- t.e3().dobind();
- }
- }
- public int numedges = 0;
- public float avgedge = 0;
}
public Main(StlFile stlf) {
for(int i=0; i<stlf.coordArray.length; i+=3) {
- Geom.V p0 = goal.new P(stlf.coordArray[i+0].x * MAG, stlf.coordArray[i+0].y * MAG, stlf.coordArray[i+0].z * MAG).register();
- Geom.V p1 = goal.new P(stlf.coordArray[i+1].x * MAG, stlf.coordArray[i+1].y * MAG, stlf.coordArray[i+1].z * MAG).register();
- Geom.V p2 = goal.new P(stlf.coordArray[i+2].x * MAG, stlf.coordArray[i+2].y * MAG, stlf.coordArray[i+2].z * MAG).register();
- 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.V p0 = goal.register(new Geom.P(stlf.coordArray[i+0].x * MAG, stlf.coordArray[i+0].y * MAG, stlf.coordArray[i+0].z * MAG));
+ Geom.V p1 = goal.register(new Geom.P(stlf.coordArray[i+1].x * MAG, stlf.coordArray[i+1].y * MAG, stlf.coordArray[i+1].z * MAG));
+ Geom.V p2 = goal.register(new Geom.P(stlf.coordArray[i+2].x * MAG, stlf.coordArray[i+2].y * MAG, stlf.coordArray[i+2].z * MAG));
+ Geom.Vec n = new Geom.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 Vec(0, 0, 1), (float)(Math.PI/2)));
+ goal.transform(new Geom.M(new Geom.Vec(0, 0, 1), (float)(Math.PI/2)));
- 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 goal_width = goal.diagonal().dot(new Geom.Vec(1, 0, 0));
+ float goal_height = goal.diagonal().dot(new Geom.Vec(0, 1, 0));
+ float goal_depth = goal.diagonal().dot(new Geom.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 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)),
+ new Geom.M(new Geom.Vec(-(width/2), height, 0)),
+ new Geom.M(new Geom.Vec( (width/2), height, 0)),
+ new Geom.M(new Geom.Vec(-(width/2), -height, 0)),
+ new Geom.M(new Geom.Vec( (width/2), -height, 0)),
+ new Geom.M(new Geom.Vec(-(width/2), 0, depth)),
+ new Geom.M(new Geom.Vec( (width/2), 0, depth)),
+ new Geom.M(new Geom.Vec(-(width/2), 0, -depth)),
+ new Geom.M(new Geom.Vec( (width/2), 0, -depth)),
+
+ new Geom.M(new Geom.Vec( width, 0, 0)),
+ new Geom.M(new Geom.Vec(-width, 0, 0)),
/*
- tile.new M(tile.new Vec( 0, 0, depth)),
- tile.new M(tile.new Vec( 0, 0, -depth)),
+ new Geom.M(new Geom.Vec( 0, 0, depth)),
+ new Geom.M(new Geom.Vec( 0, 0, -depth)),
*/
};
- Geom.V ltf = tile.new P(-(width/2), (height/2), (depth/2)).register();
- Geom.V mtf = tile.new P( 0.0, (height/2), (depth/2)).register();
- Geom.V rtf = tile.new P( (width/2), (height/2), (depth/2)).register();
- Geom.V ltn = tile.new P(-(width/2), (height/2), -(depth/2)).register();
- Geom.V mtn = tile.new P( 0.0, (height/2), -(depth/2)).register();
- Geom.V rtn = tile.new P( (width/2), (height/2), -(depth/2)).register();
- Geom.V lbf = tile.new P(-(width/2), -(height/2), (depth/2)).register();
- Geom.V mbf = tile.new P( 0.0, -(height/2), (depth/2)).register();
- Geom.V rbf = tile.new P( (width/2), -(height/2), (depth/2)).register();
- Geom.V lbn = tile.new P(-(width/2), -(height/2), -(depth/2)).register();
- Geom.V mbn = tile.new P( 0.0, -(height/2), -(depth/2)).register();
- Geom.V rbn = tile.new P( (width/2), -(height/2), -(depth/2)).register();
+ Geom.V ltf = tile.register(new Geom.P(-(width/2), (height/2), (depth/2)));
+ Geom.V mtf = tile.register(new Geom.P( 0.0, (height/2), (depth/2)));
+ Geom.V rtf = tile.register(new Geom.P( (width/2), (height/2), (depth/2)));
+ Geom.V ltn = tile.register(new Geom.P(-(width/2), (height/2), -(depth/2)));
+ Geom.V mtn = tile.register(new Geom.P( 0.0, (height/2), -(depth/2)));
+ Geom.V rtn = tile.register(new Geom.P( (width/2), (height/2), -(depth/2)));
+ Geom.V lbf = tile.register(new Geom.P(-(width/2), -(height/2), (depth/2)));
+ Geom.V mbf = tile.register(new Geom.P( 0.0, -(height/2), (depth/2)));
+ Geom.V rbf = tile.register(new Geom.P( (width/2), -(height/2), (depth/2)));
+ Geom.V lbn = tile.register(new Geom.P(-(width/2), -(height/2), -(depth/2)));
+ Geom.V mbn = tile.register(new Geom.P( 0.0, -(height/2), -(depth/2)));
+ Geom.V rbn = tile.register(new Geom.P( (width/2), -(height/2), -(depth/2)));
points = new Geom.V[] {
ltf,
// rescale to match volume
float factor = (float)Math.pow(tile.volume() / goal.volume(), 1.0/3.0);
- goal.transform(goal.new M(factor));
+ goal.transform(new Geom.M(factor));
// translate to match centroid
- goal.transform(goal.new M(tile.centroid().minus(goal.centroid())));
+ goal.transform(new Geom.M(tile.centroid().minus(goal.centroid())));
//tx.e2.shatter();
//tx.e3.shatter();
tile.bind();
- //mid.move(tile.new Vec((float)0,0,(float)-0.05));
- //ltn.move(tile.new Vec((float)0,0,(float)-0.05));
+ //mid.move(new Geom.Vec((float)0,0,(float)-0.05));
+ //ltn.move(new Geom.Vec((float)0,0,(float)-0.05));
- //mtf.move(tile.new Vec(0, (float)-0.05, (float)0.05));
+ //mtf.move(new Geom.Vec(0, (float)-0.05, (float)0.05));
System.out.println("tile volume: " + tile.volume());
if (aspect) {
/*
v = v.times(10);
- tile.aspect = tile.new M(tile.aspect.a / (v.x+1), tile.aspect.f / (v.y+1), tile.aspect.k / (v.z+1));
- tile.invaspect = tile.new M(1/tile.aspect.a, 1/tile.aspect.f, 1/tile.aspect.k);
+ tile.aspect = new Geom.M(tile.aspect.a / (v.x+1), tile.aspect.f / (v.y+1), tile.aspect.k / (v.z+1));
+ tile.invaspect = new Geom.M(1/tile.aspect.a, 1/tile.aspect.f, 1/tile.aspect.k);
goal.rescore();
tile.rescore();
*/
} else {
if (aspect) {
//tile.aspect = old_tile_aspect;
- //tile.invaspect = tile.new M(1/tile.aspect.a, 1/tile.aspect.f, 1/tile.aspect.k);
+ //tile.invaspect = new Geom.M(1/tile.aspect.a, 1/tile.aspect.f, 1/tile.aspect.k);
goal.rescore();
tile.rescore();
} else {
//if (v1.z==0 && v1.y==0) continue;
i++;
if (i != 1 /*&& i!=4*/) continue;
- Geom.V p = tile.new P(0, 0, 0).times(m).register();
- Geom.Vec v = tile.new Vec(p.p.x, p.p.y, p.p.z);
+ Geom.P p = new Geom.P(0, 0, 0).times(m);
+ Geom.Vec v = new Geom.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);
gl.glEnd();
}
- Geom.V centroid = t.centroid().register();
+ Geom.P centroid = t.centroid();
gl.glBegin(GL.GL_LINES);
gl.glColor3f(1, 1, 1);
/*