Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv3367/src/net/sourceforge/bprocessor/model
Modified Files:
Surface.java
Log Message:
fixed normal calculation bug
Index: Surface.java
===================================================================
RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v
retrieving revision 1.202
retrieving revision 1.203
diff -C2 -d -r1.202 -r1.203
*** Surface.java 12 Nov 2007 13:29:35 -0000 1.202
--- Surface.java 12 Nov 2007 20:11:51 -0000 1.203
***************
*** 1512,1524 ****
public Vertex normal() {
! return normal1(edges);
}
/**
! * USE normal for the normal
! * @param edges The collection of edges to calculate the normal from
* @return value
*/
! public static Vertex normal0(Collection<Edge> edges) {
int size = edges.size();
Edge[] e = new Edge[size];
--- 1512,1523 ----
public Vertex normal() {
! return normalOf(edges);
}
/**
! * @param edges edges
* @return value
*/
! public static Vertex normalOf(Collection<Edge> edges) {
int size = edges.size();
Edge[] e = new Edge[size];
***************
*** 1563,1567 ****
}
}
-
double[] coord;
if (y > x) {
--- 1562,1565 ----
***************
*** 1587,1687 ****
}
! int inx0 = inx1 == 0 ? e.length - 1 : inx1 - 1;
! int inx2 = (inx1 + 1) % e.length;
!
! for (int i = 0; i < e.length; i++) {
! if (coord[inx1] < coord[(inx2 + i) % e.length]) {
! inx2 = (inx2 + i) % e.length;
! break;
! }
! }
!
! 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);
! }
!
! /**
! * @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;
--- 1585,1598 ----
}
! search:
for (int i = 0; i < e.length; i++) {
if (coord[i] <= min) {
inx1 = i;
min = coord[i];
+ } else {
+ break search;
}
}
+
int inx0 = inx1 == 0 ? e.length - 1 : inx1 - 1;
int inx2 = (inx1 + 1) % e.length;
|