matlabpolyhedra

Find the set of edges of a polyhedron, without duplication


I have a polyhedron which is defined by a series of vertices, which are vectors in R^3, and triangular faces, which are defined by a mapping of the three vertices which define the face.

As an example, here is V and F

V=[-0.8379    0.1526   -0.0429;
   -0.6595   -0.3555    0.0664;
   -0.6066    0.3035    0.2454;
   -0.1323   -0.3591    0.1816;
    0.1148   -0.5169    0.0972;
    0.2875   -0.2619   -0.3980;
    0.2995    0.4483    0.2802;
    0.5233    0.2003   -0.3184;
    0.5382   -0.3219    0.2870;
    0.7498    0.1377    0.1593]

F=[2     3     1;
   7     3     4;
   3     2     4;
   7     9    10;
  10     8     7;
   9     5     6;
   9     8    10;
   1     6     2;
   7     8     1;
   2     6     5;
   8     9     6;
   5     9     4;
   9     7     4;
   4     2     5;
   7     1     3;
   6     1     8]

Euler's formula gives the relationship between face, edges, and vertices

V-E+F = 2

I'm trying to find the unique set of edges of the polyhedron from the vertices. I can already find all edges for each face (3 edges per face and every edge is a member of two adjacent faces) by doing the following

Fa = F(:,1);
Fb = F(:,2);
Fc = F(:,3);


e1=V(Fb,:)-V(Fa,:);
e2=V(Fc,:)-V(Fb,:);
e3=V(Fa,:)-V(Fc,:);

However, this finds all the edges for each face and includes duplicates. An edge, e_i on Face A, is also -e_i on Face B.

Anyone have a good method of finding the unique set of edges (positive and negative directions), or determining a mapping within e1,e2,e3 that links the positive edge to it's negative?


Solution

  • It's better to work with the edges encoded in the same way as the faces are encoded: e.g., [3 7] is an edge between the vertices 3 and 7. From this representation, you can get the coordinates of the vector just by subtracting those vertices.

    Here is a one-line command to get the unique set of edges from F:

    E = unique(sort([F(:,[1,2]); F(:,[1,3]); F(:,[2,3])], 2), 'rows');  
    

    The first argument of sort is a matrix with two columns holding all edges, with duplication. Then it's sorted so that row 7 3 becomes 3 7. Finally, unique returns the unique rows only. Output:

     1     2
     1     3
     1     6
     1     7
     1     8
     2     3
     2     4
     2     5
     2     6
     3     4
     3     7
     4     5
     4     7
     4     9
     5     6
     5     9
     6     8
     6     9
     7     8
     7     9
     7    10
     8     9
     8    10
     9    10
    

    You can then get coordinate form of the edges with coords = V(E(:,1))-V(E(:,2))