
I have a group of triangles that will tile an area, one possible configuration is shown in the included image. I want to find out how many edges each triangle shares with adjacent triangles. So a triangle by itself would share zero edges while a completely surrounded triangle would share all three edges. In the image the center triangle shares its top edge with the triangle above, but has no neighbors on the other two sides. So I need a way to detect that it only shares one edge with a neighbor.
I have defined each triangle as a polygon in shapely, then input the list of triangle polygons into an SRTtree. Then tried both the "touches" and "intersects" predicates.
Both output every neighboring triangle that touches at any one of the vertices. The preferred outcome is to only output the triangles with shared edges.
I've also attempted to use coverage operations to identify edges with no neighbors. Unfortunately, the invalid edge detection returns an empty set for every triangle. Despite having nothing next to two edges of the center triangle, it appears to satisfy coverage requirements with no invalid edges.
The below minimum reproducible example (MRE) only has four triangles from the diagram: the center triangle, the triangle above it that shares an edge, a triangle that shares a vertex, and a triangle that doesn't touch the initial triangle.
import shapely
triangles.append=shapely.Polygon(shell=((-0.5,0.866),(0.5,0.866),(0,0)),holes=None))
triangles.append=shapely.Polygon(shell=((-0.5,0.866),(0.5,0.866),(0,1.732)),holes=None))
triangles.append=shapely.Polygon(shell=((0.5,0.866),(1.5,0.866),(1,0)),holes=None))
triangles.append=shapely.Polygon(shell=((1,0),(2,0),(1.5,0.866)),holes=None))
tree=shapely.STRtree(triangles)
touching_triangles=tree.query(triangles[0], predicate="touches")
intersecting_triangles=tree.query(triangles[0], predicate="intersects")
identified_edges=shapely.coverage_invalid_edges(triangles)
So how do I identify shared edges while excluding shared vertices?