title: How to find the slicing area in STL-Model
body: <p>I've implemented the following code to search and find the vertices on the cross section of a STL-Model. As the models I use contains normally over million nodes(Vertices), it wouldn't be effecient if I really search all the nodes (vertices) and check if they are in the cross section area. So as soon as the first nodes is found I just check the neighbour nodes to find the next edge node. And continue that to reach the first node I have found.</p>
  
  <p>I want to make a list of all the blude vertices on the cropping section of the model:<a href="https://i.stack.imgur.com/Edxjo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Edxjo.png" alt="enter image description here"></a></p>
  
  <pre><code>void findCroppingPoints()
  {
  unsigned int i, f;
  int iFirst, k, kOld, p, cnt= 0;
  bool isEdge1, isEdge2, isEdge3;
  
  for (i = 0; i &lt; (m_FacetList.size()); i++)
  {
      isEdge1 = isEdge2 = isEdge3 = false;
  
  //check the three edges of the triange i to see if they are on the cross-section.
      isEdge1 = isEdgeVertex(i, 1); 
      isEdge2 = isEdgeVertex(i, 2);
      isEdge3 = isEdgeVertex(i, 3);
  
      if (isEdge1 || isEdge2 || isEdge3)
      {
          iFirst = i;
          saveFacet:
          if (cnt == 0)
              if (isEdge1 = true)
                  p = 0;
              else if (isEdge2 = true)
                  p = 1;
              else
                  p = 2;
          m_EdgePointList.push_back(m_FacetList[i]-&gt;vertex[p]);
              cnt++;
  
          for (f = 0; f &lt; m_FacetList.size(); f++)
          {
              isEdge1 = isEdge2 = isEdge3 = false;
              if (f != iFirst)
                  for (k = 0; k &lt; 3; k++)
                  {
                      if (m_FacetList[i]-&gt;vertex[p] == m_FacetList[f]-&gt;vertex[k]) // Search for the triangle, whiche contains the p (the edge, which has found before)
                      {
                          switch (k) // check, which of the two connected edges on this point is on the cross-section
                          {
                          case 0:
                              if (i != f || kOld != 1)
                                  if (isEdgeVertex(f, 1))
                                  {
                                      isEdge1 = true;
                                      p = 1;
                                      kOld = k;
                                      i = f; // Spring to the new-found triangle
                                      goto saveFacet;
                                  }
                              if (i != f || kOld != 2)
                                  if (isEdgeVertex(f, 3))
                                  {
                                      isEdge3 = true;
                                      p = 2;
                                      kOld = k;
                                      i = f; // Spring to the new-found triangle
                                      goto saveFacet;
                                  }
                              break;
                          case 1:
                              if (i != f || kOld != 0)
                                  if (isEdgeVertex(f, 1))
                                  {
                                      isEdge1 = true;
                                      p = 0;
                                      kOld = k;
                                      i = f; // Spring to the new-found triangle
                                      goto saveFacet;
                                  }
                              if (i != f || kOld != 2)
                                  if (isEdgeVertex(f, 2))
                                  {
                                      isEdge2 = true;
                                      p = 2;
                                      kOld = k;
                                      i = f; // Spring to the new-found triangle
                                      goto saveFacet;
                                  }
                              break;
                          case 2:
                              if (i != f || kOld != 1)
                                  if (isEdgeVertex(f, 2))
                                  {
                                      isEdge2 = true;
                                      p = 1;
                                      kOld = k;
                                      i = f; // Spring to the new-found triangle
                                      goto saveFacet;
                                  }
                              if (i != f || kOld != 0)
                                  if (isEdgeVertex(f, 3))
                                  {
                                      isEdge3 = true;
                                      p = 0;
                                      kOld = k;
                                      i = f; // Spring to the new-found triangle
                                      goto saveFacet;
                                  }
                              break;
                          }
                      }
                  }
          }
          break;
      }
  }
  }
  </code></pre>
  
  <p>This is how I check if an edge of a triangle represent a cross-section edge:</p>
  
  <pre><code>bool CSTLModel::isEdgeVertex(unsigned int FacetNum, int VertexNum)
  {
  bool isEdge;
  unsigned int f1, f2, f3;
  int k1, k2, p1, p2;
  
  switch (VertexNum)
  {
  case 1:
      p1 = 0;
      p2 = 1;
      break;
  case 2:
      p1 = 1;
      p2 = 2;
      break;
  case 3:
      p1 = 2;
      p2 = 0;
      break;
  }
  for (f1 = 0 ; f1 &lt; m_FacetList.size(); f1++)
      {
          if (f1 != FacetNum)
          {
              isEdge = true;
              for (k1 = 0; k1 &lt; 3; k1++)
                  if (m_FacetList[FacetNum]-&gt;vertex[p1] == m_FacetList[f1]-&gt;vertex[k1])
                      for (k2 = 0; k2 &lt; 3; k2++)
                          if (m_FacetList[FacetNum]-&gt;vertex[p2] == m_FacetList[f1]-&gt;vertex[k2])
                          {
                              isEdge = false;
                              goto endLoop;
                          }
          }
      }
  endLoop:
  return isEdge;
  }
  </code></pre>
  
  <p>But that doesn't work if there are more than one cropping section on the model, I can't jump to the next section, without having to search in all the nodes. </p>
  
  <p>Do you know any other simpler algorithm to find the cropping sections in STL Model? Or any solution to the problem in above?</p>