Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a python library capable of calculating the dual of a 3D mesh?

I looked into python-graph and the python bindings for the boost graph library but did not find anything relevant regarding the dual-ization of meshes (the vertices of the dual are the faces of the original graph and are connected by an edge in the dual if they share an edge in the original graph) . Before I set to re-invent this wheel, is there an implementation I might have overlooked?

like image 928
Noam Kremen Avatar asked Sep 07 '25 10:09

Noam Kremen


2 Answers

Probably there is, but it is quite simple to implement one. To do this it is needed to find for edge in which triangles it is used. And with that information it is possible to construct connections between triangles.

Simple python implementation, triangle (or polygon) is a list of vertex indices and edge is ordered pair of vertex indices:

from collections import defaultdict
from itertools import combinations
triangles = [(1,2,3), (2,3,4), (1,3,5), (3,4,5), (5,6,7), (4,5,6)]
# For each edge set triangles containing that edge
edge2trias = defaultdict(list)  # edge (v1,v2) -> list of triangles
for t_ind, ps in enumerate(triangles):
    for edge in zip(ps, ps[1:]+ps[:1]):
        edge2trias[tuple(sorted(edge))].append(t_ind)
# For each edge, set pair(s) of neighbouring triangles
tria2neigh = defaultdict(list)  # triangle index -> list of neighbouring triangles
for edge, trias in edge2trias.iteritems():
    for t1, t2 in combinations(trias, 2):
        tria2neigh[t1].append(t2)
        tria2neigh[t2].append(t1)
like image 129
Ante Avatar answered Sep 09 '25 00:09

Ante


And to answer own question - graph-tool's line graph function calculates the dual of the graph.

like image 29
Noam Kremen Avatar answered Sep 09 '25 00:09

Noam Kremen