# Distinguishing left from right adjacent triangles in triangle mesh [closed]

What I'm trying to do:

I'm trying to create a path-drawing function which will produce a path like the one I-P in the diagram below. The way this path was generated requires me to swap between the left adjacent triangle and the right adjacent triangle. For example, in the diagram below:

1. Start at the midpoint, I, of edge GH.
2. Choose Right -> move to midpoint, J, of edge along the right adjacent triangle, EH.
3. From new point, J, alternate to Left Choice -> find midpoint, K, of edge along the left adjacent triangle.
4. Repeat, alternating between left and right adjacent triangle edges. Where I'm Stuck:

I'm having trouble finding an efficient/intuitive way for Mathematica to know which edge is the left edge vs which edge is the right edge. I'd like to be able to do this for an arbitrary triangulation mesh, but I can't think of a simple method for Mathematica to recognize left v.s. right edges.

Also, the path is slightly easier to describe when considering, instead, that we're choosing between edges of inscribed triangles at the midpoints of the mesh. .

For example:

1. Start at I
2. Right-> Choose edge IJ (not IQ), and move to J.
3. From J, Left-> Choose edge JK (not JR), move to K.
4. From K, Right-> Choose KL, move to L
5. Continue, alternating between left and right.

Any ideas on how I can have Mathematica distinguish between the left and right edges/triangles?

Possible Solution: If I could somehow enumerate each edge around a given vertex starting from the incoming edge (#0), then the edge I'm looking for will always be #3. Is this an efficient way to approach this?

Example for Vertex J (Counter-Clockwise Enumeration):

JI=0 JH=1 JR=2 JK=3** JE=4 JQ=5

• Any code you would like to share ? – Sektor Jan 12 '15 at 21:25
• The above diagrams were done in GeoGebra. I'm hoping for an answer which guides me to consider something useful or points me to some relevant Mathematica functions that I might have overlooked. The code that I've toyed with didn't get me very far and probably isn't useful to share. I'm still trying to determine my approach, before getting to the actual testing of code, if that makes sense. – Jesse Jan 12 '15 at 21:35
• That's fair, but I don't think this is the right place to ask for an algorithm that solves a given problem. – Sektor Jan 12 '15 at 21:39
• I am not sure I understand 100% what you would like to do, if I do understand you could use the "ElementConnectivity" string property of an ElementMesh. Mesh element incidents are given in counter clockwise orientation. If you provide some code then an example could be made. – user21 Jan 12 '15 at 22:12
• You could also do that by using "VertexElementConnectivity", Look the documentation and try to understand what "EC" and "VEC" do. Unless you provide coordinates and incidents you are unlikely to get help. – user21 Jan 13 '15 at 9:59

What if you used the orientation of the triangle as a clue to choosing sides?

TriangleOrientation[{x1_, y1_}, {x2_, y2_}, {x3_, y3_}] :=
Sign[x3 (y1 - y2) + x1 (y2 - y3) + x2 (-y1 + y3)]


Any triangle in your mesh has three sides, say vertices U to V, V to W, and W back to U. Say your current midpoint is in side $k$, where $k=1$, $2$, or $3$.

If the orientation is positive (counter-clockwise) then: if stepping right go to side $k+1$, if stepping left go to side $k-1$.

If the orientation is negative (clockwise) then: if stepping right go to side $k-1$, if stepping left go to side $k+1$.

Side $k\pm 1$ is calculated mod 3, with a shift of 1. Thus, 3+1=1 and 1-1=3. In Mathematica use Mod[k,3,1]. After stepping to a new midpoint, drop the old triangle from the mesh so that the current side is in only one triangle, and reset $k$ to the side number of the new current triangle.