private HashMap<P,P> ps = new HashMap<P,P>();
private HashMap<E,E> es = new HashMap<E,E>();
- private HashSet<T> ts = new HashSet<T>();
+ private HashSet<T> ts = new HashSet<T>();
public Iterator<T> iterator() { return ts.iterator(); }
return new T(e1, e2, e3);
}
- /** point in 3-space */
+ /** [UNIQUE] point in 3-space */
public final class P {
public final float x, y, z;
public P(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
- public V minus(P p) { return null; }
+ public V minus(P p) { return new V(x-p.x, y-p.y, z-p.z); }
public boolean equals(Object o) {
if (o==null || !(o instanceof P)) return false;
P p = (P)o;
public final class V {
private final float x, y, z;
public V(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
- public V norm() { return null; /* FIXME */ }
public boolean sameDirection(V v) { throw new Error(); }
- public V cross(V v) { return null; }
+ 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 float mag() { return (float)Math.sqrt(x*x+y*y+z*z); }
+ public V norm() { float m = mag(); return new V(x/m, y/m, z/m); }
}
- /** an edge */
+ /** [UNIQUE] an edge */
public final class E {
public final P p1, p2;
T t1, t2;
}
}
- /** a triangle (face) */
+ /** [UNIQUE] a triangle (face) */
public final class T {
public final E e1, e2, e3;
public T(E e1, E e2, E e3, V normal) {
ts.add(this);
}
public boolean hasE(E e) { return e1==e || e2==e || e3==e; }
-
- // technically not required
- /*
- public int hashCode() { return e1.hashCode() ^ e2.hashCode() ^ e3.hashCode(); }
- public boolean equals(Object o) {
- if (o==null || !(o instanceof T)) return false;
- T t = (T)o;
- if (this.e1 == t.e1 && this.e2 == t.e2 && this.e3 == t.e3) return true;
- if (this.e1 == t.e2 && this.e2 == t.e3 && this.e3 == t.e1) return true;
- if (this.e1 == t.e3 && this.e2 == t.e1 && this.e3 == t.e2) return true;
- return false;
- }
- */
public void glVertices(GL gl) {
e1.unshared(e2).glVertex(gl);
e1.shared(e2).glVertex(gl);
public Main(StlFile stlf) {
for(int i=0; i<stlf.coordArray.length; i+=3) {
- Geom.P p0 = geom.newP(stlf.coordArray[i+0].x,
- stlf.coordArray[i+0].y,
- stlf.coordArray[i+0].z);
- Geom.P p1 = geom.newP(stlf.coordArray[i+1].x,
- stlf.coordArray[i+1].y,
- stlf.coordArray[i+1].z);
- Geom.P p2 = geom.newP(stlf.coordArray[i+2].x,
- stlf.coordArray[i+2].y,
- stlf.coordArray[i+2].z);
- Geom.T t = geom.newT(geom.newE(p0, p1),
- geom.newE(p1, p2),
- geom.newE(p2, p0));
+ Geom.P p0 = geom.newP(stlf.coordArray[i+0].x, stlf.coordArray[i+0].y, stlf.coordArray[i+0].z);
+ Geom.P p1 = geom.newP(stlf.coordArray[i+1].x, stlf.coordArray[i+1].y, stlf.coordArray[i+1].z);
+ Geom.P p2 = geom.newP(stlf.coordArray[i+2].x, stlf.coordArray[i+2].y, stlf.coordArray[i+2].z);
+ Geom.T t = geom.newT(geom.newE(p0, p1), geom.newE(p1, p2), geom.newE(p2, p0));
}
}
display(gld);
}
- /**
- * Take care of drawing here.
- */
+ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
+ public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { }
public void display(GLAutoDrawable drawable) {
float red = 0.0f;
float green = 0.0f;
gl.glEnd();
}
}
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
- public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) { }
-
public static void main(String[] s) throws Exception {
StlFile stlf = new StlFile();