Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv31164/src/net/sourceforge/bprocessor/model
Modified Files:
Surface.java
Log Message:
revival of old normal calculation
Index: Surface.java
===================================================================
RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v
retrieving revision 1.201
retrieving revision 1.202
diff -C2 -d -r1.201 -r1.202
*** Surface.java 12 Nov 2007 12:36:13 -0000 1.201
--- Surface.java 12 Nov 2007 13:29:35 -0000 1.202
***************
*** 1512,1516 ****
public Vertex normal() {
! return normal0(edges);
}
--- 1512,1516 ----
public Vertex normal() {
! return normal1(edges);
}
***************
*** 1614,1617 ****
--- 1614,1709 ----
return new Vertex(x, y, z);
}
+
+ /**
+ * @param edges edges
+ * @return value
+ */
+ public static Vertex normal1(Collection<Edge> edges) {
+ int size = edges.size();
+ Edge[] e = new Edge[size];
+ double[] xs = new double[size];
+ double[] ys = new double[size];
+ double[] zs = new double[size];
+ final double eps = 0.0000000001;
+ edges.toArray(e);
+ Edge e0 = e[0];
+ Edge e1 = e[1];
+ Vertex current;
+ if (e0.to == e1.from || e0.to == e1.to) {
+ current = e0.from;
+ } else {
+ current = e0.to;
+ }
+ for (int i = 0; i < e.length; i++) {
+ xs[i] = current.x;
+ ys[i] = current.y;
+ zs[i] = current.z;
+ if (current == e[i].from) {
+ current = e[i].to;
+ } else {
+ current = e[i].from;
+ }
+ }
+ double vx = xs[1] - xs[0];
+ double vy = ys[1] - ys[0];
+ double vz = zs[1] - zs[0];
+ double x = 0.0;
+ double y = 0.0;
+ double z = 0.0;
+ for (int i = 2; i < e.length; i++) {
+ double ux = xs[i] - xs[i - 1];
+ double uy = ys[i] - ys[i - 1];
+ double uz = zs[i] - zs[i - 1];
+ x = Math.abs(vy * uz - vz * uy);
+ y = Math.abs(vz * ux - vx * uz);
+ z = Math.abs(vx * uy - vy * ux);
+ if (x > eps || y > eps || z > eps) {
+ break;
+ }
+ }
+ double[] coord;
+ if (y > x) {
+ if (y > z) {
+ coord = xs;
+ } else {
+ coord = ys;
+ }
+ } else {
+ if (x > z) {
+ coord = zs;
+ } else {
+ coord = ys;
+ }
+ }
+ double min = Double.MAX_VALUE;
+ int inx1 = -1;
+ for (int i = 0; i < e.length; i++) {
+ if (coord[i] <= min) {
+ inx1 = i;
+ min = coord[i];
+ }
+ }
+ int inx0 = inx1 == 0 ? e.length - 1 : inx1 - 1;
+ int inx2 = (inx1 + 1) % e.length;
+
+ vx = xs[inx1] - xs[inx0];
+ vy = ys[inx1] - ys[inx0];
+ vz = zs[inx1] - zs[inx0];
+
+ double ux = xs[inx2] - xs[inx1];
+ double uy = ys[inx2] - ys[inx1];
+ double uz = zs[inx2] - zs[inx1];
+
+ x = vy * uz - vz * uy;
+ y = vz * ux - vx * uz;
+ z = vx * uy - vy * ux;
+ double length = Math.sqrt(x * x + y * y + z * z);
+ x = x / length;
+ y = y / length;
+ z = z / length;
+
+ return new Vertex(x, y, z);
+ }
+
/**
|