Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17986
Modified Files:
Surface.java
Log Message:
method for calculating if a vertex is inside the surface
Index: Surface.java
===================================================================
RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** Surface.java 17 Nov 2005 18:10:25 -0000 1.46
--- Surface.java 18 Nov 2005 12:15:44 -0000 1.47
***************
*** 451,455 ****
surface.move(dx, dy, dz);
}
! }
}
--- 451,455 ----
surface.move(dx, dy, dz);
}
! }
}
***************
*** 469,472 ****
--- 469,473 ----
//this can not happen so here we move the inner surface back
{
+ log.info("contained check fejlede");
List vertices = getVertices();
Vertex v0 = (Vertex) vertices.get(0);
***************
*** 507,515 ****
*/
private boolean containedCheck(Surface hole, Surface surf) {
/*this is done by aplying the crossing numbers algorithm on every vertex
*of the hole. Using the edges of the hole as rays we cover two vertecies
*at a time.
*/
! //log.info("contained check");
List holeEdges = hole.getEdges();
Iterator holeIt = holeEdges.iterator();
--- 508,525 ----
*/
private boolean containedCheck(Surface hole, Surface surf) {
+ Iterator vertIt = hole.getVertices().iterator();
+ boolean contained = true;
+ while (vertIt.hasNext() && contained) {
+ contained = surf.surrounds((Vertex)vertIt.next());
+ }
+ return contained;
+ }
+
+ //private boolean containedCheck(Surface hole, Surface surf) {
/*this is done by aplying the crossing numbers algorithm on every vertex
*of the hole. Using the edges of the hole as rays we cover two vertecies
*at a time.
*/
! /*
List holeEdges = hole.getEdges();
Iterator holeIt = holeEdges.iterator();
***************
*** 530,534 ****
}
return contained;
! }
/**
--- 540,545 ----
}
return contained;
! }*/
!
/**
***************
*** 539,543 ****
*/
private boolean crossingNumbers(Edge edge, Surface surf) {
- //log.info("crossing numbers");
List surfEdges = surf.getEdges();
Iterator surfIt = surfEdges.iterator();
--- 550,553 ----
***************
*** 796,799 ****
--- 806,877 ----
return edges.contains(e);
}
+ /**
+ * Tells whether or not a Vertex is contained inside the surface.
+ * @param v the vertex
+ * @return boolean whether or not the vertex is surrounded by the surface.
+ */
+ public boolean surrounds(Vertex v) {
+ CoordinateSystem cs = this.coordinateSystem();
+ Vertex lv = cs.translate(v);
+ /*
+ This is when the vertex is not in the same plane as
+ this surface
+ */
+ if (lv.getZ() > 0.00001) {
+ return false;
+ } else {
+ /*
+ The crossing numbers algorithm but simplyfied by translating
+ points to the local coordinates of the surface plane.
+ */
+ Iterator ei = edges.iterator();
+ int count = 0;
+ while (ei.hasNext()) {
+ Edge e = (Edge)ei.next();
+ Vertex t = cs.translate(e.getTo());
+ Vertex f = cs.translate(e.getFrom());
+ boolean cross = false;
+ if (t.getY() > lv.getY() &&
+ f.getY() < lv.getY()) {
+ cross = true;
+ } else if (t.getY() < lv.getY() &&
+ f.getY() > lv.getY()) {
+ cross = true;
+ }
+ /*
+ Making sure only to count crossings to the right
+ of v.
+ */
+ if (cross) {
+ Vertex dir = t.minus(f);
+ if (!(dir.getY() == 0)) {
+ double p = ((lv.getY() - t.getY())
+ / dir.getY());
+ double pstar = ((dir.getX() * p) + t.getX() - lv.getX());
+ cross = (pstar > 0);
+ }
+ }
+ if (cross) {
+ count++;
+ }
+ }
+ return !(count % 2 == 0);
+ }
+ }
+ /**
+ * Find the intersection point of an endge with this Surface.
+ * If there is no intersectionpoint null is returned.
+ * @param e the edge
+ * @return the vertex at the intersection
+ */
+ public Vertex intersection(Edge e) {
+ Plane p = this.plane();
+ Vertex v = p.intersection(e);
+
+ if (v != null && this.surrounds(v)) {
+ return v;
+ }
+ return null;
+ }
/**
|