mathutils.geometry.normal() giving unexpected results

Hi, as the title says, I’m having some issues with mathutils.geometry.normal(). For testing purposes I have a simple plane in an otherwise empty blend file. When I run this code

 import mathutils import bpy  verts = [vertex.co for vertex in bpy.data.objects['Plane'].data.vertices]  for i in range(len(verts)):     verts[i] = bpy.data.objects['Plane'].matrix_world * verts[i]  normal = mathutils.geometry.normal(verts)  print ("Position:") print (bpy.data.objects['Plane'].location) print ("Rotation:") print (bpy.data.objects['Plane'].rotation_euler) print ("Normal vector:") print (normal) 

I am getting normal vectors which are (0,0,0).

 Position:  Rotation:  Normal vector:  

I tried moving the plane around and rotating it and the only position where I got something else than (0, 0, 0) was this one:

 Position:  Rotation:  Normal vector:  

I also tried this on another computer and got different results (for the same positions), sometimes even NaN. I tried this using 2.7.6. I also noticed there was a change in normal() somewhat recently as in 2.7.3. normal() takes exactly 4 arguments and no lists. Am I doing something wrong or is there a bug in mathutils?

A plane has 2 triangles (4 indexed vertices) and a normal is calculated using 1 triangle (3 vertices).
If you want the average normal of the two triangles:

normal_a = mathutils.geometry.normal(vertices[:3])
#order matters
normal_b = mathutils.geometry.normal(vertices[::-1][:3])
normal_c = (normal_a + normal_b)/2

print (normal_c)

Or directly with the polygons data:

normals = [polygon.normal for polygon in bpy.data.objects['Plane'].data.polygons]

result = mathutils.Vector()
for normal in normals:
    result += normal

result /= len(normals)

print(result)

don’t forget to re-normalize after averaging normals, otherwise the normal vector isn’t likely to be a unit vector.

Oops, nevermind, didn’t read carefully enough.