[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Edge.java,1.35,1.36
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-02-17 14:45:44
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21403/src/net/sourceforge/bprocessor/model Modified Files: Edge.java Log Message: New hit-detection algorithm Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** Edge.java 16 Feb 2006 21:04:53 -0000 1.35 --- Edge.java 17 Feb 2006 14:45:24 -0000 1.36 *************** *** 399,403 **** t = (q.getZ() - p0.getZ()) / r.getZ(); } ! if (t > 0 && t < 1) { r.scale(t); Vertex p = p0.add(r).minus(q); --- 399,403 ---- t = (q.getZ() - p0.getZ()) / r.getZ(); } ! if ((t > 0 && t < 1)) { r.scale(t); Vertex p = p0.add(r).minus(q); *************** *** 410,413 **** --- 410,440 ---- /** + * Tests if the vertex intersects with this Edge + * @param vertex The vertex + * @return The answer + */ + public boolean intersects(Vertex vertex) { + Vertex p0 = getFrom(); + Vertex p1 = getTo(); + Vertex r = p1.minus(p0); + Vertex q = vertex; + double t = 0.0; + + if (Math.abs(r.getX()) > 0.0000001) { + t = (q.getX() - p0.getX()) / r.getX(); + } else if (Math.abs(r.getY()) > 0.0000001) { + t = (q.getY() - p0.getY()) / r.getY(); + } else if (Math.abs(r.getZ()) > 0.0000001) { + t = (q.getZ() - p0.getZ()) / r.getZ(); + } + r.scale(t); + Vertex p = p0.add(r).minus(q); + if (p.length() < 0.0000001) { + return true; + } + return false; + } + + /** * Gets a vector representing the direction of the edge. * From the "from" point and to the "to" point |