return new Polygon(plane, newHalfSpaces);
}
+ private static final float EPSILON = 0.00001f;
+ private static float round(float f) {
+ return Math.round(f*1000)/1000f;
+ }
public Triangle[] tesselate(Mesh mesh) {
// FIXME: check for closedness
// find a starting point
if (i==j) continue;
Point p = plane.intersect(halfSpaces[i], halfSpaces[j]);
if (p==null) continue;
+
+ //p = new Point(round(p.x), round(p.y), round(p.z));
+
for(int k=0; k<halfSpaces.length; k++) {
if (i==k || j==k) continue;
- //if (!halfSpaces[k].contains(p)) { p = null; break; }
+ if (!halfSpaces[k].contains(p, 0.0001f)) { p = null; break; }
}
if (p!=null) {
if (p1==null) p1 = p;
- else if (p2==null) { if (!p.equals(p1)) p2 = p; }
- else throw new Error();
+ else if (p2==null) { if (p.distance(p1)>EPSILON) p2 = p; }
+ else if (p.distance(p1)>EPSILON && p.distance(p2)>EPSILON) throw new Error("three points! " + p + " " + p1 + " " + p2);
}
}
if (p1!=null && p2!=null) {
- System.out.println("new segment: " + p1 + " " + p2);
+ //System.out.println("new segment: " + p1 + " " + p2);
segments.add(new Segment(p1, p2));
}
}
Vec cen = new Vec(0,0,0);
for(Segment s : segments)
- cen = cen.plus(s.p1.minus(Point.ORIGIN)).plus(s.p2.minus(Point.ORIGIN));
- Point centroid = Point.ORIGIN.plus(cen.times(1f/(2*segments.size())));
+ cen = cen.plus(s.p1.minus(Point.ZERO)).plus(s.p2.minus(Point.ZERO));
+ Point centroid = Point.ZERO.plus(cen.times(1f/(2*segments.size())));
+ //centroid = new Point(round(centroid.x), round(centroid.y), round(centroid.z));
+ if (segments.size() >= 3)
for(Segment s : segments) {
- System.out.println("newt! " + s.p1 + " " + centroid + " " + s.p2 + " " + plane.norm.times(-1));
- mesh.newT(s.p1, centroid, s.p2, plane.norm.times(-1), 0);
+ System.out.println("newt! " + s.p1 + " " + centroid + " " + s.p2 + " " + plane.norm().times(-1));
+ mesh.newT(s.p1, centroid, s.p2, plane.norm().times(-1), 0);
}
System.out.println("done");
return null;