edge to triangle

Apr 1, 2014 at 9:56 AM
Is there any efficient way to get info of edge to adjacent triangles ?

I need to search edge to triangle/triangle to edge information.

Thanks a lot for amazing library.

Apr 1, 2014 at 11:31 AM
Edited Apr 2, 2014 at 4:21 PM
I guess you are using the mesh.Edges property? At the moment, there's no way to get adjacent triangles out of the box. You could add a property to the Edge class (returning an ITraingle or just the corresponding ID) and then set it in the EdgeEnumerator class.

But it's fairly easy to do it by hand (have a look at the Quadratic Elements documentation):
private void ProcessEdges(Mesh mesh)

    // Array storing the 3 vertices of a triangle.
    var verts = new Point[3];

    // Vertices of current edge.
    Point p, q;

    ITriangle neighbor;
    int nid;

    foreach (var tri in mesh.Triangles)
        // Get the vertices of the triangle.
        verts[0] = tri.GetVertex(0);
        verts[1] = tri.GetVertex(1);
        verts[2] = tri.GetVertex(2);

        for (int i = 0; i < 3; i++)
            // The edge opposite to vertex i.
            p = verts[(i + 1) % 3];
            q = verts[(i + 2) % 3];

            // The neighbor opposite to vertex i.
            neighbor = tri.GetNeighbor(i);
            nid = neighbor == null ? -1 : neighbor.ID;

            // Consider each edge only once.
            if ((tri.ID < nid) || (nid < 0))
                // Process edge [p -> q] of triangle "tri", shared with "neighbor"
Apr 2, 2014 at 9:15 AM
I actually need extra properties in Edges. Each edge is either part of 2 triangles or 1 (in on boundary of triangulation). Similarly each triangle has 3 edges as properties.

ID cant be changed once done because I need to look from edge-triangle and triangle-edge relation. I am going though code, but some tips will help greatly.
Apr 2, 2014 at 9:22 AM
one more thing, what do you mean by "// The neighbor opposite of vertex i."? There can be N-number of triangle associated with a vertex. How come 1 or 2 only ?

I hope I am clear.

Thanks again,
Apr 2, 2014 at 11:51 AM
Make sure you understand how Triangle.NET stores its Topology.

The above code (I edited it a bit) clearly shows how you get the edges for each triangle and the corresponding neighbor across an edge. What's left for you is to choose some clever datastructures for fast access to the information you need.