public void addFace(Vertex[] vertices) { HalfEdge[] currentHalfEdges = new HalfEdge[vertices.Length]; //add halfedges for (int curr = 0; curr < vertices.Length; curr++) { int next_he = (curr + 1) % vertices.Length; // look if half-edge already exists HalfEdge exist = existHalfEdge(vertices[curr], vertices[next_he]); // if it does, add it to the array, otherwise create it if (exist == null) { // create half edge from current to next vertex currentHalfEdges[curr] = new HalfEdge(vertices[curr], vertices[next_he]); HalfEdge twin = new HalfEdge(vertices[next_he],vertices[curr]); currentHalfEdges[curr].twin = twin; twin.twin = currentHalfEdges[curr]; // add halfedge to polynet halfedges dictionary this.halfEdges.Add(vertices[curr], vertices[next_he], currentHalfEdges[curr]); this.halfEdges.Add(vertices[next_he], vertices[curr], twin); } else { currentHalfEdges[curr] = exist; } } // create face with some halfedge Face face = new Face(currentHalfEdges[0]); // calculate face's normal face.normal = faceNormal(vertices); // add face to faces list faces.Add(face); // link halfedges with next and prev for(int i = 0; i < currentHalfEdges.Length; i++){ int next = (i + 1) % currentHalfEdges.Length; int prev = (currentHalfEdges.Length + i - 1) % currentHalfEdges.Length; currentHalfEdges[i].next = currentHalfEdges[next]; currentHalfEdges[i].prev = currentHalfEdges[prev]; // link face to halfedge currentHalfEdges[i].face = face; } }
public Face(HalfEdge halfEdge) { this.halfEdge = halfEdge; }