public static boolean addOne(Vertex p) { boolean visible = false; // mark from p visible faces QueueElement<Face> wf = ConvexHull.faces.getFirst(); while (wf.getNext() != null) { Face f = wf.getElem(); if (volume(f, p) < 0) { f.visible = true; visible = true; } wf = wf.getNext(); } // no faces visible, p is inside of hull if (!visible) { p.onhull = false; return false; } QueueElement<Edge> we = ConvexHull.edges.getFirst(); while (we.getNext() != null) { Edge e = we.getElem(); if (e.getAdjface(0).visible && e.getAdjface(1).visible) { e.deleted = true; } else { if (e.getAdjface(0).visible || e.getAdjface(1).visible) { e.newface = makeStructs(e, p); } } we = we.getNext(); } return true; }
public static void constructHull() { QueueElement<Vertex> v = ConvexHull.vertices.getFirst(); { if (!v.getElem().getMark()) { v.getElem().setMark(true); addOne(v.getElem()); Cleaning.cleanUp(); } v = v.getNext(); } while (v != ConvexHull.vertices.getFirst()) ; }
public static void buildTetrahedron() { QueueElement<Vertex> v0; QueueElement<Vertex> v3; int volume; // find 3 noncollinear points v0 = ConvexHull.vertices.getFirst(); while (collinear(v0.getElem(), v0.getNext().getElem(), v0.getNext().getNext().getElem())) { v0 = v0.getNext(); if (v0.getNext() == ConvexHull.vertices.getFirst()) { System.err.println("All points are collinear"); System.exit(0); } } // mark vertices as processed v0.getElem().setMark(true); v0.getNext().getElem().setMark(true); v0.getNext().getNext().getElem().setMark(true); Edge e0 = Edge.makeEdge(v0.getElem(), v0.getNext().getElem()); Edge e1 = Edge.makeEdge(v0.getNext().getElem(), v0.getNext().getNext().getElem()); Edge e2 = Edge.makeEdge(v0.getNext().getNext().getElem(), v0.getElem()); Face f = Face.makeFace(e0, e1, e2); f.setVertices(v0.getElem(), v0.getNext().getElem(), v0.getNext().getNext().getElem()); e0.setAdjface(0, f); e1.setAdjface(0, f); e1.setAdjface(0, f); // try to find another noncollinear vertex v3 = v0.getNext().getNext().getNext(); volume = volume(f, v3.getElem()); while (volume == 0) { v3 = v3.getNext(); if (v3 == ConvexHull.vertices.getFirst()) { System.err.println("All points are coplanar"); System.exit(0); } volume = volume(f, v3.getElem()); } v3.getElem().setMark(true); // store vertices in ccw order if (volume < 0) { swap(f.getVertex(1), f.getVertex(2)); swap(f.getEdge(1), f.getEdge(2)); } e0.setAdjface(1, makeStructs(e0, v3.getElem())); e1.setAdjface(1, makeStructs(e1, v3.getElem())); e2.setAdjface(1, makeStructs(e2, v3.getElem())); Cleaning.cleanUp(); }