
-----------------------------------
102jon
Thu Feb 03, 2011 10:34 am

Tuple index out of range problem
-----------------------------------
I'm writing a script that essentially splits a polygon (a list of coordinate pairs) into two for a given special case.  For the first polygon I run a for loop as follows:
exact same thing for the second polygon:

[code]
for i in range(1, len(polygon)):
            if (polygon[i][0] > 0) and (polygon[i+1][0] < 0):
                boundIntercept = polygon[i][1] - ((polygon[i][1] - polygon[i+1][1]) / (polygon[i][0] - polygon[i+1][0])) * polygon[i][0]
                newPolygon2[i] = (0, boundIntercept)
            elif (polygon[i-1][0] < 0) and (polygon[i][0] > 0):
                boundIntercept = polygon[i][1] - ((polygon[i][1] - polygon[i-1][1]) / (polygon[i][0] - polygon[i-1][0])) * polygon[i][0]
                newPolygon2[i] = (0, boundIntercept)
            elif ((polygon[i][0] > 0) and (polygon[i-1][0] > 0) and (polygon[i+1][0] > 0)):
                newPolygon2[i] = None
        secondPolygon = [item for item in newPolygon2 if item != None][/code]

And I get a "error: tuple index out of range". Any insight would be appreciated.

-----------------------------------
DemonWasp
Thu Feb 03, 2011 12:52 pm

RE:Tuple index out of range problem
-----------------------------------
It would be easier for us to help if you also listed the initialization of the two polygons, and if your code were properly indented in your [ code ] elements.

-----------------------------------
102jon
Fri Feb 04, 2011 4:08 pm

Re: Tuple index out of range problem
-----------------------------------
I figured it out, but thanks. The code was indented properly but something happened when copying and pasting it here.
