Mesh Section Progressive sections through a topographic mesh of Zermatt, Switzerland

This sketch adds to the Half-Edge Mesh sketch, a function sectionHEM() for cutting a planar section through a mesh. It also uses the Mesh Import function to instantiate the topography from a pair of .txt files (included in the .zip file below). The section function is called in Lines 71-80 of the main tab.
```//CUT PLANAR SECTION THROUGH MESH Obj mySect= new Obj(); for (int i=0; i<myMesh.e.length; i++){   //ARGUMENTS: (HEM, TEST EDGE INDEX i, PLANE ORIGIN, PLANE NORMAL, SECTION LINES AS Obj)   sectionHEM(myMesh, i, sectPt, sectN, mySect);   if (mySect.numOfLines()>0){     if (myMesh.eTE[i]>=0){ sectionHEM(myMesh, myMesh.eTE[i], sectPt, sectN, mySect) ; }     break;   } }```
This runs a loop over every edge in the HEM, calling the sectionHEM function which checks whether the section plane intersects that edge. If so, the function proceeds in that direction, extending the section cut face-by-face, segment-by-segment, until reaching an outside edge. After finding an intersecting edge, the function sectionTWIN takes advantage of the referencing data in the HEM class to limit the subsequent search to the adjacent face.

Lines 43-54 of the HEM_functions tab show how this works. First a while loop is established to cycle through the edges of the face (when no intersection is found, ‘x’ is overwritten with its own NextEdge, Line 52). Inside this loop the code checks for the planar intersection as before using the intersectLINEPLANE() function (‘u’ is the parameter of the line intersecting, if 0<u<1 then the plane intersects on the segment). In the case of such an intersection (and a valid twinEdge -i.e. a non-negative index, Line 50) the function sectionTWIN() calls itself recursively to repeat the process on the next adjacent face (Line 50)
``` int x=m.eNE[n]; while(x != n){   u=-10;   u=intersectLINEPLANE( m.v[m.eOV[x]], m.v[m.eOV[m.eNE[x]]],o,N,seg );   if (u>=0 && u<=1){    //LOOP THROUGH NEXT EDGES AROUND TWIN'S FACE    int twnNdx = m.eTE[x];    if (twnNdx>=0){sectionTWIN(m,twnNdx,o,N,seg); }    x=n;   } else { x=m.eNE[x]; } }```

When the sectionHEM function has found an intersection, the Obj mySect will return to the main tab containing line segments and will initiate the following conditional statement (Lines 76-79) which completes the section cut in the opposite direction (across the original edge’s twin’s face) of the discovered intersection point and ends the search loop with a break command. In the next post we will see how the edge twin can be used to avoid the time-consuming edge search by identifying the face which the cutting plane’s origin is located within directly.

1. Face ID « Quotidien says: