title: How to correct winding of triangles to counter-clockwise direction of a 3D Mesh model?
body: <p>First of all let me clear .. I am not asking about 2D mesh, to determine the winding order of 2D mesh its very easy with normal-z direction. </p>
  
  <p>Second is, I am not asking any optimized algorithm, I do not worry about the time or speed, I just want to do it with my mesh.</p>
  
  <p>When I triangulate a 3D object using Greedy Projection Triangulation algorithm, This problem happens.
  check the attached images.</p>
  
  <p>If I apply 2D approaches to this model using "Calculate Signed Area" or "Cross production of AB and BC vectors of a triangle", it only solves the 2D mesh but how about a 3D mesh?</p>
  
  <p>First we need to check that which triangles are in wrong winding direction in 3D mesh, then we only consider those triangles, so the issue is, how can we check that which triangles are in wrong winding direction in 3D? We can not just do with 2D approach I have tested it and but no success.</p>
  
  <p>For example in case of a sphere, we can not apply 2D approach to sphere. 
  So is there any way to solve this issue ?  </p>
  
  <p>Thanks.</p>
  
  <p><img src="https://i.stack.imgur.com/CIomS.jpg" alt="enter image description here">
  <img src="https://i.stack.imgur.com/NDcUc.jpg" alt="enter image description here"></p>
  
  <p><em>Update # 1:</em></p>
  
  <p>Below is the algorithm to check which edge has the same winding. It doesn't work well, I don't know why. Theoretically it should correct all the triangles but it is not correcting. For example in case of a sphere check in the attached figure. Something is wrong with it. </p>
  
  <pre><code>void GLReversedEdge(int i, int j, GLFace *temp)
  {
      //i'th triangle
      int V1 = temp[i].v1;
      int V2 = temp[i].v2;
      int V3 = temp[i].v3;
  
      //i'th triangle edges
      int E1[] ={V1, V2};
      int E2[] ={V2, V3};
      int E3[] ={V3, V1};
  
      //adjacent triangle
      int jV1 = temp[j].v1;
      int jV2 = temp[j].v2;
      int jV3 = temp[j].v3;
  
      //adjacent edges
      int jE1[] ={jV1, jV2};
      int jE2[] ={jV2, jV3};
      int jE3[] ={jV3, jV1};
  
      // 1st edge of adjacent triangle is checking with all edges of ith triangle
      if((jE1[0] == E1[0] &amp;&amp; jE1[1] == E1[1]) ||
         (jE1[0] == E2[0] &amp;&amp; jE1[1] == E2[1]) ||
         (jE1[0] == E3[0] &amp;&amp; jE1[1] == E3[1]))
      {
         temp[j].set(jV2, jV1, jV3);      // 1st edges orientation is same, so reverse/swap it
      }
      // 2nd edge of adjacent triangle is checking with all edges of ith triangle
      else if((jE2[0] == E1[0] &amp;&amp; jE2[1] == E1[1]) ||
              (jE2[0] == E2[0] &amp;&amp; jE2[1] == E2[1]) ||
              (jE2[0] == E3[0] &amp;&amp; jE2[1] == E3[1]))
      {
              temp[j].set(jV1, jV3, jV2); // 2nd edges orientation is same, so reverse/swap it
      }
      // 3rd edge of adjacent triangle is checking with all edges of ith triangle
      else if((jE3[0] == E1[0] &amp;&amp; jE3[1] == E1[1]) ||
              (jE3[0] == E2[0] &amp;&amp; jE3[1] == E2[1]) ||
              (jE3[0] == E3[0] &amp;&amp; jE3[1] == E3[1]))
      {
              temp[j].set(jV3, jV2, jV1); // 3rd edges orientation is same, so reverse/swap it
      }
  }
  
  void GetCorrectWindingOfMesh()
  {
      for(int i=0; i&lt;nbF; i++)
      {
          int j1 = AdjacentTriangleToEdgeV1V2;
          if(j1 &gt;= 0) GLReversedEdge(i, j1, temp);
  
          int j2 = AdjacentTriangleToEdgeV2V3;
          if(j2 &gt;= 0) GLReversedEdge(i, j2, temp);
  
          int j3 = AdjacentTriangleToEdgeV3V1;
          if(j3 &gt;= 0) GLReversedEdge(i, j3, temp);
      }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/EfbaJ.png" alt="enter image description here"></p>