I have an array with vertices representing a triangular strip. I need to convert it into polygon. There are many solution to do the reverse, but I failed to find one for the above problem. Or it could be too easy and I just cannot see it. Please help.
OpenGL=compatible, see http://en.wikipedia.org/wiki/Triangle_strip
Example: for this strip http://en.wikipedia.org/wiki/File:Triangle_Strip_Small.png I need output A B D F E C or A C E F D B
I believe the following should work:
Walk through the list of vertices. Add the first point to your polygon. Push the second point on the stack. Add the third point to the polygon. Continue alternating between pushing points on the stack and adding them to the polygon until you reach the end of the list. When you get to the end of the list, pop the points of the stack and add them to the polygon.
I'll assume your triangle strip is always connected the same way (which I believe is true for OpenGL).
Take the "bottom" list and append the reverse of the "top" list. (ACEFDB for the example)
Or, more directly, using a zero-based index instead of letters:
// do "bottom"
for ( i = 0; i < N; i += 2 )
addVertex( i )
// do "top"
largestOddNumberLessThanN = N % 2 == 0 ? N - 1 : N - 2;
for ( i = largestOddNumberLessThanN; i >= 0; i -= 2 )
addVertex( i )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With