public static float EPSILON = (float)0.0001;
public static Random random = new Random();
- private HashMap<P,P> ps = new HashMap<P,P>();
- //public PriorityQueue<E> es = new PriorityQueue<E>();
- public HashSet<E> es = new HashSet<E>();
- //private HashSet<T> ts = new HashSet<T>();
- public ArrayList<T> ts = new ArrayList<T>();
+ private HashMap<P,P> ps = new HashMap<P,P>();
+ public HashSet<E> es = new HashSet<E>();
+ public ArrayList<T> ts = new ArrayList<T>();
public Iterator<T> iterator() { return ts.iterator(); }
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;
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() {
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; }
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;
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;
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;
}
*/
return good;
}
- public boolean move(V v) {
+ public boolean move(Vec v) {
M m = new M(v);
P p = this;
boolean good = true;
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;
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()));
}
/** 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+">"; }
}
/** 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()));
}
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) {
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;
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;
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; }
}
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)),
*/
};
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());
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<Geom.E> es = new PriorityQueue<Geom.E>();
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()));
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);