[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Edge.java, 1.69, 1.70 Vertex.java, 1
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Michael L. <he...@us...> - 2007-01-05 13:54:56
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv9923/src/net/sourceforge/bprocessor/model Modified Files: Edge.java Vertex.java Surface.java Geometry.java Persistence.java Log Message: Implemented a new normal computation function Changed Vertex.toString() to round values to get rid of -0 etc. Index: Surface.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v retrieving revision 1.128 retrieving revision 1.129 diff -C2 -d -r1.128 -r1.129 *** Surface.java 2 Jan 2007 17:48:58 -0000 1.128 --- Surface.java 5 Jan 2007 13:54:47 -0000 1.129 *************** *** 1399,1402 **** --- 1399,1493 ---- return Geometry.normal(getVertices()); } + + /** + * + * @return value + */ + public Vertex normal0() { + 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); + } /** Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** Edge.java 2 Jan 2007 17:48:58 -0000 1.69 --- Edge.java 5 Jan 2007 13:54:47 -0000 1.70 *************** *** 36,43 **** /** The start vertex */ ! private Vertex from; /** The end vertex */ ! private Vertex to; /** Constructor */ --- 36,43 ---- /** The start vertex */ ! protected Vertex from; /** The end vertex */ ! protected Vertex to; /** Constructor */ Index: Vertex.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Vertex.java,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** Vertex.java 2 Jan 2007 17:48:58 -0000 1.53 --- Vertex.java 5 Jan 2007 13:54:47 -0000 1.54 *************** *** 33,43 **** /** The x coordinate */ ! private double x; /** The y coordinate */ ! private double y; /** The z coordinate */ ! private double z; /** --- 33,43 ---- /** The x coordinate */ ! protected double x; /** The y coordinate */ ! protected double y; /** The z coordinate */ ! protected double z; /** *************** *** 402,407 **** */ public String toString() { ! return getName() + "[" + x + ", " + y + ! ", " + z + "]"; } --- 402,410 ---- */ public String toString() { ! return getName() + ! "[" + Geometry.round(x) + ! ", " + Geometry.round(y) + ! ", " + Geometry.round(z) + ! "]"; } Index: Geometry.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Geometry.java,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** Geometry.java 2 Jan 2007 18:30:33 -0000 1.41 --- Geometry.java 5 Jan 2007 13:54:47 -0000 1.42 *************** *** 22,29 **** */ public class Geometry { - - /** The logger */ private static Logger log = Logger.getLogger(Geometry.class); /** * Find all edges in given space and all its subspaces that are active parts, --- 22,43 ---- */ public class Geometry { private static Logger log = Logger.getLogger(Geometry.class); + /** Epsilon value used to judge if a double value considered zero */ + public static final double EPS = 0.0000000001; + + /** + * + * @param value double + * @return rounded value + */ + public static double round(double value) { + double factor = 10000000000.0; + double d = value * factor; + long l = Math.round(d); + double result = (double) l / factor; + return result; + } + /** * Find all edges in given space and all its subspaces that are active parts, *************** *** 451,453 **** --- 465,475 ---- } } + + /** + * Display info on the log + * @param object An object to print as info on the log + */ + public static void info(Object object) { + log.info(object); + } } Index: Persistence.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Persistence.java,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** Persistence.java 18 Dec 2006 09:11:47 -0000 1.29 --- Persistence.java 5 Jan 2007 13:54:48 -0000 1.30 *************** *** 1058,1074 **** } - - /** - * - * @param value double - * @return rounded value - */ - private static double round(double value) { - double factor = 10000000000.0; - double d = value * factor; - long l = Math.round(d); - return (double) l / factor; - } - /** * Create an xml VertexImpl and place it in the map --- 1058,1061 ---- *************** *** 1084,1090 **** } map.put(vertex, xml); ! xml.setX(round(vertex.getX())); ! xml.setY(round(vertex.getY())); ! xml.setZ(round(vertex.getZ())); return xml; } --- 1071,1077 ---- } map.put(vertex, xml); ! xml.setX(Geometry.round(vertex.getX())); ! xml.setY(Geometry.round(vertex.getY())); ! xml.setZ(Geometry.round(vertex.getZ())); return xml; } |