Given the vertex data for a polygon, you can compute a normal to the polygon by taking two non-collinear edges (we usually just assume that no two adjacent edges will be collinear), compute the cross product, and normalize the result.
The following function can be used, passing it the first three vertices of your polygon:
# computeNormal - take 3 vertex positions
# (v0, v1, v2), and return a unit length
# normal vector for the polygon
def computeNormal(v0,v1,v2):
A = [ v2[0] - v1[0],
v2[1] - v1[1],
v2[2] - v1[2] ]
B = [ v0[0] - v1[0],
v0[1] - v1[1],
v0[2] - v1[2] ]
product = [ A[1] * B[2] - A[2] * B[1],
A[2] * B[0] - A[0] * B[2],
A[0] * B[1] - A[1] * B[0] ]
length = math.sqrt(product[0]*product[0] +
product[1]*product[1] +
product[2]*product[2])
if (length == 0): # If there's a problem,
return [0, 1, 0] # return arbitrary result
else:
return [ product[0]/length,
product[1]/length,
product[2]/length ]